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

Rule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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