Passed
Push — master ( 888408...eb1365 )
by Thierry
02:11
created

DataBag::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
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\Plugin\DataBag;
4
5
use function is_array;
6
use function array_map;
7
8
class DataBag
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DataBag
Loading history...
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $aData = [];
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
14
15
    /**
16
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
17
     */
18
    protected $bTouched = false;
19
20
    /**
21
     * The constructor
22
     *
23
     * @param array $aData
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
24
     */
25
    public function __construct(array $aData)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
26
    {
27
        // Ensure all contents are arrays.
28
        $this->aData = array_map(function($aValue) {
29
            return is_array($aValue) ? $aValue : [];
30
        }, $aData);
31
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
    /**
34
     * @return bool
35
     */
36
    public function touched(): bool
37
    {
38
        return $this->bTouched;
39
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
40
41
    /**
42
     * @return array
43
     */
44
    public function getAll(): array
45
    {
46
        return $this->aData;
47
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
    /**
50
     * @param string $sBag
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
51
     * @param string $sKey
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param mixed $xValue
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
53
     *
54
     * @return void
55
     */
56
    public function set(string $sBag, string $sKey, $xValue)
57
    {
58
        $this->bTouched = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
59
        $this->aData[$sBag][$sKey] = $xValue;
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
61
62
    /**
63
     * @param string $sBag
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
64
     * @param string $sKey
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
65
     * @param mixed $xValue
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
66
     *
67
     * @return mixed
68
     */
69
    public function get(string $sBag, string $sKey, $xValue = null)
70
    {
71
        return $this->aData[$sBag][$sKey] ?? $xValue;
72
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
73
}
74