Skip to content

3. Configuration

Marco Muths edited this page Mar 25, 2017 · 6 revisions

This tool is configurable by a YAML file.

mode: 'usage' # usage | call | inheritance
source: './src'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './phpda.svg'
namespaceFilter: 'Full\Qualified\Namespace\To\NamespaceFilter'
referenceValidator: 'Full\Qualified\Namespace\To\ReferenceValidator'
groupLength: 1
visitor:
  - PhpDA\Parser\Visitor\TagCollector
  - PhpDA\Parser\Visitor\SuperglobalCollector
  - PhpDA\Parser\Visitor\UnsupportedEvalCollector
  - PhpDA\Parser\Visitor\UnsupportedFuncCollector
  - PhpDA\Parser\Visitor\UnsupportedVarCollector
  - PhpDA\Parser\Visitor\UnsupportedGlobalCollector
  - 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: 1}
  PhpDA\Parser\Visitor\Required\UsedNamespaceCollector: {minDepth: 2, sliceLength: 1}
  PhpDA\Parser\Visitor\TagCollector: {minDepth: 2, sliceLength: 1}
classMap:
  Full\Qualified\Namespace\To\ReferenceValidator: './ReferenceValidator.php'
  Full\Qualified\Namespace\To\NamespaceFilter: './NamespaceFilter.php'

Available Options

Name Type Description
mode string Graph mode: usage-Graph (default), call-Graph or inheritance-Graph
source string To be analyzed directory
filePattern string Pattern to match files inside source
ignore string, array Optional: Excluding directories inside source
formatter string Output Formatter; must be declared with a FQCN
target string File path to output the result
namespaceFilter string Optional: Namespace Filter; must be declared with a FQCN
referenceValidator string Optional: Reference Validator; must be declared with a FQCN
groupLength integer Optional: Group found namespaces by count of their namespaceparts
visitor array Optional: Indexed list of visitors to use; each visitor must be declared with a FQCN
visitorOptions array Optional: Associative list modeled by Visitor-FQCN => Properties
classMap array Optional: Associative list modeled by FQCN => Filepath to support autoloading custom plugins such as ReferenceValidator

namespaceFilter

Modify the namespace of collected dependencies to meet custom use-cases. Create a custom filter which manipulate the namespace parts.

Write your own Namespace Filter

referenceValidator

Perform a detection of violations between dependencies.

Create a custom validator which verifies that each dependency is meeting your defined architecture definition.

Write your own Reference Validator

Available visitors

FQCN Description
PhpDA\Parser\Visitor\TagCollector Fetch dependencies from namespaces found in DocBlocks
PhpDA\Parser\Visitor\SuperglobalCollector Fetch dependencies from PHP-Superglobals
PhpDA\Parser\Visitor\UnsupportedEvalCollector Fetch eval expressions to mark them as Unsupported
PhpDA\Parser\Visitor\UnsupportedFuncCollector Fetch dynamic function handler, such as create_function to mark them as Unsupported
PhpDA\Parser\Visitor\UnsupportedVarCollector Fetch dynamic variable declarations, such as $$x to mark them as Unsupported
PhpDA\Parser\Visitor\UnsupportedGlobalCollector Fetch global $foo expressions to mark them as Unsupported
PhpDA\Parser\Visitor\NamespacedStringCollector Fetch strings which looks like a namespace to msrk them as NamespacedString
PhpDA\Parser\Visitor\IocContainerAccessorCollector Fetch accessor methods which looks like a object retrieval to mark them as NamespacedString

Available visitorOptions

Each visitor is configurable by setting visitorOptions.

Property Type Description
excludePattern string Ignore namespaces where pattern is matched. Default is null, which means that filter is disabled
minDepth integer Ignore namespaces where count of namespace parts is less than defined. Default is 0, which means that filter is disabled
sliceOffset integer Filter namespaces with array_slice on their parts. Default is null, which means that filter is disabled
sliceLength integer Filter namespaces with array_slice on their parts. Default is null, which means that filter is disabled

Required Visitors

These built-in visitors are not optional but also configurable by visitorOptions.

FQCN Description
PhpDA\Parser\Visitor\Required\DeclaredNamespaceCollector Fetch dependencies from class names
PhpDA\Parser\Visitor\Required\MetaNamespaceCollector Fetch dependencies from base classes, traits and implementations
PhpDA\Parser\Visitor\Required\UsedNamespaceCollector Fetch dependencies from used class names

Available formatter

FQCN Description
PhpDA\Writer\Strategy\Svg Outputs to scalable vector graphic (SVG)
PhpDA\Writer\Strategy\Script Outputs to a plain graph description language (DOT)
PhpDA\Writer\Strategy\Html Outputs to a HTML file
PhpDA\Writer\Strategy\Json Outputs to a JSON representation