Passed
Push — main ( c6e7a1...7c50b2 )
by Breno
02:58
created

CommonFactory::allowsEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Factories;
5
6
use BrenoRoosevelt\Validation\Rules\AllowsEmpty;
7
use BrenoRoosevelt\Validation\Rules\AllowsNull;
8
use BrenoRoosevelt\Validation\Rules\Generic;
9
use BrenoRoosevelt\Validation\Rules\NotEmptyString;
10
use BrenoRoosevelt\Validation\Rules\NotRequired;
11
use BrenoRoosevelt\Validation\RuleSet;
12
use BrenoRoosevelt\Validation\Rule;
13
14
trait CommonFactory
15
{
16
    abstract public function add(Rule|RuleSet ...$rules): static;
17
18
    public function check(callable $rule, ?string $message = null): static
19
    {
20
        return $this->add(new Generic($rule, $message));
21
    }
22
23
    public function allowsNull(): static
24
    {
25
        return $this->add(new AllowsNull);
26
    }
27
28
    public function allowsEmpty(): static
29
    {
30
        return $this->add(new AllowsEmpty);
31
    }
32
33
    public function notRequired(): static
34
    {
35
        return $this->add(new NotRequired);
36
    }
37
38
    public function notEmptyString(?string $message = null): static
39
    {
40
        return $this->add(new NotEmptyString($message));
41
    }
42
}
43