Total Complexity | 11 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
8 | final class Type |
||
9 | { |
||
10 | private const METHOD = 1; |
||
11 | private const HEADER = 2; |
||
12 | private const BODY = 3; |
||
13 | private const HEARTBEAT = 8; |
||
14 | |||
15 | private static $method; |
||
16 | private static $header; |
||
17 | private static $body; |
||
18 | private static $heartbeat; |
||
19 | |||
20 | private $value; |
||
21 | |||
22 | 4 | private function __construct(int $value) |
|
25 | 4 | } |
|
26 | |||
27 | 186 | public static function method(): self |
|
28 | { |
||
29 | 186 | return self::$method ?? self::$method = new self(self::METHOD); |
|
30 | } |
||
31 | |||
32 | 62 | public static function header(): self |
|
33 | { |
||
34 | 62 | return self::$header ?? self::$header = new self(self::HEADER); |
|
35 | } |
||
36 | |||
37 | 54 | public static function body(): self |
|
40 | } |
||
41 | |||
42 | 108 | public static function heartbeat(): self |
|
43 | { |
||
44 | 108 | return self::$heartbeat ?? self::$heartbeat = new self(self::HEARTBEAT); |
|
45 | } |
||
46 | |||
47 | 114 | public static function fromInt(int $value): self |
|
48 | { |
||
49 | switch ($value) { |
||
50 | 114 | case self::METHOD: |
|
51 | 98 | return self::method(); |
|
52 | |||
53 | 50 | case self::HEADER: |
|
54 | 36 | return self::header(); |
|
55 | |||
56 | 46 | case self::BODY: |
|
57 | 36 | return self::body(); |
|
58 | |||
59 | 10 | case self::HEARTBEAT: |
|
60 | 4 | return self::heartbeat(); |
|
61 | |||
62 | default: |
||
63 | 6 | throw new UnknownFrameType((string) $value); |
|
64 | } |
||
65 | } |
||
66 | |||
67 | 200 | public function toInt(): int |
|
70 | } |
||
71 | } |
||
72 |