Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
58.33% covered (warning)
58.33%
7 / 12
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
UploadedFileStrategy
58.33% covered (warning)
58.33%
7 / 12
80.00% covered (warning)
80.00%
4 / 5
8.60
0.00% covered (danger)
0.00%
0 / 1
 supports
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCreationMetadata
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getModificationMetadata
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getResultMetadata
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\Metadata\Strategy;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\Enums\DoNotChangeUploadedFile;
6use Apie\Core\Enums\ScalarType;
7use Apie\Core\FileStorage\StoredFile;
8use Apie\Core\Metadata\EnumMetadata;
9use Apie\Core\Metadata\ScalarMetadata;
10use Apie\Core\Metadata\StoredFileMetadata;
11use Apie\Core\Metadata\StrategyInterface;
12use Apie\Core\Metadata\UnionTypeMetadata;
13use ReflectionClass;
14use ReflectionEnum;
15
16final 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}