Skip to content

Commit

Permalink
Add event that is triggered before storage and reporting engine to al…
Browse files Browse the repository at this point in the history
…low modification of result
  • Loading branch information
DZunke committed Apr 6, 2024
1 parent 7383a68 commit e4cd019
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

This project targets to deliver an extendable tool to analyze a projects sourcecode for some metrics. Have a code
coverage report? Some baselines for static analyzer that you want to keep in mind? Just file system metrics? Get
them all together based on your custom configuration and get a reporting of your mind for it.
them all together based on your custom configuration and get a reporting of your mind for it.

The plugin system ensures that it is possible to customize every step from the configuration to the collection of
the metrics and over to storage and reporting. Later on even more access with active event listening will be enabled
so that every plugin can form the way a projects analyzer tools bring their numbers together.
so that every plugin can form the way a projects analyzer tools bring their numbers together.

## Setup
## Setup

> :warning: Open TODO - Work in Progress Project
## Usage

In default the CLI Command will search for a config file `panaly.dist.yaml` which can be overwritten by giving the
In default the CLI Command will search for a config file `panaly.dist.yaml` which can be overwritten by giving the
config file with the CLI Command like `vendor/bin/panaly -c my-own-config.yaml`.

## Example Configuration
Expand Down Expand Up @@ -69,10 +69,11 @@ The event section is work in progress as there is currently no real way to regis
become available later so that plugins are also enabled to hook into the events instead of delivering metrics,
reporting or storages to the process.
| Event | Description |
|---------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ConfigurationLoaded | The event is dispatched directly after the `ConfigurationFile` was loaded. It allows to overwrite the full configuration by delivering a new instance that will then be taken for the process. |
| RuntimeLoaded | After the configuration was fully loaded and converted to the `RuntimeConfiguration` this event is triggered, it is the last possibility to change the metric running process. |
| Event | Description |
|------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Panaly\Configuration\ConfigurationFile\ConfigurationLoaded | The event is dispatched directly after the `ConfigurationFile` was loaded. It allows to overwrite the full configuration by delivering a new instance that will then be taken for the process. |
| Panaly\Configuration\ConfigurationFile\RuntimeLoaded | After the configuration was fully loaded and converted to the `RuntimeConfiguration` this event is triggered, it is the last possibility to change the metric running process. |
| Panaly\Configuration\ConfigurationFile\MetricResultCreated | When the collection, or execution, of configured metric groups is finished the event is triggered with all information and the result can be modified before the storage and reporting runs. The full environment is given her with the `ConfigurationFile`, the `RuntimeConfiguration` and the `Result` |

## Thanks and License

Expand Down
23 changes: 19 additions & 4 deletions bin/panaly
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

declare(strict_types=1);

use Panaly\Collector\Collector;
use Panaly\Configuration;
use Panaly\Event\ConfigurationLoaded;
use Panaly\Event\MetricResultCreated;
use Panaly\Event\RuntimeLoaded;
use Panaly\Reporting\Handler as ReportingHandler;
use Panaly\Storage\Handler as StorageHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
use Symfony\Component\Console\Style\SymfonyStyle;
use Panaly\Collector\Collector;
use Panaly\Reporting\Handler as ReportingHandler;
use Panaly\Storage\Handler as StorageHandler;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -35,13 +36,27 @@ require __DIR__ . '/../vendor/autoload.php';
$runtimeConfiguration = new Configuration\RuntimeConfiguration();
$configurationFile = (new Configuration\ConfigurationFileLoader())->loadFromFile($input->getOption('config'));

// The configuration file is parsed, so allow to change the configuration when there is any need for it, before the plugins are loaded
$runtimeConfiguration->getEventDispatcher()->dispatch($event = new ConfigurationLoaded($configurationFile));

// Load the plugins to get knowledge about all registered components for the runtime cofiguratioon
(new Configuration\PluginLoader())->load($event->getConfigurationFile(), $runtimeConfiguration);
// TODO: Add a validation thingy here ... so the full configuration is validated against the runtime

// Give the possibility to change the runtime configuration before the metric collection starts
$runtimeConfiguration->getEventDispatcher()->dispatch(new RuntimeLoaded($runtimeConfiguration));

// TODO: Add a validation thingy here ... so the full configuration file is validated against the now existing runtime

// Execute the metric collection to get a result of all configured collection results
$collectionResult = (new Collector($configurationFile, $runtimeConfiguration))->collect();

// Give the possibility to change the result before the storage and reporting engine are running
$runtimeConfiguration->getEventDispatcher()->dispatch(new MetricResultCreated(
$configurationFile,
$runtimeConfiguration,
$collectionResult
));

(new StorageHandler($configurationFile, $runtimeConfiguration))->handle($collectionResult);
(new ReportingHandler($configurationFile, $runtimeConfiguration))->handle($collectionResult);

Expand Down
19 changes: 19 additions & 0 deletions src/Event/MetricResultCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Panaly\Event;

use Panaly\Configuration\ConfigurationFile;
use Panaly\Configuration\RuntimeConfiguration;
use Panaly\Result\Result;

final readonly class MetricResultCreated
{
public function __construct(
public ConfigurationFile $configurationFile,
public RuntimeConfiguration $runtimeConfiguration,
public Result $result,
) {
}
}

0 comments on commit e4cd019

Please sign in to comment.