Analysers implements the Visitor pattern in a simple and effective way to make the render of your results truly customizable.

Visitor pattern

Each Analyser class must implement interface Bartlett\Reflect\Visitor\VisitorInterface.

Abstract visitor is a component of Reflect, and not CompatInfo. Take care of namespace !
<?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.

  • For packages, we need to implement a visitPackageModel method.

  • For classes, we need to implement a visitClassModel method.

  • For properties, we need to implement a visitPropertyModel method.

  • For methods, we need to implement a visitMethodModel method.

  • For functions, we need to implement a visitFunctionModel method.

  • For constants, we need to implement a visitConstantModel method.

  • For includes, we need to implement a visitIncludeModel method.

  • For dependencies, we need to implement a visitDependencyModel method.

Abstract class Bartlett\Reflect\Visitor\AbstractVisitor, that implement interface Bartlett\Reflect\Visitor\VisitorInterface, holds a basic visitor.
<?php

use Bartlett\Reflect\Visitor\AbstractVisitor;

class Analyser extends AbstractVisitor
{
    public function visitPackageModel($package)
    {
    }

    public function visitClassModel($class)
    {
    }

    public function visitMethodModel($method)
    {
    }

    public function visitPropertyModel($property)
    {
    }

    public function visitFunctionModel($function)
    {
    }

    public function visitConstantModel($constant)
    {
    }

    public function visitIncludeModel($include)
    {
    }

    public function visitDependencyModel($dependency)
    {
    }
}

An abstract class Bartlett\Reflect\Analyser\AbstractAnalyser that implement all required interfaces may be used to initialize common data in a simple way.

Your analyser became as simple like that:

<?php

use Bartlett\Reflect\Analyser\AbstractAnalyser;

class Analyser extends AbstractAnalyser
{
}

Print results

Once you have used visit methods to explore parsing results, you will need to return formatted data ready to be print.

To do so, you should implement the render() method of Bartlett\Reflect\Analyser\AnalyserInterface.