Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FromReflection | |
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
3.14 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\ClassInstantiators; |
| 3 | |
| 4 | use Apie\StorageMetadata\Interfaces\ClassInstantiatorInterface; |
| 5 | use Apie\StorageMetadata\Interfaces\StorageDtoInterface; |
| 6 | use ReflectionClass; |
| 7 | use WeakMap; |
| 8 | |
| 9 | final class FromReflection implements ClassInstantiatorInterface |
| 10 | { |
| 11 | public function supports(ReflectionClass $class, ?StorageDtoInterface $storageObject = null): bool |
| 12 | { |
| 13 | return $class->isInstantiable(); |
| 14 | } |
| 15 | |
| 16 | public function create(ReflectionClass $class, ?StorageDtoInterface $storageObject = null): object |
| 17 | { |
| 18 | if ($class->name === WeakMap::class) { |
| 19 | return new WeakMap(); |
| 20 | } |
| 21 | return $class->newInstanceWithoutConstructor(); |
| 22 | } |
| 23 | } |