CheckBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 23
dl 0
loc 93
ccs 25
cts 25
cp 1
rs 10
c 2
b 0
f 1
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A withCalculatedParams() 0 4 1
A build() 0 8 1
A withParams() 0 4 1
A create() 0 3 1
A withPredicate() 0 4 1
A __construct() 0 4 1
A withDependencies() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Factories;
6
7
use Smoren\Validator\Checks\Check;
8
use Smoren\Validator\Interfaces\CheckInterface;
9
10
class CheckBuilder
11
{
12
    /**
13
     * @var string
14
     */
15
    protected string $name;
16
    /**
17
     * @var callable
18
     */
19
    protected $predicate;
20
    /**
21
     * @var array<string, mixed>
22
     */
23
    protected array $params = [];
24
    /**
25
     * @var array<string, callable>
26
     */
27
    protected array $calculatedParams = [];
28
    /**
29
     * @var array<CheckInterface>
30
     */
31
    protected array $dependencies = [];
32
33
    /**
34
     * @param string $name
35
     * @return self
36
     */
37 298
    public static function create(string $name): self
38
    {
39 298
        return new self($name);
40
    }
41
42
    /**
43
     * @return CheckInterface
44
     */
45 298
    public function build(): CheckInterface
46
    {
47 298
        return new Check(
48 298
            $this->name,
49 298
            $this->predicate,
50 298
            $this->params,
51 298
            $this->calculatedParams,
52 298
            $this->dependencies
53 298
        );
54
    }
55
56
    /**
57
     * @param callable $predicate
58
     * @return $this
59
     */
60 298
    public function withPredicate(callable $predicate): self
61
    {
62 298
        $this->predicate = $predicate;
63 298
        return $this;
64
    }
65
66
    /**
67
     * @param array<string, mixed> $params
68
     * @return $this
69
     */
70 146
    public function withParams(array $params): self
71
    {
72 146
        $this->params = $params;
73 146
        return $this;
74
    }
75
76
    /**
77
     * @param array<string, callable> $calculatedParams
78
     * @return $this
79
     */
80 3
    public function withCalculatedParams(array $calculatedParams): self
81
    {
82 3
        $this->calculatedParams = $calculatedParams;
83 3
        return $this;
84
    }
85
86
    /**
87
     * @param array<CheckInterface> $dependencies
88
     * @return $this
89
     */
90 48
    public function withDependencies(array $dependencies): self
91
    {
92 48
        $this->dependencies = $dependencies;
93 48
        return $this;
94
    }
95
96
    /**
97
     * @param string $name
98
     */
99 298
    private function __construct(string $name)
100
    {
101 298
        $this->name = $name;
102 298
        $this->predicate = fn () => true;
103
    }
104
}
105