| Total Complexity | 4 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 75% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | #[Immutable] |
||
| 12 | final class AttributeHelper |
||
| 13 | { |
||
| 14 | private function __construct() |
||
| 15 | { |
||
| 16 | } |
||
| 17 | |||
| 18 | public static function hasAttribute(\ReflectionProperty|\ReflectionClass|\ReflectionMethod|\ReflectionFunction|\ReflectionParameter $target, string $attributeClass): bool |
||
| 19 | { |
||
| 20 | return null !== self::getAttribute($target, $attributeClass); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @template T |
||
| 25 | * |
||
| 26 | * @param class-string<T> $attributeClass |
||
|
|
|||
| 27 | * |
||
| 28 | * @return null|T |
||
| 29 | */ |
||
| 30 | 15 | public static function getAttribute(\ReflectionProperty|\ReflectionClass|\ReflectionMethod|\ReflectionFunction|\ReflectionParameter $target, string $attributeClass): ?object |
|
| 31 | { |
||
| 32 | 15 | return ArrayList::collect(self::getAttributes($target, $attributeClass))->firstElement()->get(); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @template T |
||
| 37 | * |
||
| 38 | * @param class-string<T> $attributeClass |
||
| 39 | * |
||
| 40 | * @return T[] |
||
| 41 | */ |
||
| 42 | 29 | public static function getAttributes(\ReflectionProperty|\ReflectionClass|\ReflectionMethod|\ReflectionFunction|\ReflectionParameter $target, string $attributeClass): array |
|
| 47 | ; |
||
| 48 | } |
||
| 49 | } |
||
| 50 |