ConstraintCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A put() 0 3 1
A add() 0 7 2
A all() 0 3 1
A create() 0 3 1
1
<?php
2
/**
3
 * Created by enea dhack - 09/01/2020 20:00.
4
 */
5
6
namespace Vaened\Searcher;
7
8
use Closure;
9
use InvalidArgumentException;
10
11
final class ConstraintCollection
12
{
13
    private array $constraints = [];
14
15
    public static function create(): self
16
    {
17
        return new static();
18
    }
19
20
    public function put(string $key, Closure $constraint): void
21
    {
22
        $this->add($key, $constraint);
23
    }
24
25
    private function add(string $key, Closure $constraint): void
26
    {
27
        if (isset($this->constraints[$key])) {
28
            throw new InvalidArgumentException("The [{$key}] key was already defined in the collection");
29
        }
30
31
        $this->constraints[$key] = $constraint;
32
    }
33
34
    public function all(): array
35
    {
36
        return $this->constraints;
37
    }
38
}
39