Analysers implements the Visitor pattern in a simple and effective way to make the render of your results truly customizable.
Each Analyser
class must implement interface Bartlett\Reflect\Visitor\VisitorInterface
.
<?php namespace Bartlett\Reflect\Visitor; use Bartlett\Reflect\Model\Visitable; interface VisitorInterface { public function visit(Visitable $visitable); }
Each element that need to be explored by your analyser should have a visit method accordingly.
![]() | |
Abstract class |
<?php use Bartlett\Reflect\Visitor\AbstractVisitor; class Analyser extends AbstractVisitor { public function visitPackageModel($package) { } public function visitClassModel($class) { } public function visitPropertyModel($property) { } public function visitMethodModel($method) { } public function visitFunctionModel($function) { } public function visitParameterModel($parameter) { } public function visitConstantModel($constant) { } public function visitIncludeModel($include) { } public function visitDependencyModel($dependency) { } }
![]() | |
An abstract class Your analyser became as simple like that: <?php use Bartlett\Reflect\Analyser\AbstractAnalyser; class Analyser extends AbstractAnalyser { } |
Once you have used visit methods to explore parsing results, you probably want to display it.
To do so, you should implement the render()
method of Bartlett\Reflect\Analyser\AnalyserInterface
.
Each analyser is responsible to display results with the render()
method.
You can either used the Bartlett\Reflect\Printer\Text
helper to produces report line by line,
or any other solution.
If you used the printer text helper, your implementation should follow only one rule. Return an array with :
Example 19.1. Console lines information (without data)
<?php $lines['dataSourceAnalysed'] = array( '<info>Data Source Analysed</info>%s', array(PHP_EOL) ); $lines['methodsScope'] = array( ' Scope', array() );
Example 19.2. Console line information with only one value
<?php $lines['methods'] = array( ' Methods %10d', array($count['methods']) );
Example 19.3. Console line information with more than one value
<?php $lines['nonStaticMethods'] = array( ' Non-Static Methods %10d (%.2f%%)', array( $count['nonStaticMethods'], $count['methods'] > 0 ? ($count['nonStaticMethods'] / $count['methods']) * 100 : 0, ) );
![]() | |
See source code of Structure Analyser as example. :leveloffset: 0 |