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 | 20 | public function __construct() |
|
20 | { |
||
21 | 20 | $this->actions = collect(); |
|
22 | 20 | } |
|
23 | |||
24 | /** |
||
25 | * Add action if not exists. |
||
26 | * |
||
27 | * @param string $action |
||
28 | * @return ActionsBag |
||
29 | */ |
||
30 | 10 | public function addIfNotExists(string $action): self |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Delete action if exists. |
||
41 | * |
||
42 | * @param string $action |
||
43 | * @return ActionsBag |
||
44 | */ |
||
45 | 4 | public function deleteIfExists(string $action): self |
|
46 | { |
||
47 | $this->actions = $this->actions->reject(function (string $existingAction) use ($action) { |
||
48 | 4 | return $existingAction === $action; |
|
49 | 4 | }); |
|
50 | |||
51 | 4 | return $this; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get array with all actions. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | 7 | public function get(): array |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Determines if bag is empty. |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | 14 | public function isEmpty(): bool |
|
74 |