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

Method   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 6 1
A jsonSerialize() 0 8 1
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
use JsonSerializable;
7
use Stringable;
8
9
use function array_map;
10
use function implode;
11
12
class Method implements JsonSerializable, Stringable
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Method
Loading history...
13
{
14
    /**
15
     * The name of the javascript function
16
     *
17
     * @var string
18
     */
19
    private $sName;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
20
21
    /**
22
     * @var array<ParameterInterface>
23
     */
24
    private $aParameters = [];
25
26
    /**
27
     * The constructor.
28
     *
29
     * @param string $sName     The method name
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter name; 5 found
Loading history...
30
     * @param array $aArguments The method arguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
31
     */
32
    public function __construct(string $sName, array $aArguments)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
33
    {
34
        $this->sName = $sName;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
35
        $this->aParameters = array_map(function($xArgument) {
36
            return Parameter::make($xArgument);
37
        }, $aArguments);
38
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
    /**
41
     * Convert this call to array, when converting the response into json.
42
     *
43
     * @return array
44
     */
45
    public function jsonSerialize(): array
46
    {
47
        return [
48
            '_type' => 'method',
49
            '_name' => $this->sName,
50
            'args' => array_map(function(JsonSerializable $xParam) {
51
                return $xParam->jsonSerialize();
52
            }, $this->aParameters),
53
        ];
54
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
55
56
    /**
57
     * Returns a string representation of this call
58
     *
59
     * @return string
60
     */
61
    public function __toString(): string
62
    {
63
        $aParameters = array_map(function(Stringable $xParam) {
64
            return $xParam->__toString();
65
        }, $this->aParameters);
66
        return '.' . $this->sName . '(' . implode(', ', $aParameters) . ')';
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
68
}
69