Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
81.82% |
9 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
FromStoredFile | |
81.82% |
9 / 11 |
|
0.00% |
0 / 2 |
5.15 | |
0.00% |
0 / 1 |
supports | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
create | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 |
1 | <?php |
2 | namespace Apie\StorageMetadata\ClassInstantiators; |
3 | |
4 | use Apie\Core\FileStorage\StoredFile; |
5 | use Apie\StorageMetadata\Interfaces\ClassInstantiatorInterface; |
6 | use Apie\StorageMetadata\Interfaces\StorageDtoInterface; |
7 | use Psr\Http\Message\UploadedFileInterface; |
8 | use ReflectionClass; |
9 | |
10 | final class FromStoredFile implements ClassInstantiatorInterface |
11 | { |
12 | public function supports(ReflectionClass $class, ?StorageDtoInterface $storageObject = null): bool |
13 | { |
14 | if ($class->name === UploadedFileInterface::class) { |
15 | return true; |
16 | } |
17 | if ($storageObject === null) { |
18 | return false; |
19 | } |
20 | return in_array(UploadedFileInterface::class, $class->getInterfaceNames()); |
21 | } |
22 | |
23 | public function create(ReflectionClass $class, ?StorageDtoInterface $storageObject = null): object |
24 | { |
25 | assert($storageObject !== null); |
26 | $classReference = $storageObject->getClassReference(); |
27 | if ($classReference->name === UploadedFileInterface::class) { |
28 | $classReference = new ReflectionClass(StoredFile::class); |
29 | } |
30 | return $classReference->getMethod('createFromDto') |
31 | ->invoke(null, $storageObject); |
32 | } |
33 | } |