Passed
Push — master ( 17adcb...9acb8c )
by Smoren
12:18
created

BaseRule::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Exceptions\ValidationError;
8
use Smoren\Validator\Interfaces\BaseRuleInterface;
9
use Smoren\Validator\Interfaces\ExecutionResultInterface;
10
use Smoren\Validator\Structs\ExecutionResult;
11
12
abstract class BaseRule implements BaseRuleInterface
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17 61
    public function validate($value): void
18
    {
19 61
        $this->execute($value);
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function isValid($value): bool
26
    {
27
        try {
28
            $this->validate($value);
29
            return true;
30
        } catch (ValidationError $e) {
31
            return false;
32
        }
33
    }
34
35
    /**
36
     * @param mixed $value
37
     *
38
     * @return ExecutionResultInterface
39
     */
40 61
    protected function execute($value): ExecutionResultInterface
41
    {
42 61
        return new ExecutionResult(false);
43
    }
44
}
45