| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class ComposedReducer |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var array<callable> |
||
| 15 | */ |
||
| 16 | protected $reducers = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * ComposedReducer constructor. |
||
| 20 | * |
||
| 21 | * @param array<callable> $reducers |
||
| 22 | */ |
||
| 23 | 1 | public function __construct(array $reducers) |
|
| 27 | } |
||
| 28 | 1 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @param mixed $state |
||
| 32 | * @param ActionInterface $action |
||
| 33 | * @return mixed |
||
| 34 | */ |
||
| 35 | 1 | public function __invoke($state, ActionInterface $action) |
|
| 36 | { |
||
| 37 | 1 | foreach ($this->getReducers() as $reducer) { |
|
| 38 | 1 | $state = $reducer($state, $action); |
|
| 39 | } |
||
| 40 | 1 | return $state; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param callable $reducer |
||
| 45 | */ |
||
| 46 | 1 | protected function addReducer(callable $reducer): void |
|
| 47 | { |
||
| 48 | 1 | $this->reducers[] = $reducer; |
|
| 49 | 1 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @return array<callable> |
||
| 53 | */ |
||
| 54 | 1 | protected function getReducers(): array |
|
| 57 | } |
||
| 58 | } |