mamuz / PhpDependencyAnalysis

Static code analysis to find violations in a dependency graph
http://mamuz.github.io/PhpDependencyAnalysis/
MIT License
561 stars 45 forks source link

namespaceFilter plugin is never called on global namespace #40

Open doekia opened 5 years ago

doekia commented 5 years ago

I have an old project that does not use namespace (only ) and a set of classes alias. I'm trying to implement a namespace filter to mimic package (namespace) and class alias. I discovered that the filter is never called. Here is a simplified scenario to reproduce the issue.

My Environment (version of the project, operating system, or hardware)

Debian 9
PhpDependencyAnalysis by Marco Muths v1.3.1
PHP 5.6.40-1+0~20190111135530.9+stretch~1.gbp5f42c9 (cli)
dot - graphviz version 2.38.0 (20140413.2041)

My phpda.yml:

mode: 'call'
source: './web'
filePattern: '*.php'
ignore: [ 'cache','test','install173','modules', 'Tests','fonts','tools', 'override' ]
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './web/total0.svg'
namespaceFilter: PS\Plugin\CoreNamespaceFilter
groupLength: 2
visitor:
  - PhpDA\Parser\Visitor\TagCollector
  - PhpDA\Parser\Visitor\NamespacedStringCollector
  - PhpDA\Parser\Visitor\IocContainerAccessorCollector
visitorOptions:
  - PhpDA\Parser\Visitor\Required\DeclaredNamespaceCollector: {minDepth: 2, sliceLength: 2}
  - PhpDA\Parser\Visitor\Required\MetaNamespaceCollector: {minDepth: 2, sliceLength: 2}
  - PhpDA\Parser\Visitor\Required\UsedNamespaceCollector: {minDepth: 2, sliceLength: 2}
  - PhpDA\Parser\Visitor\TagCollector: {minDepth: 2, sliceLength: 2}
classMap:
  PS\Plugin\CoreNamespaceFilter: './CoreNamespaceFilter.php'

My filter

<?php

namespace PS\Plugin;

use PhpDA\Parser\Filter\NamespaceFilterInterface;

class CoreNamespaceFilter implements NamespaceFilterInterface
{

    public function filter(array $nameParts)
    {
        die(print_r($nameParts,1));
    }
}

When I run this command:

phpda analyze phpda.yml

Actual behavior: svg is generated but filter never called ( Never die - Note that a die in the constructer works as expected - hence plugins is loaded )

Expected behavior: filter to be called.