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

PreValidateTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A preValidate() 0 14 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