Total Complexity | 8 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | final class Container implements \JsonSerializable |
||
9 | { |
||
10 | /** |
||
11 | * Container ID |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | private $id; |
||
16 | |||
17 | /** |
||
18 | * @param string $id |
||
19 | */ |
||
20 | 15 | public function __construct($id) |
|
21 | { |
||
22 | 15 | $this->assertId($id); |
|
23 | |||
24 | 14 | $this->id = $id; |
|
25 | 14 | } |
|
26 | |||
27 | /** |
||
28 | * @param mixed $id |
||
29 | * |
||
30 | * @return void |
||
31 | * |
||
32 | * @throws \InvalidArgumentException |
||
33 | */ |
||
34 | 15 | private function assertId($id) |
|
35 | { |
||
36 | 15 | if (null !== $id && false === is_string($id)) { |
|
37 | 1 | throw new \InvalidArgumentException('[id] must be one of these types: string or null.'); |
|
38 | } |
||
39 | 14 | } |
|
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | 1 | public function id() |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return Container |
||
51 | */ |
||
52 | 11 | public static function discover() |
|
53 | { |
||
54 | 11 | return new self( |
|
55 | 11 | ControlGroups::instance()->containerId() |
|
56 | 11 | ); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return array|null |
||
61 | */ |
||
62 | 2 | public function jsonSerialize() |
|
70 | 1 | ]; |
|
71 | } |
||
72 | } |
||
73 |