Passed
Push — v5.x ( 6ac3c7...223ede )
by Thierry
02:17
created

AttrSet::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Js\Selector;
4
5
use Jaxon\Js\Parameter;
6
7
use JsonSerializable;
8
use Stringable;
9
10
class AttrSet implements JsonSerializable, Stringable
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class AttrSet
Loading history...
11
{
12
    /**
13
     * The attribute name
14
     *
15
     * @var string
16
     */
17
    private $sAttrName;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
18
19
    /**
20
     * The attribute value
21
     *
22
     * @var Parameter
23
     */
24
    private $xAttrValue;
25
26
    /**
27
     * The constructor.
28
     *
29
     * @param string $sAttrName    The attribute name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
30
     * @param mixed $xAttrValue    The attribute value
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
31
     */
32
    public function __construct(string $sAttrName, $xAttrValue)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
33
    {
34
        $this->sAttrName = $sAttrName;
35
        $this->xAttrValue = Parameter::make($xAttrValue);
36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
37
38
    /**
39
     * Convert this call to array, when converting the response into json.
40
     *
41
     * @return array
42
     */
43
    public function jsonSerialize(): array
44
    {
45
        return [
46
            '_type' => 'attr',
47
            '_name' => $this->sAttrName,
48
            'value' => $this->xAttrValue->jsonSerialize(),
49
        ];
50
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
51
52
    /**
53
     * Returns a string representation of this call
54
     *
55
     * @return string
56
     */
57
    public function __toString(): string
58
    {
59
        return '.' . $this->sAttrName . ' = ' . $this->xAttrValue;
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
61
}
62