Total Complexity | 4 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Coverage | 30% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Check implements CheckInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected string $name; |
||
14 | /** |
||
15 | * @var callable |
||
16 | */ |
||
17 | protected $predicate; |
||
18 | /** |
||
19 | * @var array<string, mixed> |
||
20 | */ |
||
21 | protected array $params; |
||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected bool $blocking; |
||
26 | |||
27 | /** |
||
28 | * @param string $name |
||
29 | * @param callable $predicate |
||
30 | * @param array<string, mixed> $params |
||
31 | * @param bool $isBlocking |
||
32 | */ |
||
33 | public function __construct(string $name, callable $predicate, array $params = [], bool $isBlocking = false) |
||
34 | { |
||
35 | $this->name = $name; |
||
36 | $this->predicate = $predicate; |
||
37 | $this->params = $params; |
||
38 | $this->blocking = $isBlocking; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritDoc} |
||
43 | */ |
||
44 | 22 | public function execute($value): void |
|
45 | { |
||
46 | 22 | if (($this->predicate)($value, ...array_values($this->params)) === false) { |
|
47 | 13 | throw new CheckError($this->name, $value, $this->params); |
|
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function isBlocking(): bool |
||
57 | } |
||
58 | } |
||
59 |