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

BaseRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 44.44%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 3 1
A isValid() 0 7 2
A execute() 0 3 1
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