Passed
Push — master ( 853516...f09da5 )
by Thierry
09:47 queued 07:04
created

start.php ➔ pm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
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
use Jaxon\Jaxon;
4
use Jaxon\Plugin\Plugin;
5
use Jaxon\Request\Factory\RequestFactory;
6
use Jaxon\Request\Factory\ParameterFactory;
7
use Jaxon\Response\Plugin\JQuery\Dom\Element as DomElement;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DomElement.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
9
/**
10
 * start.php -
11
 *
12
 * This file is automatically loaded by the Composer autoloader
13
 *
14
 * The Jaxon global functions are defined here, and the library is initialised.
15
 *
16
 * @package jaxon-core
17
 * @author Thierry Feuzeu <[email protected]>
18
 * @copyright 2016 Thierry Feuzeu <[email protected]>
19
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
20
 * @link https://github.com/jaxon-php/jaxon-core
21
 */
22
23
/**
24
 * Return the singleton instance of the Jaxon/Jaxon class
25
 *
26
 * @return Jaxon
27
 */
28
function jaxon()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
29
{
30
    return Jaxon::getInstance();
31
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
/**
34
 * Translate a text to the selected language
35
 *
36
 * @param string        $sText                  The text to translate
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter name; 18 found
Loading history...
37
 * @param array         $aPlaceHolders          The placeholders in the text
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 10 found
Loading history...
38
 * @param string|null   $sLanguage              The language to translate to
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 14 found
Loading history...
39
 *
40
 * @return string
41
 */
42
function jaxon_trans($sText, array $aPlaceHolders = [], $sLanguage = null)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
43
{
44
    return Jaxon::getInstance()->di()->getTranslator()->trans($sText, $aPlaceHolders, $sLanguage);
45
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
46
47
/**
48
 * Register a plugin
49
 *
50
 * @param Plugin         $xPlugin               An instance of a plugin
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 15 found
Loading history...
51
 * @param integer        $nPriority             The plugin priority, used to order the plugins
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 13 found
Loading history...
52
 *
53
 * @return void
54
 */
55
function jaxon_register_plugin(Plugin $xPlugin, $nPriority = 1000)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
56
{
57
    Jaxon::getInstance()->registerPlugin($xPlugin, $nPriority);
58
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
59
60
/**
0 ignored issues
show
Coding Style introduced by
Parameter $sClassName should have a doc-comment as per coding-style.
Loading history...
61
 * Get the single instance of the request factory, and set the class to call.
62
 *
63
 * @return RequestFactory
64
 */
65
function rq($sClassName = null)
66
{
67
    return Jaxon::getInstance()->di()->getRequestFactory()->setClassName($sClassName);
68
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
69
70
/**
71
 * Get the single instance of the parameter factory
72
 *
73
 * @return ParameterFactory
74
 */
75
function pm()
76
{
77
    return Jaxon::getInstance()->di()->getParameterFactory();
78
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
79
80
/**
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
81
 * Get the single instance of the parameter factory
82
 *
83
 * The pr function is already defined in CakePHP, so it was renamed to pm.
84
 * This function is therefore deprecated, and will be removed in a future version.
85
 *
86
 * @return ParameterFactory
87
 */
88
if(!function_exists('pr'))
89
{
90
    function pr()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function pr()
Loading history...
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
91
    {
92
        return Jaxon::getInstance()->di()->getParameterFactory();
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
94
}
95
/**
96
 * Create a JQuery Element with a given selector
97
 *
98
 * The returned element is not linked to any Jaxon response, so this function shall be used
99
 * to insert jQuery code into a javascript function, or as a parameter of a Jaxon function call.
100
 *
101
 * @param string        $sSelector            The jQuery selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
102
 * @param string        $sContext             A context associated to the selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
103
 *
104
 * @return DomElement
105
 */
106
function jq($sSelector = '', $sContext = '')
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
107
{
108
    return new DomElement($sSelector, $sContext);
109
}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
110
111
/**
112
 * Create a JQuery Element with a given selector
113
 *
114
 * The returned element is not linked to any Jaxon response, so this function shall be used
115
 * to insert jQuery code into a javascript function, or as a parameter of a Jaxon function call.
116
 *
117
 * @param string        $sSelector            The jQuery selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
118
 * @param string        $sContext             A context associated to the selector
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
119
 *
120
 * @return DomElement
121
 */
122
function jQuery($sSelector = '', $sContext = '')
123
{
124
    return jq($sSelector, $sContext);
125
}
126