| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | trait MaybeBelongsToField |
||
| 9 | { |
||
| 10 | private ?string $field = null; |
||
| 11 | |||
| 12 | public function getField(): ?string |
||
| 15 | } |
||
| 16 | |||
| 17 | public function withField(?string $field): static |
||
| 18 | { |
||
| 19 | if ($field !== null) { |
||
| 20 | (new NotEmpty('When provided, the field cannot be left blank'))->validateOrFail($field); |
||
| 21 | } |
||
| 22 | |||
| 23 | $instance = clone $this; |
||
| 24 | $instance->field = $field; |
||
| 25 | return $instance; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function belongsToField(): bool |
||
| 29 | { |
||
| 30 | return $this->field !== null; |
||
| 31 | } |
||
| 32 | |||
| 33 | private function newEmptyValidationResult(): ValidationResult|ValidationResultByField |
||
| 39 | } |
||
| 40 | } |
||
| 41 |