Enrichers¶
How do they work?¶
Enrichers can add extra data to a data holder. Supported data holders are:
ProjectFileClass_Trait_Interface_ConstantPropertyMethodFunction_Argument
Enrichers come with a 3 phase process:
1. Create¶
Before dog parses all project files each enricher is initialized by
calling create(string $id, ConfigurationInterface $config) to set its id and the current dog configuration.
2. Prepare¶
After initializing all enrichers prepare() is called for each enricher.
In this phase enricher should validate its configuration, then gather and prepare data that is later on needed to enrich data holders. Typical preparation tasks are reading and parsing files from processes that have run before dog.
3: Enrich¶
After dog did build the Project each enricher then visits all Project related data holders.
In this phase enricher can add data be calling setData(string $id, $value) on the data holder.
Using the enricher id here is best practise.
Note
All enricher first visit the project and then the elements.
Access Data in Templates¶
Enriched data can be accessed be calling getData(string $id) on Project or Element items - eg for the
PHPLOCEnricher with id phploc:
{% for key, value in project.data('phploc') %}
{{ '- '~key }}{{ ' = '~value }}
{% endfor %}
Bundled Enricher¶
clover¶
Reads and parses test coverage clover xml file generated by tools like phpunit and codeception.
Added data:
Project: object of\Klitsche\Dog\Enrichers\Clover\ProjectMetricsClass: object of\Klitsche\Dog\Enrichers\Clover\ClassMetricsTrait: object of\Klitsche\Dog\Enrichers\Clover\ClassMetricsMethod: object of\Klitsche\Dog\Enrichers\Clover\MethodMetrics
You have to run your tests with coverage upfront - eg.:
vendor/bin/phpunit --coverage-clover=clover.xml
Configure like:
enrichers:
clover:
class: \Klitsche\Dog\Enrichers\Clover\CloverEnricher
file: clover.xml
phploc¶
Reads and parses the json output file generated by phploc.
Data added:
Project: json decoded result
You have to run phploc upfront - eg. like:
php phploc.phar --log-json=phploc.json src
Configure like:
enrichers:
phploc:
class: \Klitsche\Dog\Enrichers\PHPLOC\PHPLOCEnricher
file: phploc.json
extendedBy¶
Collects a list of extending classes for each class and a list of extending interfaces for each interface.
Data added:
Interface_: array ofInterface_objectsClass_: array ofClass_objects
Configure like:
enrichers:
extendedBy:
class: \Klitsche\Dog\Enrichers\ExtendedBy\ExtendedByEnricher
implementedBy¶
Collects a list of implementing classes for each interface.
Data added:
Interface_: array ofClass_objects
Configure like:
enrichers:
implementedBy:
class: \Klitsche\Dog\Enrichers\ImplementedBy\ImplementedByEnricher
usedBy¶
Collects a list of using classes and traits for each trait.
Data added:
Trait_: array ofClass_andTraitobjects `` Configure like:
enrichers:
usedBy:
class: \Klitsche\Dog\Enrichers\UsedBy\UsedByEnricher
Custom enricher¶
- A Enricher must implement
Klitsche\Dog\Enrichers\EnricherInterface - Best practise: enricher extends the abstract class
Klitsche\Dog\Enrichers\Enricher - Data holders must implement
Klitsche\Dog\Enrichers\DataAwareInterface - Best practise: use its enricher id to add extra data to data holders
- Extra data can be scalar values or objects