| Total Complexity | 7 |
| Total Lines | 93 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 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 |
|
| 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) |
|
| 103 | } |
||
| 104 | } |
||
| 105 |