Passed
Push — v5.x ( fe38d4...6ac3c7 )
by Thierry
10:27
created

js()   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 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon;
4
5
use Jaxon\App\Ajax;
6
use Jaxon\Exception\SetupException;
7
use Jaxon\Request\Factory\ParameterFactory;
8
use Jaxon\Request\Factory\JsCallFactory;
9
use Jaxon\Request\Js\Selector;
10
11
/**
12
 * start.php
13
 *
14
 * This file is automatically loaded by the Composer autoloader
15
 *
16
 * The Jaxon global functions are defined here, and the library is initialised.
17
 *
18
 * @package jaxon-core
19
 * @author Thierry Feuzeu <[email protected]>
20
 * @copyright 2016 Thierry Feuzeu <[email protected]>
21
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
22
 * @link https://github.com/jaxon-php/jaxon-core
23
 */
24
25
/**
26
 * Return the singleton instance of the Ajax class
27
 *
28
 * @return Ajax
29
 */
30
function jaxon(): Ajax
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
31
{
32
    return Ajax::getInstance();
33
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
34
35
/**
36
 * Factory for ajax calls to a registered PHP class or function.
37
 *
38
 * @param string $sClassName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
39
 *
40
 * @return JsCallFactory
41
 * @throws SetupException
42
 */
43
function rq(string $sClassName = ''): JsCallFactory
44
{
45
    return jaxon()->factory()->rq($sClassName);
46
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
47
48
/**
49
 * Get the factory for calls to a js object or function.
50
 *
51
 * @param string $sJsObject
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
 *
53
 * @return JsCallFactory
54
 */
55
function js(string $sJsObject = ''): JsCallFactory
56
{
57
    return jaxon()->factory()->js($sJsObject, false);
0 ignored issues
show
Unused Code introduced by
The call to Jaxon\Request\Factory\Factory::js() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
    return jaxon()->factory()->/** @scrutinizer ignore-call */ js($sJsObject, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
58
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
59
60
/**
61
 * Get the single instance of the parameter factory
62
 *
63
 * @return ParameterFactory
64
 */
65
function pm(): ParameterFactory
66
{
67
    return jaxon()->factory()->pm();
68
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
69
70
/**
71
 * Create a JQuery Selector with a given path
72
 *
73
 * The returned element is not linked to any Jaxon response, so this function shall be used
74
 * to insert jQuery's code into a javascript function, or as a parameter of a Jaxon function call.
75
 *
76
 * @param string $sPath    The jQuery selector path
77
 * @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...
78
 *
79
 * @return Selector
80
 */
81
function jq(string $sPath = '', $xContext = null): Selector
82
{
83
    return new Selector($sPath, $xContext);
84
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
85
86
// Register the Jaxon request and response plugins
87
jaxon()->di()->getPluginManager()->registerPlugins();
88