File tree Expand file tree Collapse file tree 3 files changed +69
-1
lines changed
app/Infrastructure/Analyze/Adapters/PhpParser
Unit/Infrastructure/Analyze Expand file tree Collapse file tree 3 files changed +69
-1
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ public function enterNode(Node $node): void
2020 if ($ node instanceof Class_) {
2121 $ this ->fqcn = $ node ->namespacedName ?->toString();
2222 $ this ->isAbstract = $ node ->isAbstract ();
23+ $ this ->isInterface = false ;
2324 }
2425
25- if ($ node instanceof Interface_) {
26+ if ($ node instanceof Interface_ && $ this -> fqcn === null ) {
2627 $ this ->fqcn = $ node ->namespacedName ?->toString();
2728 $ this ->isInterface = true ;
2829 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Fixtures \Php85 ;
4+
5+ use Attribute ;
6+ use DateTimeInterface ;
7+ use IteratorAggregate ;
8+
9+ #[Attribute]
10+ class CustomAttribute {}
11+
12+ interface Contract {}
13+
14+ abstract class AbstractBase {}
15+
16+ enum Status: string {
17+ case Active = 'active ' ;
18+ }
19+
20+ final class ModernClass extends AbstractBase implements Contract, IteratorAggregate
21+ {
22+ public function __construct (
23+ private readonly DateTimeInterface $ clock ,
24+ ) {}
25+
26+ #[CustomAttribute]
27+ public function handle (Status |Contract |null $ value ): ?DateTimeInterface
28+ {
29+ return $ this ->clock ;
30+ }
31+
32+ public function getIterator (): \Traversable
33+ {
34+ return new \ArrayIterator ([]);
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use App \Infrastructure \Analyze \Adapters \PhpParser \PhpAstClassDependenciesParser ;
4+
5+ it ('detects dependencies from modern PHP syntax (8.1+) ' , function () {
6+ $ parser = app (PhpAstClassDependenciesParser::class);
7+
8+ $ analysis = $ parser ->parse (__DIR__ . '/../../../Fixtures/Php85/ModernClass.php ' );
9+
10+ expect ($ analysis ->fqcn ())->toBe ('Tests \\Fixtures \\Php85 \\ModernClass ' );
11+
12+ expect ($ analysis ->dependencies ())->toContain (
13+ 'Tests \\Fixtures \\Php85 \\AbstractBase ' ,
14+ 'Tests \\Fixtures \\Php85 \\Contract ' ,
15+ 'IteratorAggregate ' ,
16+ 'DateTimeInterface ' ,
17+ 'Tests \\Fixtures \\Php85 \\Status ' ,
18+ 'Tests \\Fixtures \\Php85 \\CustomAttribute ' ,
19+ 'ArrayIterator ' ,
20+ 'Traversable ' ,
21+ );
22+ });
23+
24+ it ('marks interface and abstract correctly ' , function () {
25+ $ parser = app (PhpAstClassDependenciesParser::class);
26+
27+ $ analysis = $ parser ->parse (__DIR__ . '/../../../Fixtures/Php85/ModernClass.php ' );
28+
29+ expect ($ analysis ->isAbstract ())->toBeFalse ();
30+ expect ($ analysis ->isInterface ())->toBeFalse ();
31+ });
You can’t perform that action at this time.
0 commit comments