Skip to content

Commit

Permalink
Merge pull request #70 from carlosas/fix-include
Browse files Browse the repository at this point in the history
Fix include option
  • Loading branch information
carlosas authored Jan 8, 2020
2 parents 68b030f + abb0334 commit 970a90c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Parser/MapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 10 additions & 6 deletions src/Statement/StatementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit 970a90c

Please sign in to comment.