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