Passed
Push — v5.x ( 8eee51...080647 )
by Thierry
10:22
created

JQueryPlugin::getReadyScript()   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
c 0
b 0
f 0
dl 0
loc 3
rs 10
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\Plugin\Response\JQuery;
4
5
use Jaxon\Plugin\ResponsePlugin;
6
7
class JQueryPlugin extends ResponsePlugin
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JQueryPlugin
Loading history...
8
{
9
    /**
10
     * @const The plugin name
11
     */
12
    const NAME = 'jquery';
13
14
    /**
15
     * @var string
16
     */
17
    protected $jQueryNs;
18
19
    /**
20
     * True if the next selector is a command
21
     *
22
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
23
     */
24
    protected $bCommand = true;
25
26
    /**
27
     * The class constructor
28
     *
29
     * @param string $jQueryNs
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
30
     */
31
    public function __construct(string $jQueryNs)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
32
    {
33
        $this->jQueryNs = $jQueryNs;
34
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
35
36
    /**
37
     * @param bool $bCommand
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
38
     *
39
     * @return JQueryPlugin
40
     */
41
    public function command(bool $bCommand): JQueryPlugin
42
    {
43
        $this->bCommand = $bCommand;
44
        return $this;
45
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
46
47
    /**
48
     * @inheritDoc
49
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
50
    public function getName(): string
51
    {
52
        return self::NAME;
53
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
54
55
    /**
56
     * @inheritDoc
57
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
58
    public function getHash(): string
59
    {
60
        // Use the version number as hash
61
        return '4.0.0';
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * Create a JQueryPlugin DomSelector, and link it to the current response.
66
     *
67
     * Since this element is linked to a response, its code will be automatically sent to the client.
68
     * The returned object can be used to call jQuery functions on the selected elements.
69
     *
70
     * @param string $sPath    The jQuery selector path
71
     * @param mixed $xContext    A context associated to the selector
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...
72
     *
73
     * @return DomSelector
74
     */
75
    public function selector(string $sPath = '', $xContext = null): DomSelector
76
    {
77
        $xSelector = new DomSelector($sPath, $xContext);
78
        if($this->bCommand && $this->response() !== null)
79
        {
80
            $this->addCommand('jquery', ['selector' => $xSelector]);
81
        }
82
        // Reset the command value.
83
        $this->bCommand = true;
84
        return $xSelector;
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
86
}
87