Test Failed
Pull Request — stable (#303)
by Sander
07:26
created

CommandRecorder::commandWasCalled()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
4
namespace LaravelZero\Framework\Providers\CommandRecorder;
5
6
7
use Illuminate\Support\Collection;
8
9
class CommandRecorder
10
{
11
    const MODE_SILENT = 'silent';
12
    const MODE_DEFAULT = 'default';
13
14
    /**
15
     * @var Collection
16
     */
17
    protected $commandsCalled;
18
19
    /**
20
     * CommandRecorder constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->commandsCalled = new Collection;
25
    }
26
27
    /**
28
     * Clears the records.
29
     */
30
    public function reset()
31
    {
32
        $this->commandsCalled = new Collection;
33
    }
34
35
    /**
36
     * @return Collection
37
     */
38
    public function getCommandsCalled()
39
    {
40
        return $this->commandsCalled;
41
    }
42
43
    /**
44
     * Record a command call.
45
     *
46
     * @param $command
47
     * @param array $parameters
48
     * @param string $mode
49
     */
50
    public function record($command, $parameters = [], $mode = self::MODE_DEFAULT)
51
    {
52
        $this->commandsCalled[] = [
53
            'command' => $command,
54
            'parameters' => $parameters,
55
            'mode' => $mode,
56
        ];
57
    }
58
59
    /**
60
     * Determine if the command was called with the provided parameters.
61
     *
62
     * @param $command
63
     * @param array $parameters
64
     * @return bool
65
     */
66
    public function commandWasCalled($command, $parameters = [])
67
    {
68
        return $this->commandsCalled->contains(function($value) use ($command, $parameters) {
69
            return $value['command'] === $command && $value['parameters'] === $parameters;
70
        });
71
    }
72
}