Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FromReflection
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
3.14
0.00% covered (danger)
0.00%
0 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 create
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2namespace Apie\StorageMetadata\ClassInstantiators;
3
4use Apie\StorageMetadata\Interfaces\ClassInstantiatorInterface;
5use Apie\StorageMetadata\Interfaces\StorageDtoInterface;
6use ReflectionClass;
7use WeakMap;
8
9final 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}