Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
81.82% |
9 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DoNotChangeFileNormalizer | |
81.82% |
9 / 11 |
|
0.00% |
0 / 2 |
8.38 | |
0.00% |
0 / 1 |
| supportsNormalization | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
7.05 | |||
| normalize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Serializer\Normalizers; |
| 3 | |
| 4 | use Apie\Core\Actions\ActionResponse; |
| 5 | use Apie\Core\ContextConstants; |
| 6 | use Apie\Core\Enums\DoNotChangeUploadedFile; |
| 7 | use Apie\Serializer\Context\ApieSerializerContext; |
| 8 | use Apie\Serializer\Interfaces\NormalizerInterface; |
| 9 | use Psr\Http\Message\UploadedFileInterface; |
| 10 | |
| 11 | /** |
| 12 | * Special normalizer related to not changing files. |
| 13 | */ |
| 14 | class DoNotChangeFileNormalizer implements NormalizerInterface |
| 15 | { |
| 16 | public function supportsNormalization(mixed $object, ApieSerializerContext $apieSerializerContext): bool |
| 17 | { |
| 18 | if ($apieSerializerContext->getContext()->hasContext(ActionResponse::class)) { |
| 19 | return false; |
| 20 | } |
| 21 | if (!$apieSerializerContext->getContext()->hasContext(ContextConstants::EDIT_OBJECT) |
| 22 | && !$apieSerializerContext->getContext()->hasContext(ContextConstants::REPLACE_OBJECT)) { |
| 23 | return false; |
| 24 | } |
| 25 | if (!$apieSerializerContext->getContext()->hasContext(ContextConstants::DISPLAY_FORM)) { |
| 26 | return false; |
| 27 | } |
| 28 | return is_resource($object) |
| 29 | || $object instanceof UploadedFileInterface |
| 30 | || get_debug_type($object) === 'resource (closed)'; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param resource|UploadedFileInterface $object |
| 35 | */ |
| 36 | public function normalize(mixed $object, ApieSerializerContext $apieSerializerContext): string |
| 37 | { |
| 38 | return DoNotChangeUploadedFile::DoNotChange->value; |
| 39 | } |
| 40 | } |