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

PreValidateTrait::preValidate()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 20
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 7
c 1
b 0
f 0
nc 4
nop 5
dl 0
loc 20
ccs 0
cts 8
cp 0
crap 56
rs 8.8333
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