Comments (9)
The same problem occurs (arrayAlias
reported) when using PHPStan type like this:
/**
* @phpstan-type arrayAlias array<string, mixed>
*/
class SomeClass
{
/**
* @return arrayAlias
*/
private function someMethod(): array
{
return [];
}
}
from deptrac.
The same problem occurs (
arrayAlias
reported) when using PHPStan type like this:/** * @phpstan-type arrayAlias array<string, mixed> */ class SomeClass { /** * @return arrayAlias */ private function someMethod(): array { return []; } }
To be fair in this case it really should be @phpstan-return
as you are defining @phpstan-type
and therefore the referenced return should also only be scoped to @phpstan
.
from deptrac.
@psalm-import-type
has the same problem
from deptrac.
@psalm-import-type
has the same problem
And I would propose the same solution. You should reference it with @psalm-return
. This is a case where you would be always behind. As there is a potentially infinite number of tools that can define their prefixed tags. Deptrac does this as well with @deptrac-internal
.
There is a larger argument that we should be able to fully support Psalm and PHPStan.
from deptrac.
The prefix is not really scoping, tools like PHPStan often introduce some features with prefixed annotation (like @phpstan-return
), but later other tools (like PHPStorm) includes such feature in regular annotation (like @return
). I have not met a single issue when combining prefixed and non-prefixed stuff since every tool reads annotations of the others. So we use non-prefixed version wherever possible.
But I understand this might be hard for deptrac to be in-sync with all the tools.
from deptrac.
I also encountered the same problem. But i just swooped them into the baseline. I mean, it would be nice if deptrac could understand it and work with it, but not a must have i think. Also, there are cases where you define phpstan-return
and psalm-return
due to different syntax approaches or missing feature in one tool (if you are using both, which i do). So this would also add extra complexity: which return are we then taking into account, or maybe even both?
from deptrac.
Currently, I'm using this to avoid this issue in general (as we use only class tokens):
class ExcludeUncoveredHandler implements EventSubscriberInterface
{
public function handleUncovered(PostProcessEvent $event): void
{
$result = $event->getResult();
/** @var Uncovered $uncovered */
foreach ($result->allOf(Uncovered::class) as $uncovered) {
if ($this->isUncoveredIgnored($uncovered)) {
$result->remove($uncovered);
}
}
}
private function isUncoveredIgnored(Uncovered $uncovered): bool
{
/** @var class-string<object> $class */
$class = $uncovered->getDependency()->getDependent()->toString();
try {
/** @throws ReflectionException */
$reflectionClass = new ReflectionClass($class);
} catch (ReflectionException $e) {
return true; // prevent deptrac bugs like https://github.com/qossmic/deptrac/issues/1399
}
return false;
}
/**
* @return array<string, array{string}>
*/
public static function getSubscribedEvents(): array
{
return [
PostProcessEvent::class => ['handleUncovered'],
];
}
}
services:
excludeUncoveredHandler:
class: App\EventHandler\ExcludeUncoveredHandler
tags:
- { name: kernel.event_subscriber }
from deptrac.
This could catch also other errors no? I would suggest just to utilize the baseline feature. I mean, this is exactly meant for such cases.
from deptrac.
We have other tooling to detect non-existing classes in codebase, so this should be safe in our case. If deptrac finds non-class token, it clearly does something wrong and I dont want that to be reported.
from deptrac.
Related Issues (20)
- Support for typed const - PHP 8.3 HOT 24
- Add support for mermaid formatters HOT 4
- Referencing non-existing layer in depfile emits no error, but breaks the referencing layer HOT 2
- PHP 8.3 new override attribute HOT 2
- Add ability to disable "Parsing File" output HOT 2
- Allow usage of debug:unassigned in CI or add `--fail-on-unassigned`
- Ability to disable `@internal` feature HOT 4
- Ability to add custom `PhpParser\NodeVisitor` to alter AST attributes HOT 7
- Modularization and Encapsulation Support in Deptrac Configuration HOT 4
- Vendor folder as a layer question HOT 1
- How to install deptrac via composer HOT 7
- Version 2.0.0-alpha ignores @internal and just works with @deptrac-internal HOT 2
- Vendor directory combined with an empty composer file. HOT 1
- Uncaught Error: Typed property Qossmic\Deptrac\Core\Ast\AstMap\DependencyToken::$context must not be accessed before initialization HOT 3
- Does `functionName` only support functions with namespaces?
- Cannot configure skipViolations with DeptracConfig HOT 1
- Problem with duplicate functions and classes
- PHP Fatal error on v2.0 (EventHelper::__construct(): Argument #1 ($skippedViolations) must be of type array, null given) HOT 3
- Unable to use custom `EventSubscriberInterface` in depfile since 2.0 as those are prefixed in the phar HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deptrac.