Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
28.57% |
2 / 7 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Typehint | |
28.57% |
2 / 7 |
|
66.67% |
2 / 3 |
19.12 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFromPrimitive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFromObject | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | namespace Apie\Serializer\PropertySerializer; |
| 3 | |
| 4 | use Apie\Core\Lists\ItemHashmap; |
| 5 | use Apie\Core\Lists\ItemList; |
| 6 | use Apie\Core\Lists\ItemSet; |
| 7 | |
| 8 | final class Typehint |
| 9 | { |
| 10 | public function __construct( |
| 11 | public readonly TypeDefinition $type, |
| 12 | public readonly string|int|float|bool|null|TypehintMap $value |
| 13 | ) { |
| 14 | } |
| 15 | |
| 16 | public static function createFromPrimitive(string|int|float|bool|null $value): self |
| 17 | { |
| 18 | return new self(TypeDefinition::from(get_debug_type($value)), $value); |
| 19 | } |
| 20 | |
| 21 | public static function createFromObject(object $object, TypehintMap $properties): self |
| 22 | { |
| 23 | if ($object instanceof ItemHashmap) { |
| 24 | return new self(TypeDefinition::Map, $properties); |
| 25 | } |
| 26 | if ($object instanceof ItemList || $object instanceof ItemSet) { |
| 27 | return new self(TypeDefinition::Array, $properties); |
| 28 | } |
| 29 | return new self(TypeDefinition::ObjectReference, spl_object_hash($object)); |
| 30 | } |
| 31 | } |