Total Complexity | 17 |
Total Lines | 129 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | final class EmptyOptional implements OptionalInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var EmptyOptional|null |
||
18 | */ |
||
19 | private static $instance; |
||
20 | |||
21 | 1 | private function __construct() |
|
23 | 1 | } |
|
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 1 | public function filter(callable $predicate): OptionalInterface |
|
29 | { |
||
30 | 1 | return $this; |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 1 | public function map(callable $transformer): OptionalInterface |
|
37 | { |
||
38 | 1 | return $this; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 1 | public function apply(callable $consumer): void |
|
45 | { |
||
46 | 1 | } |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 1 | public function or($value) |
|
52 | { |
||
53 | 1 | return $value; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 1 | public function orSupply(callable $supplier) |
|
60 | { |
||
61 | 1 | return $supplier(); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 2 | public function orThrows($exception = RuntimeException::class) |
|
68 | { |
||
69 | 2 | if (is_string($exception)) { |
|
70 | 1 | $exception = new $exception; |
|
71 | } |
||
72 | |||
73 | 2 | throw $exception; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 2 | public function present(): bool |
|
80 | { |
||
81 | 2 | return false; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 1 | public function get() |
|
88 | { |
||
89 | 1 | return null; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 1 | public function __call(string $name, array $arguments): OptionalInterface |
|
96 | { |
||
97 | 1 | return $this; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 1 | public function __get(string $name): OptionalInterface |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 1 | public function __isset(string $name): bool |
|
112 | { |
||
113 | 1 | return false; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 1 | public function __set(string $name, $value): void |
|
120 | { |
||
121 | 1 | } |
|
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | 1 | public function stream(): StreamInterface |
|
127 | { |
||
128 | 1 | return EmptyStream::instance(); |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get the EmptyOptional instance |
||
133 | * |
||
134 | * @return EmptyOptional |
||
135 | */ |
||
136 | 27 | public static function instance(): EmptyOptional |
|
143 | } |
||
144 | } |
||
145 |