Passed
Push — v5.x ( 6eb5e2...afe246 )
by Thierry
02:28
created

Call   A

Complexity

Total Complexity 39

Size/Duplication

Total Lines 477
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 39
eloc 86
dl 0
loc 477
rs 9.28
c 0
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A clearParameters() 0 4 1
A setDialogManager() 0 3 1
A ifgt() 0 4 1
A pushParameter() 0 4 1
A toInt() 0 4 1
A elseWarning() 0 4 1
A ifnte() 0 4 1
A iflt() 0 4 1
A elseError() 0 4 1
A elseInfo() 0 4 1
A __construct() 0 3 1
A elseShow() 0 4 1
A ifle() 0 4 1
A unless() 0 3 1
A ifge() 0 4 1
A elseSuccess() 0 4 1
A ifteq() 0 4 1
A when() 0 3 1
A addParameter() 0 4 1
A hasPageNumber() 0 3 1
A ifne() 0 4 1
A toArray() 0 33 5
A ifeq() 0 4 1
A __toString() 0 7 2
A findPageNumber() 0 10 3
A confirm() 0 4 1
A addParameters() 0 7 2
A setPageNumber() 0 9 2
A getArgs() 0 4 1
A jsonSerialize() 0 3 1
1
<?php
2
3
/**
4
 * Call.php - The Jaxon Call
5
 *
6
 * This class is used to create js ajax requests to callable classes and functions.
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\Js;
22
23
use Jaxon\App\Dialog\DialogManager;
24
use JsonSerializable;
25
use Stringable;
26
27
use function array_map;
28
use function array_shift;
29
use function func_get_args;
30
31
class Call
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Call
Loading history...
32
{
33
    /**
34
     * @var DialogManager
35
     */
36
    protected $xDialogManager;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
37
38
    /**
39
     * The name of the javascript function
40
     *
41
     * @var string
42
     */
43
    private $sFunction;
44
45
    /**
46
     * @var array<ParameterInterface>
47
     */
48
    protected $aParameters = [];
49
50
    /**
51
     * Convert the parameter value to integer
52
     *
53
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
54
     */
55
    protected $bToInt = false;
56
57
    /**
58
     * The arguments of the else() calls
59
     *
60
     * @var array
61
     */
62
    protected $aMessage = [];
63
64
    /**
65
     * A condition to check before making the call
66
     *
67
     * @var array
68
     */
69
    protected $aCondition = [];
70
71
    /**
72
     * The arguments of the confirm() call
73
     *
74
     * @var array
75
     */
76
    protected $aConfirm = [];
77
78
    /**
79
     * The constructor.
80
     *
81
     * @param string $sFunction    The javascript function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
82
     */
83
    public function __construct(string $sFunction)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
