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