CallableRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 13
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isValid() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Rules;
5
6
use Closure;
7
8
class CallableRule extends AbstractValidation
9
{
10
    private Closure $rule;
11
12
    public function __construct(callable $rule, string $message = 'Invalid input')
13
    {
14
        $this->rule = Closure::fromCallable($rule);
15
        parent::__construct($message);
16
    }
17
18
    protected function isValid($input, array $context = []): bool
19
    {
20
        return ($this->rule)($input, $context);
21
    }
22
}
23