ConstraintCollection::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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