Passed
Push — v5.x ( 6ac3c7...223ede )
by Thierry
02:17
created

Call::getArgs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

441
            $xParameter->/** @scrutinizer ignore-call */ 
442
                         setValue($nPageNumber);
Loading history...
442
        }
443
        return $this;
444
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
445
446
    /**
447
     * Convert this call to array
448
     *
449
     * @return array
450
     */
451
    public function toArray(): array
452
    {
453
        $aCalls = [[
454
            '_type' => 'func',
455
            '_name' => $this->sFunction,
456
            'args' => array_map(function(JsonSerializable $xParam) {
457
                return $xParam->jsonSerialize();
458
            }, $this->aParameters),
459
        ]];
0 ignored issues
show
Coding Style introduced by
Closing brace of array declaration must be on a new line
Loading history...
460
        if($this->bToInt)
461
        {
462
            $aCalls[] = [
463
                '_type' => 'method',
464
                '_name' => 'toInt',
465
                'args' => [],
466
            ];
467
        }
468
469
        $aCall = ['_type' => 'expr', 'calls' => $aCalls];
470
        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...
471
        {
472
            $aCall['question'] = $this->aConfirm;
473
        }
474
        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...
475
        {
476
            $aCall['condition'] = $this->aCondition;
477
        }
478
        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...
479
        {
480
            $aCall['message'] = $this->aMessage;
481
        }
482
483
        return $aCall;
484
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
485
486
    /**
487
     * Convert this call to array, when converting the response into json.
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 call to jaxon as a string
498
     *
499
     * @return string
500
     */
501
    public function __toString(): string
502
    {
503
        return 'jaxon.exec(' . json_encode($this->toArray()) . ')';
504
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
505
506
    /**
507
     * Returns the js code of the call
508
     *
509
     * @return string
510
     */
511
    public function raw(): string
512
    {
513
        $aParameters = array_map(function(Stringable $xParam) {
514
            return $xParam->__toString();
515
        }, $this->aParameters);
516
        $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...
517
        return $this->bToInt ? "parseInt($sScript)" : $sScript;
518
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
519
}
520