Total Complexity | 8 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class SimpleFilterChain |
||
14 | { |
||
15 | private $filters; |
||
16 | |||
17 | 27 | public function __construct(array $filters = []) |
|
18 | { |
||
19 | 27 | $this->setFilters($filters); |
|
20 | } |
||
21 | |||
22 | 13 | public function appendFilter(callable $filter): self |
|
23 | { |
||
24 | 13 | $this->filters[] = $filter; |
|
25 | 13 | return $this; |
|
26 | } |
||
27 | |||
28 | 27 | private function setFilters(array $filters): self |
|
29 | { |
||
30 | 27 | $this->filters = []; |
|
31 | |||
32 | 27 | foreach ($filters as $filter) { |
|
33 | 12 | $this->appendFilter($filter); |
|
34 | } |
||
35 | |||
36 | 21 | return $this; |
|
37 | } |
||
38 | |||
39 | 14 | public function getFilters(): array |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Invokes each filter in turn; the specified 'request' will be passed to each filter. |
||
46 | * |
||
47 | * Iteration will stop if a filter returns the value of `$valueToBreak`. If iteration is forcibly stopped then the |
||
48 | * method will return the value of `$valueToBreak`. If, however, iteration is allowed to continue until completion |
||
49 | * then the method will return `null`. |
||
50 | * |
||
51 | * @param mixed $request |
||
52 | * @param mixed $valueToBreak |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 4 | public function execute(&$request, $valueToBreak = false) |
|
66 | } |
||
67 | } |
||
68 |