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