diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php index 56f9b4b4..a5292e59 100644 --- a/src/Analyzer/FileVisitor.php +++ b/src/Analyzer/FileVisitor.php @@ -149,6 +149,10 @@ public function enterNode(Node $node): void return; } + if ($this->isScalarType($node->type->toString())) { + return; + } + $this->classDescriptionBuilder->addDependency(new ClassDependency($node->type->toString(), $node->getLine())); } @@ -220,4 +224,9 @@ private function addParamDependency(Node\Param $node): void $this->classDescriptionBuilder ->addDependency(new ClassDependency($node->type->toString(), $node->getLine())); } + + private function isScalarType(string $typeName): bool + { + return \in_array($typeName, ['bool', 'int', 'float', 'string']); + } } diff --git a/tests/Unit/Analyzer/FileVisitorTest.php b/tests/Unit/Analyzer/FileVisitorTest.php index c8499d01..f56895f5 100644 --- a/tests/Unit/Analyzer/FileVisitorTest.php +++ b/tests/Unit/Analyzer/FileVisitorTest.php @@ -551,4 +551,33 @@ class ApplicationLevelDto $this->assertCount(1, $violations); } + + public function test_it_parse_scalar_typed_property(): void + { + $code = <<< 'EOF' +parse($code, 'relativePathName'); + + $cd = $fp->getClassDescriptions(); + + $violations = new Violations(); + + $notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('MyProject\AppBundle\Application'); + $notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software'); + + $this->assertCount(0, $violations); + } }