diff --git a/src/Collector/Collector.php b/src/Collector/Collector.php index 612335e..2e7cda7 100644 --- a/src/Collector/Collector.php +++ b/src/Collector/Collector.php @@ -33,7 +33,7 @@ public function collect(): Result foreach ($executingGroup->metrics as $executingMetric) { $metricHandler = $this->runtimeConfiguration->getMetric($executingMetric->metric); - $event = new BeforeMetricCalculate($metricHandler, $executingMetric->options); + $event = new BeforeMetricCalculate($executingMetric, $executingMetric->options); $this->runtimeConfiguration->getEventDispatcher()->dispatch($event); $metricResult = $metricHandler->calculate($event->getOptions()); diff --git a/src/Configuration/ConfigurationFile.php b/src/Configuration/ConfigurationFile.php index 0c41f16..b8ee263 100644 --- a/src/Configuration/ConfigurationFile.php +++ b/src/Configuration/ConfigurationFile.php @@ -97,7 +97,7 @@ private static function buildMetricGroupConfig(array $metricGroupConfig): array $metricGroup[] = new MetricGroup( $groupIdentifier, $options['title'] ?? '', - self::convertToMetricConfig($options['metrics'] ?? []), + self::convertToMetricConfig($groupIdentifier, $options['metrics'] ?? []), ); } @@ -109,7 +109,7 @@ private static function buildMetricGroupConfig(array $metricGroupConfig): array * * @return list */ - private static function convertToMetricConfig(array $metricConfig): array + private static function convertToMetricConfig(string $groupIdentifier, array $metricConfig): array { $metrics = []; foreach ($metricConfig as $identifier => $options) { @@ -123,6 +123,9 @@ private static function convertToMetricConfig(array $metricConfig): array // Take the metric not from the key but from the option $metric = $options['metric']; unset($options['metric']); + } else { + // Because the name of the metric was utilized as key it is not unique, so combine it with the group + $identifier = $groupIdentifier . '.' . $identifier; } $metrics[] = new Metric($identifier, $metric, $title, $options); diff --git a/src/Configuration/ConfigurationFile/MetricGroup.php b/src/Configuration/ConfigurationFile/MetricGroup.php index bce93a7..bcd6763 100644 --- a/src/Configuration/ConfigurationFile/MetricGroup.php +++ b/src/Configuration/ConfigurationFile/MetricGroup.php @@ -6,13 +6,13 @@ use Panaly\Configuration\Exception\InvalidConfigurationFile; -class MetricGroup +readonly class MetricGroup { /** @param list $metrics */ public function __construct( - public readonly string $identifier, - public readonly string $title, - public readonly array $metrics, + public string $identifier, + public string $title, + public array $metrics, ) { if ($this->identifier === '') { throw InvalidConfigurationFile::metricGroupMustNotHaveABlankName(); diff --git a/src/Event/BeforeMetricCalculate.php b/src/Event/BeforeMetricCalculate.php index 4710311..d8499c2 100644 --- a/src/Event/BeforeMetricCalculate.php +++ b/src/Event/BeforeMetricCalculate.php @@ -4,12 +4,12 @@ namespace Panaly\Event; -use Panaly\Plugin\Plugin\Metric; +use Panaly\Configuration\ConfigurationFile\Metric; final class BeforeMetricCalculate { public function __construct( - public readonly Metric $plugin, + public readonly Metric $metricConfiguration, private array $options, ) { } diff --git a/tests/Configuration/ConfigurationFileTest.php b/tests/Configuration/ConfigurationFileTest.php index b5c0607..cc39e0a 100644 --- a/tests/Configuration/ConfigurationFileTest.php +++ b/tests/Configuration/ConfigurationFileTest.php @@ -79,13 +79,13 @@ public function testThatCreatingWithMetricGroupsIsValid(): void self::assertCount(3, $configurationFile->metricGroups[0]->metrics); // The "baz" metric - self::assertSame('baz', $configurationFile->metricGroups[0]->metrics[0]->identifier); + self::assertSame('foo.baz', $configurationFile->metricGroups[0]->metrics[0]->identifier); self::assertSame('baz', $configurationFile->metricGroups[0]->metrics[0]->metric); self::assertSame('foo_baz', $configurationFile->metricGroups[0]->metrics[0]->title); self::assertSame(['foo' => 'bar'], $configurationFile->metricGroups[0]->metrics[0]->options); // The "quo" metric - self::assertSame('quo', $configurationFile->metricGroups[0]->metrics[1]->identifier); + self::assertSame('foo.quo', $configurationFile->metricGroups[0]->metrics[1]->identifier); self::assertSame('quo', $configurationFile->metricGroups[0]->metrics[1]->metric); self::assertNull($configurationFile->metricGroups[0]->metrics[1]->title); self::assertSame(['foo' => 'baz'], $configurationFile->metricGroups[0]->metrics[1]->options);