MaybeBelongsToField::newEmptyValidationResult()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation;
5
6
trait MaybeBelongsToField
7
{
8
    private ?string $field = null;
9
10
    public function getField(): ?string
11
    {
12
        return $this->field;
13
    }
14
15
    public function setField(?string $field): self
16
    {
17
        $this->field = $field;
18
        return $this;
19
    }
20
21
    public function belongsToField(): bool
22
    {
23
        return $this->field !== null;
24
    }
25
26
    private function newEmptyValidationResult(): ValidationResult|ValidationResultByField
27
    {
28
        return $this->belongsToField() ? new ValidationResultByField($this->getField()) : new ValidationResult;
29
    }
30
}
31