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

CommonFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A notRequired() 0 3 1
A allowsEmpty() 0 3 1
A check() 0 3 1
A notEmptyString() 0 3 1
A allowsNull() 0 3 1
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