CommandRecorderRepository::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LaravelZero\Framework\Providers\CommandRecorder;
4
5
use Illuminate\Support\Collection;
6
7
/**
8
 * @internal
9
 */
10
final class CommandRecorderRepository
11
{
12
    /**
13
     * Command called in silence mode.
14
     */
15
    public const MODE_SILENT = 'silent';
16
17
    /**
18
     * Command called in default mode.
19
     */
20
    public const MODE_DEFAULT = 'default';
21
22
    /**
23
     * Holds the called commands.
24
     *
25
     * @var \Illuminate\Support\Collection
26
     */
27
    private $storage;
28
29
    /**
30
     * CommandRecorderRepository constructor.
31
     *
32
     * @param \Illuminate\Support\Collection|null $storage
33
     */
34 21
    public function __construct(Collection $storage = null)
35
    {
36 21
        $this->storage = $storage ?? collect();
37 21
    }
38
39
    /**
40
     * Clears the current history of called commands.
41
     */
42
    public function clear(): void
43
    {
44
        $this->storage = collect();
45
    }
46
47
    /**
48
     * Create a new entry of a called command in the storage.
49
     *
50
     * @param string $command
51
     * @param array $arguments
52
     * @param string $mode
53
     */
54 21
    public function create(string $command, array $arguments = [], string $mode = self::MODE_DEFAULT): void
55
    {
56 21
        $this->storage[] = [
57 21
            'command' => $command,
58 21
            'arguments' => $arguments,
59 21
            'mode' => $mode,
60
        ];
61 21
    }
62
63
    /**
64
     * Determine if the given command exists with the given arguments.
65
     *
66
     * @param string $command
67
     * @param array $arguments
68
     */
69 2
    public function exists(string $command, array $arguments = []): bool
70
    {
71
        return $this->storage->contains(function ($value) use ($command, $arguments) {
72 2
            return $value['command'] === $command && $value['arguments'] === $arguments;
73 2
        });
74
    }
75
}
76