-
Notifications
You must be signed in to change notification settings - Fork 43
4. Examples
This illustrates an Usage-Graph with aggregated dependencies to package level, which includes a cycle violation between PackageA, PackageB and PackageC. Aggregation is reached by visitorOptions configuration.
sliceLength leads to aggregate found namespaces of dependencies.
Used configuration
mode: 'usage'
source: './examples'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/packages.svg'
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollector
visitorOptions:
PhpDA\Parser\Visitor\Required\DeclaredNamespaceCollector: {minDepth: 2, sliceLength: 1}
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}It illustrates an Usage-Graph with aggregated dependencies to layer level. Each namespace is grouped to their package. This analysis is performed with a ReferenceValidator (see used ExampleValidator) to verify dependecies. It includes a violation between Controller and Mapper. A controller should not permitted to access a mapper directly. For demonstration purposes it also incudes a violation between PackageB and PackageC which is detected in Service-Layer.
Used configuration
mode: 'usage'
source: './examples/Project/PackageB'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/layers.svg'
referenceValidator: 'MyDomain\Plugin\ReferenceValidator'
groupLength: 1
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollector
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:
MyDomain\Plugin\ReferenceValidator: '../../../_data/Plugin/ReferenceValidator.php'It illustrates a complex cycle violation inside a module by..
FilterA->FilterB->FilterC->FilterD->FilterA.
You can also see that each filter implements FilterInterface.
Used configuration
mode: 'usage'
source: './examples/Project/PackageC/Filter'
filePattern: '*.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/complex-cycle.svg'
groupLength: 3Here you can see an inheritance structure. Each inheritance dependency is drawn by a dashed arrow. Except in case of aggregation of dependencies dashed arrows are always used for an inherit dependency. An inheritance dependency can be an implementation, a class-extending or a trait-use.
Used configuration
mode: 'inheritance'
source: './src/Writer'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/inheritance.svg'
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollector
visitorOptions:
PhpDA\Parser\Visitor\Required\DeclaredNamespaceCollector: {minDepth: 2}
PhpDA\Parser\Visitor\Required\MetaNamespaceCollector: {minDepth: 2}
PhpDA\Parser\Visitor\TagCollector: {minDepth: 2}This graph illustrates only call dependencies. A call can be a method parameter, a method return-value or an instance creation.
Used configuration
mode: 'call'
source: './src/Plugin'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/call.svg'
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollectorIt illustrates an Usage-Graph of dependencies on class level. You can see that functions are also to be subject to namespacing.
Used configuration
mode: 'usage'
source: './examples/Project/PackageA/Service'
filePattern: 'Command.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/class.svg'
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollectorIt's like the first example:
This illustrates an Usage-Graph with aggregated dependencies to package level, which includes a cycle violation between PackageA, PackageB and PackageC. Aggregation is reached by visitorOptions configuration.
sliceLength leads to aggregate found namespaces of dependencies.
We are using a NamespaceFilter (see used ExampleFilter) to convert Zend namespaces to Framework just for demonstration purpose.
Used configuration
mode: 'usage'
source: '../../Project'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: '../../../_output/svg/namespace-filter.svg'
namespaceFilter: 'MyDomain\Plugin\NamespaceFilter'
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollector
visitorOptions:
PhpDA\Parser\Visitor\Required\DeclaredNamespaceCollector: {minDepth: 2, sliceLength: 1}
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:
MyDomain\Plugin\NamespaceFilter: '../../../_data/Plugin/NamespaceFilter.php'It illustrates a Usage-Graph of dependencies for an entire project. Its possible to perform this but you also see that is not really visitable.
Used configuration
mode: 'usage'
source: './examples'
filePattern: '*.php'
ignore: 'tests'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/total.svg'
groupLength: 1
visitor:
- PhpDA\Parser\Visitor\TagCollector
- PhpDA\Parser\Visitor\SuperglobalCollectorParsing PHP7 Return Type Declarations
It illustrates the compatibility to the new PHP7 Return Type Declarations feature based on ReturnValue Stub.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'ReturnType.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/return-type.svg'Parsing PHP7 Anonymous Classes
It illustrates the compatibility to the new PHP7 Anonymous Classes feature based on AnonymousClass Stub.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'AnonymousClass.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/anonymous-class.svg'It illustrates the capabilities of the PhpDA\Parser\Visitor\TagCollector for parsing PhpDocBlocks.
Just check the DocBlockTag Stub for this demonstration.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'DocBlockTag.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/docblock.svg'
visitor:
- PhpDA\Parser\Visitor\TagCollectorDemonstration of the capabilities of the PhpDA\Parser\Visitor\SuperglobalCollector based on the SuperGlobalAccess Stub.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'SuperGlobalAccess.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/superglobals.svg'
visitor:
- PhpDA\Parser\Visitor\SuperglobalCollectorDemonstration for collecting Constants as dependencies based on the Constant Stub.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'Constant.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/constant.svg'Demonstration of the capabilities of the PhpDA\Parser\Visitor\NamespacedStringCollector and PhpDA\Parser\Visitor\IocContainerAccessorCollector based on the NamespacedString Stub. Those dependecies are approximated and detected in strings. Of course they are not resolvable to real namespaces, therefore they are yellow colored and must be checked manually.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'NamespacedString.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/namespaced-strings.svg'
visitor:
- PhpDA\Parser\Visitor\NamespacedStringCollector
- PhpDA\Parser\Visitor\IocContainerAccessorCollectorDemonstration of the capabilities of the PhpDA\Parser\Visitor\Unsupported*Collector based on the UnsupportedStatement Stub. All found unsupported statements are red colored, because they are not resolvable and must be checked manually.
Used configuration
mode: 'usage'
source: './examples/Project/tests/stubs'
filePattern: 'UnsupportedStatement.php'
formatter: 'PhpDA\Writer\Strategy\Svg'
target: './examples/unsupported-stmt.svg'
visitor:
- PhpDA\Parser\Visitor\UnsupportedEvalCollector
- PhpDA\Parser\Visitor\UnsupportedFuncCollector
- PhpDA\Parser\Visitor\UnsupportedVarCollector
- PhpDA\Parser\Visitor\UnsupportedGlobalCollector