Total Complexity | 7 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 94.44% |
Changes | 0 |
1 | <?php |
||
18 | final class SignedShortInteger implements Value |
||
19 | { |
||
20 | private static $definitionSet; |
||
21 | |||
22 | private $value; |
||
23 | private $original; |
||
24 | |||
25 | 18 | public function __construct(Integer $value) |
|
26 | { |
||
27 | 18 | $this->original = $value; |
|
28 | 18 | } |
|
29 | |||
30 | 4 | public static function of(Integer $value): self |
|
31 | { |
||
32 | 4 | if (!self::definitionSet()->contains($value)) { |
|
33 | 4 | throw new OutOfRangeValue($value, self::definitionSet()); |
|
34 | } |
||
35 | |||
36 | return new self($value); |
||
37 | } |
||
38 | |||
39 | 8 | public static function fromStream(Readable $stream): Value |
|
40 | { |
||
41 | 8 | [, $value] = \unpack('s', (string) $stream->read(2)); |
|
42 | |||
43 | 8 | return new self(new Integer($value)); |
|
44 | } |
||
45 | |||
46 | 16 | public function original(): Integer |
|
49 | } |
||
50 | |||
51 | 16 | public function __toString(): string |
|
52 | { |
||
53 | 16 | return $this->value ?? $this->value = \pack('s', $this->original->value()); |
|
54 | } |
||
55 | |||
56 | 4 | public static function definitionSet(): Set |
|
61 | ); |
||
62 | } |
||
63 | } |
||
64 |