84
    {
85
        $this->sFunction = $sFunction;
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
87
88
    /**
89
     * @return Call
90
     */
91
    public function toInt(): Call
92
    {
93
        $this->bToInt = true;
94
        return $this;
95
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
96
97
    /**
98
     * Clear the parameter list associated with this request
99
     *
100
     * @return Call
101
     */
102
    public function clearParameters(): Call
103
    {
104
        $this->aParameters = [];
105
        return $this;
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Set the value of the parameter at the given position
110
     *
111
     * @param ParameterInterface $xParameter    The value to be used
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
112
     *
113
     * @return Call
114
     */
115
    public function pushParameter(ParameterInterface $xParameter): Call
116
    {
117
        $this->aParameters[] = $xParameter;
118
        return $this;
119
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
120
121
    /**
122
     * Add a parameter value to the parameter list for this request
123
     *
124
     * @param string $sType    The type of the value to be used
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
125
     * @param string $sValue    The value to be used
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
126
     *
127
     * Types should be one of the following <Parameter::FORM_VALUES>, <Parameter::QUOTED_VALUE>, <Parameter::NUMERIC_VALUE>,
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
128
     * <Parameter::JS_VALUE>, <Parameter::INPUT_VALUE>, <Parameter::CHECKED_VALUE>, <Parameter::PAGE_NUMBER>.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
129
     * The value should be as follows:
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
130
     * - <Parameter::FORM_VALUES> - Use the ID of the form you want to process.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
131
     * - <Parameter::QUOTED_VALUE> - The string data to be passed.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
132
     * - <Parameter::JS_VALUE> - A string containing valid javascript
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 1
Loading history...
133
     *   (either a javascript variable name that will be in scope at the time of the call or
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 3
Loading history...
134
     *   a javascript function call whose return value will become the parameter).
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 26 spaces but found 3
Loading history...
135
     *
136
     * @return Call
137
     */
138
    public function addParameter(string $sType, string $sValue): Call
139
    {
140
        $this->pushParameter(new Parameter($sType, $sValue));
141
        return $this;
142
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
143
144
    /**
145
     * Add a set of parameters to this request
146
     *
147
     * @param array $aParameters    The parameters
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
148
     *
149
     * @return Call
150
     */
151
    public function addParameters(array $aParameters): Call
152
    {
153
        foreach($aParameters as $xParameter)
154
        {
155
            $this->pushParameter(Parameter::make($xParameter));
156
        }
157
        return $this;
158
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
159
160
    /**
161
     * @param array $aArgs
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
162
     *
163
     * @return array
164
     */
165
    private function getArgs(array $aArgs): array
166
    {
167
        array_shift($aArgs);
168
        return $aArgs;
169
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
170
171
    /**
172
     * @param DialogManager $xDialogManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
173
     *
174
     * @return void
175
     */
176
    public function setDialogManager(DialogManager $xDialogManager)
177
    {
178
        $this->xDialogManager = $xDialogManager;
179
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
180
181
    /**
182
     * Show a message if the condition to the call is not met
183
     *
184
     * @param string $sMessage  The message to show
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
185
     *
186
     * @return Call
187
     */
188
    public function elseShow(string $sMessage): Call
189
    {
190
        $this->aMessage = $this->xDialogManager->warning($sMessage, $this->getArgs(func_get_args()));
191
        return $this;
192
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
193
194
    /**
195
     * Show an information message if the condition to the call is not met
196
     *
197
     * @param string $sMessage  The message to show
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
198
     *
199
     * @return Call
200
     */
201
    public function elseInfo(string $sMessage): Call
202
    {
203
        $this->aMessage = $this->xDialogManager->info($sMessage, $this->getArgs(func_get_args()));
204
        return $this;
205
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
206
207
    /**
208
     * Show a success message if the condition to the call is not met
209
     *
210
     * @param string $sMessage  The message to show
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
211
     *
212
     * @return Call
213
     */
214
    public function elseSuccess(string $sMessage): Call
215
    {
216
        $this->aMessage = $this->xDialogManager->success($sMessage, $this->getArgs(func_get_args()));
217
        return $this;
218
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
219
220
    /**
221
     * Show a warning message if the condition to the call is not met
222
     *
223
     * @param string $sMessage  The message to show
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
224
     *
225
     * @return Call
226
     */
227
    public function elseWarning(string $sMessage): Call
228
    {
229
        $this->aMessage = $this->xDialogManager->warning($sMessage, $this->getArgs(func_get_args()));
230
        return $this;
231
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
232
233
    /**
234
     * Show an error message if the condition to the call is not met
235
     *
236
     * @param string $sMessage  The message to show
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
237
     *
238
     * @return Call
239
     */
240
    public function elseError(string $sMessage): Call
241
    {
242
        $this->aMessage = $this->xDialogManager->error($sMessage, $this->getArgs(func_get_args()));
243
        return $this;
244
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
245
246
    /**
247
     * Add a confirmation question to the request
248
     *
249
     * @param string $sQuestion    The question to ask
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
250
     *
251
     * @return Call
252
     */
253
    public function confirm(string $sQuestion): Call
254
    {
255
        $this->aConfirm = $this->xDialogManager->confirm($sQuestion, $this->getArgs(func_get_args()));
256
        return $this;
257
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
258
259
    /**
260
     * Check if a value is equal to another before sending the request
261
     *
262
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
263
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
264
     *
265
     * @return Call
266
     */
267
    public function ifeq($xValue1, $xValue2): Call
268
    {
269
        $this->aCondition = ['eq', Parameter::make($xValue1), Parameter::make($xValue2)];
270
        return $this;
271
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
272
273
    /**
274
     * Check if a value is equal to another before sending the request
275
     *
276
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
277
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
278
     *
279
     * @return Call
280
     */
281
    public function ifteq($xValue1, $xValue2): Call
282
    {
283
        $this->aCondition = ['teq', Parameter::make($xValue1), Parameter::make($xValue2)];
284
        return $this;
285
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
286
287
    /**
288
     * Check if a value is not equal to another before sending the request
289
     *
290
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
291
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
292
     *
293
     * @return Call
294
     */
295
    public function ifne($xValue1, $xValue2): Call
296
    {
297
        $this->aCondition = ['ne', Parameter::make($xValue1), Parameter::make($xValue2)];
298
        return $this;
299
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
300
301
    /**
302
     * Check if a value is not equal to another before sending the request
303
     *
304
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
305
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
306
     *
307
     * @return Call
308
     */
309
    public function ifnte($xValue1, $xValue2): Call
310
    {
311
        $this->aCondition = ['nte', Parameter::make($xValue1), Parameter::make($xValue2)];
312
        return $this;
313
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
314
315
    /**
316
     * Check if a value is greater than another before sending the request
317
     *
318
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
319
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
320
     *
321
     * @return Call
322
     */
323
    public function ifgt($xValue1, $xValue2): Call
324
    {
325
        $this->aCondition = ['gt', Parameter::make($xValue1), Parameter::make($xValue2)];
326
        return $this;
327
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
328
329
    /**
330
     * Check if a value is greater or equal to another before sending the request
331
     *
332
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
333
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
334
     *
335
     * @return Call
336
     */
337
    public function ifge($xValue1, $xValue2): Call
338
    {
339
        $this->aCondition = ['ge', Parameter::make($xValue1), Parameter::make($xValue2)];
340
        return $this;
341
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
342
343
    /**
344
     * Check if a value is lower than another before sending the request
345
     *
346
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
347
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
348
     *
349
     * @return Call
350
     */
351
    public function iflt($xValue1, $xValue2): Call
352
    {
353
        $this->aCondition = ['lt', Parameter::make($xValue1), Parameter::make($xValue2)];
354
        return $this;
355
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
356
357
    /**
358
     * Check if a value is lower or equal to another before sending the request
359
     *
360
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
361
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
362
     *
363
     * @return Call
364
     */
365
    public function ifle($xValue1, $xValue2): Call
366
    {
367
        $this->aCondition = ['le', Parameter::make($xValue1), Parameter::make($xValue2)];
368
        return $this;
369
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
370
371
    /**
372
     * Add a condition to the request
373
     *
374
     * The request is sent only if the condition is true.
375
     *
376
     * @param mixed $xCondition    The condition to check
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
377
     *
378
     * @return Call
379
     */
380
    public function when($xCondition): Call
381
    {
382
        return $this->ifeq(true, $xCondition);
383
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
384
385
    /**
386
     * Add a condition to the request
387
     *
388
     * The request is sent only if the condition is false.
389
     *
390
     * @param mixed $xCondition    The condition to check
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
391
     *
392
     * @return Call
393
     */
394
    public function unless($xCondition): Call
395
    {
396
        return $this->ifeq(false, $xCondition);
397
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
398
399
    /**
400
     * Check if the request has a parameter of type Parameter::PAGE_NUMBER
401
     *
402
     * @return ParameterInterface|null
403
     */
404
    private function findPageNumber(): ?ParameterInterface
405
    {
406
        foreach($this->aParameters as $xParameter)
407
        {
408
            if($xParameter->getType() === Parameter::PAGE_NUMBER)
409
            {
410
                return $xParameter;
411
            }
412
        }
413
        return null;
414
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
415
416
    /**
417
     * Check if the request has a parameter of type Parameter::PAGE_NUMBER
418
     *
419
     * @return bool
420
     */
421
    public function hasPageNumber(): bool
422
    {
423
        return $this->findPageNumber() !== null;
424
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
425
426
    /**
427
     * Set a value to the Parameter::PAGE_NUMBER parameter
428
     *
429
     * @param integer $nPageNumber    The current page number
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
430
     *
431
     * @return Call
432
     */
433
    public function setPageNumber(int $nPageNumber): Call
434
    {
435
        /** @var Parameter */
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
436
        $xParameter = $this->findPageNumber();
437
        if($xParameter !== null)
438
        {
439
            $xParameter->setValue($nPageNumber);
0 ignored issues
show
Bug introduced by
The method setValue() does not exist on Jaxon\Request\Js\ParameterInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jaxon\Request\Js\ParameterInterface. ( Ignorable by Annotation )

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

439
            $xParameter->/** @scrutinizer ignore-call */ 
440
                         setValue($nPageNumber);
Loading history...
440
        }
441
        return $this;
442
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
443
444
    /**
445
     * Convert this call to array
446
     *
447
     * @return array
448
     */
449
    public function toArray(): array
450
    {
451
        $aCalls = [[
452
            '_type' => 'func',
453
            '_name' => $this->sFunction,
454
            'args' => array_map(function(JsonSerializable $xParam) {
455
                return $xParam->jsonSerialize();
456
            }, $this->aParameters),
457
        ]];
0 ignored issues
show
Coding Style introduced by
Closing brace of array declaration must be on a new line
Loading history...
458
        if($this->bToInt)
459
        {
460
            $aCalls[] = [
461
                '_type' => 'func',
462
                '_name' => 'toInt',
463
                'args' => [[ '_type' => '_', '_name' => 'this' ]],
464
            ];
465
        }
466
467
        $aCall = ['_type' => 'expr', 'calls' => $aCalls];
468
        if(($this->aConfirm))
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->aConfirm of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
469
        {
470
            $aCall['question'] = $this->aConfirm;
471
        }
472
        if(($this->aCondition))
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->aCondition of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
473
        {
474
            $aCall['condition'] = $this->aCondition;
475
        }
476
        if(($this->aMessage))
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->aMessage of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
477
        {
478
            $aCall['message'] = $this->aMessage;
479
        }
480
481
        return $aCall;
482
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
483
484
    /**
485
     * Convert this call to array, when converting the response into json.
486
     *
487
     * This is a method of the JsonSerializable interface.
488
     *
489
     * @return array
490
     */
491
    public function jsonSerialize(): array
492
    {
493
        return $this->toArray();
494
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
495
496
    /**
497
     * Returns a string representation of the script output (javascript) from this request object
498
     *
499
     * @return string
500
     */
501
    public function __toString()
502
    {
503
        $aParameters = array_map(function(Stringable $xParam) {
504
            return $xParam->__toString();
505
        }, $this->aParameters);
506
        $sScript = $this->sFunction . '(' . implode(', ', $aParameters) . ')';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
507
        return $this->bToInt ? "parseInt($sScript)" : $sScript;
508
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
509
}
510