Total Complexity | 8 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
17 | final class CanBeNull implements ExposesDataKey |
||
18 | { |
||
19 | private $or; |
||
20 | |||
21 | private function __construct(ExposesDataKey $mapping) |
||
22 | { |
||
23 | $this->or = $mapping; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Creates a new nullable type wrapper. |
||
28 | * |
||
29 | * @param ExposesDataKey $mapping The mapping to decorate. |
||
30 | * @return self The nullable mapping. |
||
31 | */ |
||
32 | public static function or(ExposesDataKey $mapping): self |
||
33 | { |
||
34 | return new self($mapping); |
||
35 | } |
||
36 | |||
37 | /** @inheritdoc */ |
||
38 | public function value(array $data, $owner = null) |
||
39 | { |
||
40 | if (is_null($this->my($data))) { |
||
41 | return null; |
||
42 | } |
||
43 | return $this->or->value($data, $owner); |
||
44 | } |
||
45 | |||
46 | /** @inheritdoc */ |
||
47 | public function name(): string |
||
48 | { |
||
49 | return $this->or->name(); |
||
50 | } |
||
51 | |||
52 | /** @inheritdoc */ |
||
53 | public function key(): string |
||
54 | { |
||
55 | return $this->or->key(); |
||
56 | } |
||
57 | |||
58 | /** @throws UnmappableInput */ |
||
59 | private function my(array $data) |
||
66 | } |
||
67 | } |
||
68 |