Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
58.33% |
7 / 12 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
UploadedFileStrategy | |
58.33% |
7 / 12 |
|
80.00% |
4 / 5 |
8.60 | |
0.00% |
0 / 1 |
supports | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCreationMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModificationMetadata | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getResultMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\Core\Metadata\Strategy; |
3 | |
4 | use Apie\Core\Context\ApieContext; |
5 | use Apie\Core\Enums\DoNotChangeUploadedFile; |
6 | use Apie\Core\Enums\ScalarType; |
7 | use Apie\Core\FileStorage\StoredFile; |
8 | use Apie\Core\Metadata\EnumMetadata; |
9 | use Apie\Core\Metadata\ScalarMetadata; |
10 | use Apie\Core\Metadata\StoredFileMetadata; |
11 | use Apie\Core\Metadata\StrategyInterface; |
12 | use Apie\Core\Metadata\UnionTypeMetadata; |
13 | use ReflectionClass; |
14 | use ReflectionEnum; |
15 | |
16 | final class UploadedFileStrategy implements StrategyInterface |
17 | { |
18 | public static function supports(ReflectionClass $class): bool |
19 | { |
20 | do { |
21 | if ($class->name === StoredFile::class) { |
22 | return true; |
23 | } |
24 | } while ($class = $class->getParentClass()); |
25 | return false; |
26 | } |
27 | |
28 | /** |
29 | * @param ReflectionClass<StoredFile> $class |
30 | */ |
31 | public function __construct(private readonly ReflectionClass $class) |
32 | { |
33 | } |
34 | |
35 | public function getCreationMetadata(ApieContext $context): StoredFileMetadata |
36 | { |
37 | return new StoredFileMetadata($this->class, false, true); |
38 | } |
39 | |
40 | public function getModificationMetadata(ApieContext $context): UnionTypeMetadata |
41 | { |
42 | return new UnionTypeMetadata( |
43 | new EnumMetadata(new ReflectionEnum(DoNotChangeUploadedFile::class)), |
44 | new StoredFileMetadata($this->class, false, false), |
45 | new ScalarMetadata((ScalarType::NULLVALUE)), |
46 | ); |
47 | } |
48 | |
49 | public function getResultMetadata(ApieContext $context): StoredFileMetadata |
50 | { |
51 | return new StoredFileMetadata($this->class, true, false); |
52 | } |
53 | } |