Passed
Pull Request — master (#65)
by Alexander
03:12
created

Required   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 15
ccs 5
cts 5
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Yiisoft\Validator\HasValidationMessage;
8
use Yiisoft\Validator\Rule;
9
use Yiisoft\Validator\Result;
10
use Yiisoft\Validator\DataSetInterface;
11
12
/**
13
 * RequiredValidator validates that the specified attribute does not have null or empty value.
14
 */
15
class Required extends Rule
16
{
17
    use HasValidationMessage;
18
19
    private string $message = 'Value cannot be blank.';
20
21 3
    protected function validateValue($value, DataSetInterface $dataSet = null): Result
22
    {
23 3
        $result = new Result();
24
25 3
        if ($this->isEmpty(is_string($value) ? trim($value) : $value)) {
26 1
            $result->addError($this->translateMessage($this->message));
27
        }
28
29 3
        return $result;
30
    }
31
}
32