Passed
Push — master ( 8eafb5...9551a9 )
by Thierry
02:09
created

JQueryPlugin::element()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
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\Response\Plugin\JQuery\Dom\Element;
6
use Jaxon\Utils\Config\Config;
7
8
class JQueryPlugin extends \Jaxon\Plugin\Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JQueryPlugin
Loading history...
9
{
10
    /**
11
     * @var Config
12
     */
13
    protected $xConfig;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
14
15
    /**
16
     * The class constructor
17
     *
18
     * @param Config $xConfig
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
19
     */
20
    public function __construct(Config $xConfig)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
21
    {
22
        $this->xConfig = $xConfig;
23
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
24
25
    /**
26
     * @inheritDoc
27
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
28
    public function getName(): string
29
    {
30
        return 'jquery';
31
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
    /**
34
     * @inheritDoc
35
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
36
    public function getHash(): string
37
    {
38
        // Use the version number as hash
39
        return '3.3.0';
40
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
41
42
    /**
43
     * @inheritDoc
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
45
    public function getReadyScript(): string
46
    {
47
        return '
48
    jaxon.command.handler.register("jquery", function(args) {
49
        jaxon.cmd.script.execute(args);
50
    });
51
';
52
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
53
54
    /**
55
     * Create a JQueryPlugin Element with a given selector, and link it to the current response.
56
     *
57
     * Since this element is linked to a response, its code will be automatically sent to the client.
58
     * The returned object can be used to call jQuery functions on the selected elements.
59
     *
60
     * @param string $sSelector    The jQuery selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
61
     * @param string $sContext    A context associated to the selector
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
62
     *
63
     * @return Element
64
     */
65
    public function element(string $sSelector = '', string $sContext = ''): Element
66
    {
67
        $jQueryNs = $this->xConfig->getOption('core.jquery.no_conflict', false) ? 'jQuery' : '$';
68
        $xElement = new Element($jQueryNs, $sSelector, $sContext);
69
        $this->addCommand(['cmd' => 'jquery'], $xElement);
70
        return $xElement;
71
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
72
}
73