ActionsBag::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace Hivokas\LaravelHandlers\Support;
4
5
use Illuminate\Support\Collection;
6
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
31
    {
32 10
        if (! $this->actions->contains($action)) {
33 10
            $this->actions->push($action);
34
        }
35
36 10
        return $this;
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
60
    {
61 7
        return $this->actions->toArray();
62
    }
63
64
    /**
65
     * Determines if bag is empty.
66
     *
67
     * @return bool
68
     */
69 14
    public function isEmpty(): bool
70
    {
71 14
        return $this->actions->isEmpty();
72
    }
73
}
74