Passed
Push — master ( b34d93...aea763 )
by Thierry
03:02 queued 24s
created

CallableFunction   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 28
c 0
b 0
f 0
dl 0
loc 127
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 13 4
A getJsName() 0 3 1
A __construct() 0 5 1
A getName() 0 3 1
A getOptions() 0 3 1
A configure() 0 13 3
1
<?php
2
3
/**
4
 * CallableFunction.php - Jaxon user function
5
 *
6
 * This class stores a reference to a user defined function which can be called from the client via an Jaxon request
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Jared White
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
10
 * @author J. Max Wilson
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
11
 * @author Joseph Woolley
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
12
 * @author Steffen Konerow
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
13
 * @author Thierry Feuzeu <[email protected]>
14
 * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
15
 * @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
16
 * @copyright 2016 Thierry Feuzeu <[email protected]>
17
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
18
 * @link https://github.com/jaxon-php/jaxon-core
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
20
21
namespace Jaxon\Plugin\Request\CallableFunction;
22
23
class CallableFunction
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CallableFunction
Loading history...
24
{
25
    /**
26
     * The name of the function in the ajax call
27
     *
28
     * @var string
29
     */
30
    private $sFunction;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
31
32
    /**
33
     * The name of the generated javascript function
34
     *
35
     * @var string
36
     */
37
    private $sJsFunction;
38
39
    /**
40
     * A string or an array which defines the registered PHP function
41
     *
42
     * @var string|array
43
     */
44
    private $xPhpFunction;
45
46
    /**
47
     * The path and file name of the include file where the function is defined
48
     *
49
     * @var string
50
     */
51
    private $sInclude;
52
53
    /**
54
     * An associative array containing call options that will be sent
55
     * to the browser curing client script generation
56
     *
57
     * @var array
58
     */
59
    private $aOptions = [];
60
61
    /**
62
     * The constructor
63
     *
64
     * @param string $sFunction
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
65
     * @param string $sJsFunction
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
66
     * @param string $sPhpFunction
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
67
     */
68
    public function __construct(string $sFunction, string $sJsFunction, string $sPhpFunction)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
69
    {
70
        $this->sFunction = $sFunction;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71
        $this->sJsFunction = $sJsFunction;
72
        $this->xPhpFunction = $sPhpFunction;
73
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
74
75
    /**
76
     * Get the name of the function being referenced
77
     *
78
     * @return string
79
     */
80
    public function getName(): string
81
    {
82
        return $this->sFunction;
83
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
84
85
    /**
86
     * Get name of the corresponding javascript function
87
     *
88
     * @return string
89
     */
90
    public function getJsName(): string
91
    {
92
        return $this->sJsFunction;
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
94
95
    /**
96
     * Get the config options of the function being referenced
97
     *
98
     * @return array
99
     */
100
    public function getOptions(): array
101
    {
102
        return $this->aOptions;
103
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
104
105
    /**
106
     * Set call options for this instance
107
     *
108
     * @param string $sName    The name of the configuration option
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
109
     * @param string $sValue    The value of the configuration option
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
110
     *
111
     * @return void
112
     */
113
    public function configure(string $sName, string $sValue)
114
    {
115
        switch($sName)
116
        {
117
        case 'class': // The user function is a method in the given class
118
            $this->xPhpFunction = [$sValue, $this->xPhpFunction];
119
            break;
120
        case 'include':
121
            $this->sInclude = $sValue;
122
            break;
123
        default:
124
            $this->aOptions[$sName] = $sValue;
125
            break;
126
        }
127
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
128
129
    /**
130
     * Call the registered user function, including an external file if needed
131
     * and passing along the specified arguments
132
     *
133
     * @param array $aArgs    The function arguments
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
134
     *
135
     * @return mixed
136
     */
137
    public function call(array $aArgs = [])
138
    {
139
        if(($this->sInclude))
140
        {
141
            require_once $this->sInclude;
142
        }
143
        // If the function is an alias for a class method, then instantiate the class
144
        if(is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0]))
145
        {
146
            $sClassName = $this->xPhpFunction[0];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
147
            $this->xPhpFunction[0] = new $sClassName;
148
        }
149
        return call_user_func_array($this->xPhpFunction, $aArgs);
150
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
151
}
152