Completed
Push — master ( 34bc1a...41d5a5 )
by Thierry
02:48 queued 02:48
created

JQueryPlugin::command()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Response\Plugin\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
     * @inheritDoc
66
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
67
    public function getReadyScript(): string
68
    {
69
        return '
70
    jaxon.command.handler.register("jquery", function(args) {
71
        jaxon.cmd.script.execute(args);
72
    });
73
';
74
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
75
76
    /**
77
     * Create a JQueryPlugin DomSelector, and link it to the current response.
78
     *
79
     * Since this element is linked to a response, its code will be automatically sent to the client.
80
     * The returned object can be used to call jQuery functions on the selected elements.
81
     *
82
     * @param string $sPath    The jQuery selector path
83
     * @param string $sContext    A context associated to the selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
84
     *
85
     * @return DomSelector
86
     */
87
    public function selector(string $sPath = '', string $sContext = ''): DomSelector
88
    {
89
        $xSelector = new DomSelector($this->jQueryNs, $sPath, $sContext);
90
        if($this->bCommand && $this->xResponse !== null)
91
        {
92
            $this->addCommand(['cmd' => 'jquery'], $xSelector);
93
        }
94
        // Reset the command value.
95
        $this->bCommand = true;
96
        return $xSelector;
97
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
98
}
99