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