Passed
Push — master ( d1e56b...d668ed )
by Smoren
02:53
created

WrappedCheck   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 6 2
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Checks;
6
7
use Smoren\Validator\Exceptions\CheckError;
8
use Smoren\Validator\Interfaces\CheckInterface;
9
10
class WrappedCheck implements CheckInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected string $name;
16
    /**
17
     * @var CheckInterface
18
     */
19
    protected CheckInterface $check;
20
    /**
21
     * @var callable
22
     */
23
    protected $errorHandler;
24
25
    /**
26
     * @param string $name
27
     * @param CheckInterface $check
28
     * @param callable $errorHandler
29
     */
30 2
    public function __construct(string $name, CheckInterface $check, callable $errorHandler)
31
    {
32 2
        $this->name = $name;
33 2
        $this->check = $check;
34 2
        $this->errorHandler = $errorHandler;
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 2
    public function execute($value, array $previousErrors, bool $preventDuplicate = false): void
41
    {
42
        try {
43 2
            $this->check->execute($value, $previousErrors, $preventDuplicate);
44 1
        } catch (CheckError $e) {
45 1
            throw ($this->errorHandler)($e, $this->name);
46
        }
47
    }
48
}
49