| Total Complexity | 9 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class BoolExpression |
||
| 13 | { |
||
| 14 | |||
| 15 | /** @var AbstractOperator[] */ |
||
| 16 | private $operators = []; |
||
| 17 | |||
| 18 | public function __construct(callable $checker) |
||
| 19 | { |
||
| 20 | $this->operators[] = new AndOperator($checker); |
||
| 21 | } |
||
| 22 | |||
| 23 | public static function with(callable $checker): self |
||
| 24 | { |
||
| 25 | return new self($checker); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function __invoke($item): bool |
||
| 29 | { |
||
| 30 | $value = null; |
||
| 31 | foreach ($this->operators as $operator) { |
||
| 32 | if ($value === null) { |
||
| 33 | if (!$value = $operator->getChecker()($item)) { |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | if (!$value = $operator($value, $item)) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function and(callable $checker): self |
||
| 46 | { |
||
| 47 | $this->operators[] = new AndOperator($checker); |
||
| 48 | return $this; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function or(callable $checker): self |
||
| 55 | } |
||
| 56 | |||
| 57 | } |
||
| 58 |