ActionsBag   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 65
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addIfNotExists() 0 7 2
A get() 0 3 1
A __construct() 0 3 1
A deleteIfExists() 0 7 1
A isEmpty() 0 3 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