BlocklistProcessor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 67
ccs 17
cts 17
cp 1
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A passed() 0 13 4
A getCheckers() 0 3 1
A addChecker() 0 5 1
A __construct() 0 3 1
A setCheckers() 0 5 1
1
<?php
2
3
namespace BlockListCheck;
4
5
use BlockListCheck\Contracts\BlocklistChecker;
6
use InvalidArgumentException;
7
8
class BlocklistProcessor
9
{
10
11
    /**
12
     * @var BlocklistChecker[]|array
13
     */
14
    protected array $checkers = [];
15
16
    /**
17
     * BlocklistChecker constructor.
18
     * @param array $checkers
19
     */
20 3
    public function __construct(array $checkers = [])
21
    {
22 3
        $this->checkers = $checkers;
23
    }
24
25
    /**
26
     * @return array
27
     */
28 1
    public function getCheckers(): array
29
    {
30 1
        return $this->checkers;
31
    }
32
33
    /**
34
     * @param array $checkers
35
     *
36
     * @return static
37
     */
38 1
    public function setCheckers(array $checkers): static
39
    {
40 1
        $this->checkers = $checkers;
41
42 1
        return $this;
43
    }
44
45
    /**
46
     * @param BlocklistChecker $checker
47
     * @return static
48
     */
49 1
    public function addChecker(BlocklistChecker $checker): static
50
    {
51 1
        array_push($this->checkers, $checker);
52
53 1
        return $this;
54
    }
55
56
    /**
57
     * @param $entity
58
     *
59
     * @return bool
60
     * @throws InvalidArgumentException
61
     */
62 2
    public function passed($entity): bool
63
    {
64 2
        foreach ($this->checkers as $checker) {
65 2
            if (!($checker instanceof BlocklistChecker)) {
66 1
                throw new InvalidArgumentException('$checker should implement BlocklistChecker');
67
            }
68
69 1
            if (!$checker->check($entity)) {
70 1
                return false;
71
            }
72
        }
73
74 1
        return true;
75
    }
76
}
77