Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.00% |
1 / 5 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| EntitySnapshotLeaf | |
20.00% |
1 / 5 |
|
33.33% |
1 / 3 |
12.19 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applies | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| normalize | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\Other; |
| 3 | |
| 4 | use Apie\Common\Enums\AccessDenied; |
| 5 | use Apie\Core\Attributes\ApieContextAttribute; |
| 6 | use Apie\Serializer\Context\ApieSerializerContext; |
| 7 | |
| 8 | /** |
| 9 | * Represents a scalar value of an entity snapshot. |
| 10 | */ |
| 11 | class EntitySnapshotLeaf implements EntitySnapshotInstance |
| 12 | { |
| 13 | public function __construct( |
| 14 | private readonly string|int|float|bool|null $scalar, |
| 15 | public readonly ApieContextAttribute $context |
| 16 | ) { |
| 17 | } |
| 18 | |
| 19 | public function applies(ApieSerializerContext $apieSerializerContext): bool |
| 20 | { |
| 21 | return $this->context->applies($apieSerializerContext->getContext()); |
| 22 | } |
| 23 | |
| 24 | public function normalize(ApieSerializerContext $apieSerializerContext): string|int|float|bool|null|AccessDenied |
| 25 | { |
| 26 | if (!$this->applies($apieSerializerContext)) { |
| 27 | return AccessDenied::Denied; |
| 28 | } |
| 29 | return $this->scalar; |
| 30 | } |
| 31 | } |