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

Event::__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\Call;
6
use JsonSerializable;
7
use Stringable;
8
9
class Event implements JsonSerializable, Stringable
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Event
Loading history...
10
{
11
    /**
12
     * @var string
13
     */
14
    private $sName;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
15
16
    /**
17
     * @var Call
18
     */
19
    private $xHandler;
20
21
    /**
22
     * The constructor.
23
     *
24
     * @param string $sName    The event name
25
     * @param Call $xHandler   The event handler
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 3 found
Loading history...
26
     */
27
    public function __construct(string $sName, Call $xHandler)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        $this->sName = $sName;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
30
        $this->xHandler = $xHandler;
31
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
    /**
34
     * Convert this call to array, when converting the response into json.
35
     *
36
     * @return array
37
     */
38
    public function jsonSerialize(): array
39
    {
40
        return [
41
            '_type' => 'event',
42
            '_name' => $this->sName,
43
            'func' => $this->xHandler->jsonSerialize(),
44
        ];
45
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
46
47
    /**
48
     * Returns a string representation of this call
49
     *
50
     * @return string
51
     */
52
    public function __toString(): string
53
    {
54
        return ".on('{$this->sName}', () => { " . $this->xHandler->__toString() . '; })';
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
56
}
57