Passed
Push — main ( 352c83...c69694 )
by Breno
01:58
created

Generic   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

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