Passed
Branch main (c6b4b7)
by Breno
02:14
created

Rule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 14
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 Attribute;
7
use Closure;
8
9
#[Attribute(Attribute::TARGET_PROPERTY)]
10
class Rule extends AbstractValidation
11
{
12
    private Closure $rule;
13
14
    public function __construct(callable $rule, ?string $message = 'Invalid input')
15
    {
16
        $this->rule = Closure::fromCallable($rule);
17
        parent::__construct($message);
18
    }
19
20
    protected function isValid($input, array $context = []): bool
21
    {
22
        return ($this->rule)($input, $context);
23
    }
24
}
25