| Total Complexity | 6 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class ActionsBag |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Collection of actions. |
||
| 11 | * |
||
| 12 | * @var Collection |
||
| 13 | */ |
||
| 14 | protected $actions; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * ActionsBag constructor. |
||
| 18 | */ |
||
| 19 | 15 | public function __construct() |
|
| 20 | { |
||
| 21 | 15 | $this->actions = collect(); |
|
| 22 | 15 | } |
|
| 23 | |||
| 24 | /** |
||
| 25 | * Add action if not exists. |
||
| 26 | * |
||
| 27 | * @param string $action |
||
| 28 | * @return ActionsBag |
||
| 29 | */ |
||
| 30 | 6 | public function addIfNotExists(string $action): self |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Delete action if exists. |
||
| 41 | * |
||
| 42 | * @param string $action |
||
| 43 | * @return ActionsBag |
||
| 44 | */ |
||
| 45 | 3 | public function deleteIfExists(string $action): self |
|
| 46 | { |
||
| 47 | $this->actions = $this->actions->reject(function (string $existingAction) use ($action) { |
||
| 48 | 3 | return $existingAction === $action; |
|
| 49 | 3 | }); |
|
| 50 | |||
| 51 | 3 | return $this; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Get array with all actions. |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | 4 | public function get(): array |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Determines if bag is empty. |
||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | 12 | public function isEmpty(): bool |
|
| 74 |