Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ManyToOneAttribute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReflectionProperty | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\Attributes; |
| 3 | |
| 4 | use Attribute; |
| 5 | use ReflectionClass; |
| 6 | use ReflectionException; |
| 7 | use ReflectionProperty; |
| 8 | |
| 9 | #[Attribute(Attribute::TARGET_PROPERTY)] |
| 10 | class ManyToOneAttribute |
| 11 | { |
| 12 | public function __construct( |
| 13 | private string $propertyName |
| 14 | ) { |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @template T of object |
| 19 | * @param ReflectionClass<T> $targetClass |
| 20 | * @param T $instance |
| 21 | */ |
| 22 | public function getReflectionProperty(ReflectionClass $targetClass, object $instance): ?ReflectionProperty |
| 23 | { |
| 24 | $property = $targetClass->getProperty($this->propertyName); |
| 25 | try { |
| 26 | $property->isInitialized($instance); |
| 27 | return $property; |
| 28 | } catch (ReflectionException) { |
| 29 | return null; |
| 30 | } |
| 31 | } |
| 32 | } |