Passed
Push — master ( 41d5a5...e82656 )
by Thierry
03:02
created

CommandTrait::getCommandCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Response\Traits;
4
5
use Jaxon\Response\ResponseInterface;
6
7
use function array_merge;
8
use function count;
9
10
trait CommandTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait CommandTrait
Loading history...
11
{
12
    /**
13
     * The commands that will be sent to the browser in the response
14
     *
15
     * @var array
16
     */
17
    protected $aCommands = [];
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
18
19
    /**
20
     * Get the commands in the response
21
     *
22
     * @return array
23
     */
24
    public function getCommands(): array
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
25
    {
26
        return $this->aCommands;
27
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
28
29
    /**
30
     * Get the number of commands in the response
31
     *
32
     * @return int
33
     */
34
    public function getCommandCount(): int
35
    {
36
        return count($this->aCommands);
37
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
    /**
40
     * Clear all the commands already added to the response
41
     *
42
     * @return void
43
     */
44
    public function clearCommands()
45
    {
46
        $this->aCommands = [];
47
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
    /**
50
     * Merge the commands with those in this <Response> object
51
     *
52
     * @param array $aCommands    The commands to merge
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
53
     * @param bool $bBefore    Add the new commands to the beginning of the list
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
54
     *
55
     * @return void
56
     */
57
    public function appendCommands(array $aCommands, bool $bBefore = false)
58
    {
59
        $this->aCommands = ($bBefore) ?
0 ignored issues
show
Coding Style introduced by
Expected 1 space after "?"; newline found
Loading history...
60
            array_merge($aCommands, $this->aCommands) :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
61
            array_merge($this->aCommands, $aCommands);
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * Merge the response commands with those in this <Response> object
66
     *
67
     * @param ResponseInterface $xResponse    The <Response> object
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
68
     * @param bool $bBefore    Add the new commands to the beginning of the list
0 ignored issues
show
Coding Style introduced by
Expected 14 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
69
     *
70
     * @return void
71
     */
72
    public function appendResponse(ResponseInterface $xResponse, bool $bBefore = false)
73
    {
74
        $this->appendCommands($xResponse->getCommands(), $bBefore);
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
76
}
77