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

CallableFunction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\Request\Plugin\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 corresponding javascript function
27
     *
28
     * @var string
29
     */
30
    private $sJsFunction;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
31
32
    /**
33
     * A string or an array which defines the function to be registered
34
     *
35
     * @var string|array
36
     */
37
    private $xCallableFunction;
38
39
    /**
40
     * The path and file name of the include file where the function is defined
41
     *
42
     * @var string
43
     */
44
    private $sInclude;
45
46
    /**
47
     * An associative array containing call options that will be sent
48
     * to the browser curing client script generation
49
     *
50
     * @var array
51
     */
52
    private $aConfiguration;
53
54
    public function __construct(string $sCallableFunction)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
55
    {
56
        $this->aConfiguration = [];
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...
57
        $this->sJsFunction = $sCallableFunction;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
58
        $this->xCallableFunction = $sCallableFunction;
59
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
60
61
    /**
62
     * Get the name of the function being referenced
63
     *
64
     * @return string
65
     */
66
    public function getName(): string
67
    {
68
        return $this->sJsFunction;
69
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
70
71
    /**
72
     * Get the config options of the function being referenced
73
     *
74
     * @return array
75
     */
76
    public function getConfigOptions(): array
77
    {
78
        return $this->aConfiguration;
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
    /**
82
     * Set call options for this instance
83
     *
84
     * @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...
85
     * @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...
86
     *
87
     * @return void
88
     */
89
    public function configure(string $sName, string $sValue)
90
    {
91
        switch($sName)
92
        {
93
        case 'class': // The user function is a method in the given class
94
            $this->xCallableFunction = [$sValue, $this->xCallableFunction];
95
            break;
96
        case 'alias':
97
            $this->sJsFunction = $sValue;
98
            break;
99
        case 'include':
100
            $this->sInclude = $sValue;
101
            break;
102
        default:
103
            $this->aConfiguration[$sName] = $sValue;
104
            break;
105
        }
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Call the registered user function, including an external file if needed
110
     * and passing along the specified arguments
111
     *
112
     * @param array $aArgs    The function arguments
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
113
     *
114
     * @return void
115
     */
116
    public function call(array $aArgs = [])
117
    {
118
        if(($this->sInclude))
119
        {
120
            require_once $this->sInclude;
121
        }
122
123
        // If the function is an alias for a class method, then instanciate the class
124
        if(is_array($this->xCallableFunction) && is_string($this->xCallableFunction[0]))
125
        {
126
            $sClassName = $this->xCallableFunction[0];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 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...
127
            $this->xCallableFunction[0] = new $sClassName;
128
        }
129
130
        return call_user_func_array($this->xCallableFunction, $aArgs);
131
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
132
}
133