Test Failed
Pull Request — master (#244)
by Dmitriy
02:50
created

PreValidateTrait::preValidate()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 9.2222
cc 6
nc 4
nop 3
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Trait;
6
7
use Yiisoft\Validator\BeforeValidationInterface;
8
use Yiisoft\Validator\ValidationContext;
9
10
trait PreValidateTrait
11
{
12
    use EmptyCheckTrait;
13
14
    private string $parameterPreviousRulesErrored = 'previousRulesErrored';
15
16 40
    private function preValidate(
17
        $value,
18
        ValidationContext $context,
19
        BeforeValidationInterface $rule
20
    ): bool {
21 40
        if ($rule->shouldSkipOnEmpty() && $this->isEmpty($value)) {
22 2
            return true;
23
        }
24
25 38
        if ($rule->shouldSkipOnError() && $context->getParameter($this->parameterPreviousRulesErrored) === true) {
26 1
            return true;
27
        }
28
29 37
        return is_callable($rule->getWhen()) && !($rule->getWhen())($value, $context);
30
    }
31
}
32