Passed
Push — master ( e82656...5198fb )
by Thierry
03:06
created

CallbackManager::getErrorCallbacks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Callbacks.php - Jaxon request callbacks
5
 *
6
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2017 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
12
13
namespace Jaxon\Request\Handler;
14
15
use function count;
16
17
class CallbackManager
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CallbackManager
Loading history...
18
{
19
    /**
20
     * The callbacks to run after booting the library
21
     *
22
     * @var callable[]
23
     */
24
    protected $aBootCallbacks = [];
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
25
26
    /**
27
     * The callbacks to run before processing the request
28
     *
29
     * @var callable[]
30
     */
31
    protected $aBeforeCallbacks = [];
32
33
    /**
34
     * The callbacks to run afteer processing the request
35
     *
36
     * @var callable[]
37
     */
38
    protected $aAfterCallbacks = [];
39
40
    /**
41
     * The callbacks to run in case of invalid request
42
     *
43
     * @var callable[]
44
     */
45
    protected $aInvalidCallbacks = [];
46
47
    /**
48
     * The callbacks to run in case of error
49
     *
50
     * @var callable[]
51
     */
52
    protected $aErrorCallbacks = [];
53
54
    /**
55
     * The callbacks to run when a class is instanced
56
     *
57
     * @var callable[]
58
     */
59
    protected $aInitCallbacks = [];
60
61
    /**
62
     * Get the library booting callbacks, and reset the array.
63
     *
64
     * @return callable[]
65
     */
66
    public function popBootCallbacks(): array
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
67
    {
68
        if(empty($this->aBootCallbacks))
69
        {
70
            return [];
71
        }
72
        $aCallbacks = $this->aBootCallbacks;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
73
        $this->aBootCallbacks = [];
74
        return $aCallbacks;
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
76
77
    /**
78
     * Get the pre-request processing callbacks.
79
     *
80
     * @return callable[]
81
     */
82
    public function getBeforeCallbacks(): array
83
    {
84
        return $this->aBeforeCallbacks;
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
86
87
    /**
88
     * Get the post-request processing callbacks.
89
     *
90
     * @return callable[]
91
     */
92
    public function getAfterCallbacks(): array
93
    {
94
        return $this->aAfterCallbacks;
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
96
97
    /**
98
     * Get the invalid request callbacks.
99
     *
100
     * @return callable[]
101
     */
102
    public function getInvalidCallbacks(): array
103
    {
104
        return $this->aInvalidCallbacks;
105
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
106
107
    /**
108
     * Get the processing error callbacks.
109
     *
110
     * @return callable[]
111
     */
112
    public function getErrorCallbacks(): array
113
    {
114
        return $this->aErrorCallbacks;
115
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
116
117
    /**
118
     * Get the class initialisation callbacks.
119
     *
120
     * @return callable[]
121
     */
122
    public function getInitCallbacks(): array
123
    {
124
        return $this->aInitCallbacks;
125
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
126
127
    /**
128
     * Add a library booting callback.
129
     *
130
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
131
     *
132
     * @return CallbackManager
133
     */
134
    public function boot(callable $xCallable): CallbackManager
135
    {
136
        $this->aBootCallbacks[] = $xCallable;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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...
137
        $this->nBootCallbackAdded = true;
0 ignored issues
show
Bug Best Practice introduced by
The property nBootCallbackAdded does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
138
        return $this;
139
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
140
141
    /**
142
     * Add a pre-request processing callback.
143
     *
144
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
145
     *
146
     * @return CallbackManager
147
     */
148
    public function before(callable $xCallable): CallbackManager
149
    {
150
        $this->aBeforeCallbacks[] = $xCallable;
151
        return $this;
152
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
153
154
    /**
155
     * Add a post-request processing callback.
156
     *
157
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
158
     *
159
     * @return CallbackManager
160
     */
161
    public function after(callable $xCallable): CallbackManager
162
    {
163
        $this->aAfterCallbacks[] = $xCallable;
164
        return $this;
165
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
166
167
    /**
168
     * Add a invalid request callback.
169
     *
170
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
171
     *
172
     * @return CallbackManager
173
     */
174
    public function invalid(callable $xCallable): CallbackManager
175
    {
176
        $this->aInvalidCallbacks[] = $xCallable;
177
        return $this;
178
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
179
180
    /**
181
     * Add a processing error callback.
182
     *
183
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
184
     *
185
     * @return CallbackManager
186
     */
187
    public function error(callable $xCallable): CallbackManager
188
    {
189
        $this->aErrorCallbacks[] = $xCallable;
190
        return $this;
191
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
192
193
    /**
194
     * Add a class initialisation callback.
195
     *
196
     * @param callable $xCallable    The callback function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
197
     *
198
     * @return CallbackManager
199
     */
200
    public function init(callable $xCallable): CallbackManager
201
    {
202
        $this->aInitCallbacks[] = $xCallable;
203
        return $this;
204
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
205
}
206