Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
ReflectionPropertyList | |
94.12% |
16 / 17 |
|
50.00% |
1 / 2 |
5.01 | |
0.00% |
0 / 1 |
offsetGet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createFromClass | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | namespace Apie\StorageMetadataBuilder\Lists; |
3 | |
4 | use Apie\Core\Entities\PolymorphicEntityInterface; |
5 | use Apie\Core\Lists\ItemList; |
6 | use Apie\Core\Utils\EntityUtils; |
7 | use ReflectionClass; |
8 | use ReflectionProperty; |
9 | |
10 | final class ReflectionPropertyList extends ItemList |
11 | { |
12 | public function offsetGet(mixed $offset): ReflectionProperty |
13 | { |
14 | return parent::offsetGet($offset); |
15 | } |
16 | |
17 | public static function createFromClass(ReflectionClass $class): self |
18 | { |
19 | $singleCase = function (ReflectionClass $class): array { |
20 | $list = []; |
21 | $visibility = null; |
22 | while ($class) { |
23 | $list = [...$list, ...$class->getProperties($visibility)]; |
24 | $visibility = ReflectionProperty::IS_PRIVATE; |
25 | $class = $class->getParentClass(); |
26 | } |
27 | return $list; |
28 | }; |
29 | $list = []; |
30 | $classes = [$class]; |
31 | if (in_array(PolymorphicEntityInterface::class, $class->getInterfaceNames())) { |
32 | $classes = EntityUtils::getDiscriminatorClasses($class); |
33 | } |
34 | foreach ($classes as $class) { |
35 | $list = [...$list, ...$singleCase($class)]; |
36 | } |
37 | |
38 | return new self($list); |
39 | } |
40 | } |