Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetSearchIndexAttribute | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getValue | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\Attributes; |
| 3 | |
| 4 | use Apie\Core\Entities\EntityInterface; |
| 5 | use Attribute; |
| 6 | use ReflectionClass; |
| 7 | |
| 8 | #[Attribute(Attribute::TARGET_PROPERTY)] |
| 9 | class GetSearchIndexAttribute |
| 10 | { |
| 11 | /** |
| 12 | * @param class-string<object>|null $declaredClass |
| 13 | */ |
| 14 | public function __construct( |
| 15 | public readonly string $methodName, |
| 16 | public readonly ?string $declaredClass = null, |
| 17 | public readonly ?string $arrayValueType = null, |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @param ReflectionClass<EntityInterface> $targetClass |
| 23 | */ |
| 24 | public function getValue(ReflectionClass $targetClass, object $domainObject): mixed |
| 25 | { |
| 26 | $refl = ($this->declaredClass ? new ReflectionClass($this->declaredClass) : $targetClass); |
| 27 | if ($refl->hasMethod($this->methodName)) { |
| 28 | return $refl->getMethod($this->methodName)->invoke($domainObject); |
| 29 | } |
| 30 | return $refl->getProperty($this->methodName)->getValue($domainObject); |
| 31 | } |
| 32 | } |