Passed
Pull Request — master (#222)
by Dmitriy
02:26
created

PreValidateTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 8
cp 0
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B preValidate() 0 20 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Closure;
8
use Yiisoft\Validator\Result;
9
use Yiisoft\Validator\ValidationContext;
10
use Yiisoft\Validator\Validator;
11
12
trait PreValidateTrait
13
{
14
    use EmptyCheckTrait;
15
16
    private function preValidate(
17
        $value,
18
        ValidationContext $context,
19
        bool $skipOnEmpty,
20
        bool $skipOnError,
21
        Closure $when,
22
    ) {
23
        if ($skipOnEmpty && $this->isEmpty($value)) {
24
            return new Result();
25
        }
26
27
        if ($skipOnError && $context->getParameter(Validator::PARAMETER_PREVIOUS_RULES_ERRORED) === true) {
28
            return new Result();
29
        }
30
31
        if (is_callable($when) && !($when)($value, $context)) {
32
            return new Result();
33
        }
34
35
        return null;
36
    }
37
}
38