diff --git a/src/Parser/MapBuilder.php b/src/Parser/MapBuilder.php index d81ca6e7..4529c695 100644 --- a/src/Parser/MapBuilder.php +++ b/src/Parser/MapBuilder.php @@ -55,9 +55,10 @@ public function build(): array $this->traverser->traverse($parsed); - $astMap[] = new AstNode( + $className = $this->astNodesCollector->getClassNames()[0]; + $astMap[$className->getFQCN()] = new AstNode( $fileInfo, - $this->astNodesCollector->getClassNames()[0], + $className, $this->astNodesCollector->getParents()[0] ?? null, $this->astNodesCollector->getDependencies(), $this->astNodesCollector->getInterfaces(), diff --git a/src/Statement/StatementBuilder.php b/src/Statement/StatementBuilder.php index 975ecc16..8503afb9 100644 --- a/src/Statement/StatementBuilder.php +++ b/src/Statement/StatementBuilder.php @@ -7,6 +7,7 @@ use PhpAT\App\Configuration; use PhpAT\Parser\AstNode; use PhpAT\Rule\Rule; +use PhpAT\Selector\SelectorInterface; use PhpAT\Selector\SelectorResolver; use PhpParser\Parser; @@ -41,15 +42,18 @@ public function __construct(SelectorResolver $selectorResolver, Parser $parser) */ public function build(Rule $rule, array $astMap): \Generator { - $origins = $this->selectClassNames($rule->getOrigin(), $rule->getOriginExcluded(), $astMap); - $destinations = $this->selectClassNames($rule->getDestination(), $rule->getDestinationExcluded(), $astMap); + $origins = $this->getNamesFromSelectors($rule->getOrigin(), $rule->getOriginExcluded(), $astMap); + $destinations = $this->getNamesFromSelectors($rule->getDestination(), $rule->getDestinationExcluded(), $astMap); if (!empty(Configuration::getSrcIncluded())) { $filteredOrigins = []; foreach (Configuration::getSrcIncluded() as $checkOnly) { $checkOnly = Configuration::getSrcPath() . $checkOnly; foreach ($origins as $key => $value) { - if ($this->normalizePath($checkOnly) == $this->normalizePath($value->getPathname())) { + if ( + isset($astMap[$value]) + && $this->normalizePath($checkOnly) == $this->normalizePath($astMap[$value]->getFilePathname()) + ) { $filteredOrigins[] = $origins[$key]; } } @@ -68,13 +72,13 @@ public function build(Rule $rule, array $astMap): \Generator } /** - * @param array $included - * @param array $excluded + * @param SelectorInterface[] $included + * @param SelectorInterface[] $excluded * @param array $astMap * @return string[] * @throws \Exception */ - private function selectClassNames(array $included, array $excluded, array $astMap): array + private function getNamesFromSelectors(array $included, array $excluded, array $astMap): array { $classNamesToValidate = []; foreach ($included as $i) {