diff --git a/core/Common/Reflection.php b/core/Common/Reflection.php index 686f5b6e..3ca4779a 100644 --- a/core/Common/Reflection.php +++ b/core/Common/Reflection.php @@ -175,6 +175,37 @@ public static function fetchTraits( return \array_unique($traits); } + /** + * Fetch the attributes of every case of an enum. + * + * Every case is present in the result, in declaration order, so a caller can walk the enum once and + * fall back to a default where a case carries nothing. + * + * @template T of object + * + * @param \ReflectionEnum|class-string<\UnitEnum> $enum + * @param class-string|null $attributeClass If provided, only attributes of this class will be returned. + * @param int $flags Flags to pass to {@see \ReflectionEnumUnitCase::getAttributes()}. + * + * @return ($attributeClass is null + * ? array> + * : array>>) Attributes keyed by case name. + */ + public static function fetchEnumCaseAttributes( + \ReflectionEnum|string $enum, + ?string $attributeClass = null, + int $flags = 0, + ): array { + \is_string($enum) and $enum = new \ReflectionEnum($enum); + + $attributes = []; + foreach ($enum->getCases() as $case) { + $attributes[$case->name] = $case->getAttributes($attributeClass, $flags); + } + + return $attributes; + } + /** * Find all methods in a class that have a specific attribute. * diff --git a/core/Core/Metric/Memory.php b/core/Core/Metric/Memory.php new file mode 100644 index 00000000..1f58cb00 --- /dev/null +++ b/core/Core/Metric/Memory.php @@ -0,0 +1,34 @@ +name, + $to::class, + $to->name, + )); + } +} diff --git a/core/Metric/Exception/InvalidUnitDeclaration.php b/core/Metric/Exception/InvalidUnitDeclaration.php new file mode 100644 index 00000000..8d9ffa10 --- /dev/null +++ b/core/Metric/Exception/InvalidUnitDeclaration.php @@ -0,0 +1,30 @@ +` is distinct from a `Metric