File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,20 @@ public function enterNode(Node $node): void
61
61
}
62
62
}
63
63
64
+ /**
65
+ * adding static classes as dependencies
66
+ * $constantValue = StaticClass::constant;.
67
+ *
68
+ * @see FileVisitorTest::test_it_should_return_errors_for_const_outside_namespace
69
+ */
70
+ if ($ node instanceof Node \Expr \ClassConstFetch &&
71
+ method_exists ($ node ->class , 'toString ' ) &&
72
+ null !== $ this ->classDescriptionBuilder
73
+ ) {
74
+ $ this ->classDescriptionBuilder
75
+ ->addDependency (new ClassDependency ($ node ->class ->toString (), $ node ->getLine ()));
76
+ }
77
+
64
78
/**
65
79
* adding static function classes as dependencies
66
80
* $static = StaticClass::foo();.
Original file line number Diff line number Diff line change @@ -380,4 +380,33 @@ class Foo {}
380
380
$ cd [0 ]->getAttributes ()
381
381
);
382
382
}
383
+
384
+ public function test_it_should_return_errors_for_const_outside_namespace (): void
385
+ {
386
+ $ code = <<< 'EOF'
387
+ <?php
388
+ namespace Root\Cars;
389
+ use AnotherNamespace\CarMake;
390
+ class KiaSportage extends AbstractCar
391
+ {
392
+ public function __construct()
393
+ {
394
+ parent::__construct(CarMake::KIA, 'Sportage');
395
+ }
396
+ }
397
+ EOF;
398
+
399
+ /** @var FileParser $fp */
400
+ $ fp = FileParserFactory::createFileParser (TargetPhpVersion::create ('7.4 ' ));
401
+ $ fp ->parse ($ code , 'relativePathName ' );
402
+
403
+ $ cd = $ fp ->getClassDescriptions ();
404
+
405
+ $ violations = new Violations ();
406
+
407
+ $ notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace ('Root\Cars ' );
408
+ $ notHaveDependencyOutsideNamespace ->evaluate ($ cd [0 ], $ violations , 'we want to add this rule for our software ' );
409
+
410
+ $ this ->assertCount (1 , $ violations );
411
+ }
383
412
}
You can’t perform that action at this time.
0 commit comments