Completed
Push — master ( e6fe6f...a29d2d )
by Hannes
09:33
created

Grammar::parseL_REQ_AMENDMENT()   F

Complexity

Conditions 14
Paths 465

Size

Total Lines 102
Code Lines 60

Duplication

Lines 102
Ratio 100 %

Importance

Changes 0
Metric Value
dl 102
loc 102
rs 3.3791
c 0
b 0
f 0
cc 14
eloc 60
nc 465
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace byrokrat\autogiro;
4
5
use byrokrat\autogiro\Tree\FileNode;
6
use byrokrat\autogiro\Tree\LayoutNode;
7
use byrokrat\autogiro\Tree\OpeningNode;
8
use byrokrat\autogiro\Tree\ClosingNode;
9
use byrokrat\autogiro\Tree\RequestMandateCreationNode;
10
use byrokrat\autogiro\Tree\RequestMandateAcceptanceNode;
11
use byrokrat\autogiro\Tree\RequestMandateRejectionNode;
12
use byrokrat\autogiro\Tree\RequestMandateUpdateNode;
13
use byrokrat\autogiro\Tree\RequestMandateDeletionNode;
14
use byrokrat\autogiro\Tree\RequestIncomingTransactionNode;
15
use byrokrat\autogiro\Tree\RequestOutgoingTransactionNode;
16
use byrokrat\autogiro\Tree\RequestTransactionDeletionNode;
17
use byrokrat\autogiro\Tree\RequestTransactionUpdateNode;
18
use byrokrat\autogiro\Tree\MandateResponseNode;
19
use byrokrat\autogiro\Tree\PersonalIdNode;
20
use byrokrat\autogiro\Tree\OrganizationIdNode;
21
use byrokrat\autogiro\Tree\AmountNode;
22
use byrokrat\autogiro\Tree\AccountNode;
23
use byrokrat\autogiro\Tree\BankgiroNode;
24
use byrokrat\autogiro\Tree\MessageNode;
25
use byrokrat\autogiro\Tree\PayerNumberNode;
26
27
class Grammar
28
{
29
    protected $string;
30
    protected $position;
31
    protected $value;
32
    protected $cache;
33
    protected $cut;
34
    protected $errors;
35
    protected $warnings;
36
37
    protected function parseFILE()
38
    {
39
        $_position = $this->position;
40
41
        if (isset($this->cache['FILE'][$_position])) {
42
            $_success = $this->cache['FILE'][$_position]['success'];
43
            $this->position = $this->cache['FILE'][$_position]['position'];
44
            $this->value = $this->cache['FILE'][$_position]['value'];
45
46
            return $_success;
47
        }
48
49
        $_value3 = array();
50
51
        $_success = $this->parseRESET_LINE_COUNT();
52
53
        if ($_success) {
54
            $_value3[] = $this->value;
55
56
            $_position1 = $this->position;
57
            $_cut2 = $this->cut;
58
59
            $this->cut = false;
60
            $_success = $this->parseL_REQ_CONTAINER();
61
62
            if (!$_success && !$this->cut) {
63
                $this->position = $_position1;
64
65
                $_success = $this->parseL_RESP_MANDATE();
66
            }
67
68
            $this->cut = $_cut2;
69
70
            if ($_success) {
71
                $layout = $this->value;
72
            }
73
        }
74
75
        if ($_success) {
76
            $_value3[] = $this->value;
77
78
            $this->value = $_value3;
79
        }
80
81
        if ($_success) {
82
            $this->value = call_user_func(function () use (&$layout) {
83
                return $layout;
84
            });
85
        }
86
87
        $this->cache['FILE'][$_position] = array(
88
            'success' => $_success,
89
            'position' => $this->position,
90
            'value' => $this->value
91
        );
92
93
        if (!$_success) {
94
            $this->report($_position, 'FILE');
95
        }
96
97
        return $_success;
98
    }
99
100
    protected function parseRESET_LINE_COUNT()
101
    {
102
        $_position = $this->position;
103
104
        if (isset($this->cache['RESET_LINE_COUNT'][$_position])) {
105
            $_success = $this->cache['RESET_LINE_COUNT'][$_position]['success'];
106
            $this->position = $this->cache['RESET_LINE_COUNT'][$_position]['position'];
107
            $this->value = $this->cache['RESET_LINE_COUNT'][$_position]['value'];
108
109
            return $_success;
110
        }
111
112
        if (substr($this->string, $this->position, strlen('')) === '') {
113
            $_success = true;
114
            $this->value = substr($this->string, $this->position, strlen(''));
115
            $this->position += strlen('');
116
        } else {
117
            $_success = false;
118
119
            $this->report($this->position, '\'\'');
120
        }
121
122
        if ($_success) {
123
            $this->value = call_user_func(function () {
124
                $this->currentLineNr = 0;
0 ignored issues
show
Bug introduced by
The property currentLineNr does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
125
            });
126
        }
127
128
        $this->cache['RESET_LINE_COUNT'][$_position] = array(
129
            'success' => $_success,
130
            'position' => $this->position,
131
            'value' => $this->value
132
        );
133
134
        if (!$_success) {
135
            $this->report($_position, 'RESET_LINE_COUNT');
136
        }
137
138
        return $_success;
139
    }
140
141
    protected function parseR_GENERIC_OPENING()
142
    {
143
        $_position = $this->position;
144
145
        if (isset($this->cache['R_GENERIC_OPENING'][$_position])) {
146
            $_success = $this->cache['R_GENERIC_OPENING'][$_position]['success'];
147
            $this->position = $this->cache['R_GENERIC_OPENING'][$_position]['position'];
148
            $this->value = $this->cache['R_GENERIC_OPENING'][$_position]['value'];
149
150
            return $_success;
151
        }
152
153
        $_value4 = array();
154
155
        if (substr($this->string, $this->position, strlen('01')) === '01') {
156
            $_success = true;
157
            $this->value = substr($this->string, $this->position, strlen('01'));
158
            $this->position += strlen('01');
159
        } else {
160
            $_success = false;
161
162
            $this->report($this->position, '\'01\'');
163
        }
164
165 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
            $_value4[] = $this->value;
167
168
            if (substr($this->string, $this->position, strlen('AUTOGIRO')) === 'AUTOGIRO') {
169
                $_success = true;
170
                $this->value = substr($this->string, $this->position, strlen('AUTOGIRO'));
171
                $this->position += strlen('AUTOGIRO');
172
            } else {
173
                $_success = false;
174
175
                $this->report($this->position, '\'AUTOGIRO\'');
176
            }
177
        }
178
179
        if ($_success) {
180
            $_value4[] = $this->value;
181
182
            $_success = $this->parseS10();
183
        }
184
185
        if ($_success) {
186
            $_value4[] = $this->value;
187
188
            $_success = $this->parseS();
189
        }
190
191
        if ($_success) {
192
            $_value4[] = $this->value;
193
194
            $_success = $this->parseS();
195
        }
196
197
        if ($_success) {
198
            $_value4[] = $this->value;
199
200
            $_success = $this->parseS();
201
        }
202
203
        if ($_success) {
204
            $_value4[] = $this->value;
205
206
            $_success = $this->parseS();
207
        }
208
209
        if ($_success) {
210
            $_value4[] = $this->value;
211
212
            $_success = $this->parseDATE();
213
214
            if ($_success) {
215
                $date = $this->value;
216
            }
217
        }
218
219
        if ($_success) {
220
            $_value4[] = $this->value;
221
222
            $_success = $this->parseS10();
223
        }
224
225
        if ($_success) {
226
            $_value4[] = $this->value;
227
228
            $_success = $this->parseS();
229
        }
230
231
        if ($_success) {
232
            $_value4[] = $this->value;
233
234
            $_success = $this->parseS();
235
        }
236
237
        if ($_success) {
238
            $_value4[] = $this->value;
239
240
            $_success = $this->parseA20();
241
242
            if ($_success) {
243
                $layout = $this->value;
244
            }
245
        }
246
247 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
248
            $_value4[] = $this->value;
249
250
            $_success = $this->parseCUST_NR();
251
252
            if ($_success) {
253
                $custNr = $this->value;
254
            }
255
        }
256
257 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258
            $_value4[] = $this->value;
259
260
            $_success = $this->parseBANKGIRO();
261
262
            if ($_success) {
263
                $bg = $this->value;
264
            }
265
        }
266
267
        if ($_success) {
268
            $_value4[] = $this->value;
269
270
            $_success = $this->parseEOR();
271
        }
272
273
        if ($_success) {
274
            $_value4[] = $this->value;
275
276
            $this->value = $_value4;
277
        }
278
279 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
280
            $this->value = call_user_func(function () use (&$date, &$layout, &$custNr, &$bg) {
281
                return new OpeningNode(rtrim($layout), $date, $custNr, $bg, $this->currentLineNr);
282
            });
283
        }
284
285
        $this->cache['R_GENERIC_OPENING'][$_position] = array(
286
            'success' => $_success,
287
            'position' => $this->position,
288
            'value' => $this->value
289
        );
290
291
        if (!$_success) {
292
            $this->report($_position, 'R_GENERIC_OPENING');
293
        }
294
295
        return $_success;
296
    }
297
298
    protected function parseL_REQ_CONTAINER()
299
    {
300
        $_position = $this->position;
301
302
        if (isset($this->cache['L_REQ_CONTAINER'][$_position])) {
303
            $_success = $this->cache['L_REQ_CONTAINER'][$_position]['success'];
304
            $this->position = $this->cache['L_REQ_CONTAINER'][$_position]['position'];
305
            $this->value = $this->cache['L_REQ_CONTAINER'][$_position]['value'];
306
307
            return $_success;
308
        }
309
310
        $_position5 = $this->position;
311
        $_cut6 = $this->cut;
312
313
        $this->cut = false;
314
        $_success = $this->parseL_REQ_MANDATE();
315
316
        if (!$_success && !$this->cut) {
317
            $this->position = $_position5;
318
319
            $_success = $this->parseL_REQ_PAYMENT();
320
        }
321
322
        if (!$_success && !$this->cut) {
323
            $this->position = $_position5;
324
325
            $_success = $this->parseL_REQ_AMENDMENT();
326
        }
327
328
        $this->cut = $_cut6;
329
330
        if ($_success) {
331
            $_value8 = array($this->value);
332
            $_cut9 = $this->cut;
333
334
            while (true) {
335
                $_position7 = $this->position;
336
337
                $this->cut = false;
338
                $_position5 = $this->position;
339
                $_cut6 = $this->cut;
340
341
                $this->cut = false;
342
                $_success = $this->parseL_REQ_MANDATE();
343
344
                if (!$_success && !$this->cut) {
345
                    $this->position = $_position5;
346
347
                    $_success = $this->parseL_REQ_PAYMENT();
348
                }
349
350
                if (!$_success && !$this->cut) {
351
                    $this->position = $_position5;
352
353
                    $_success = $this->parseL_REQ_AMENDMENT();
354
                }
355
356
                $this->cut = $_cut6;
357
358
                if (!$_success) {
359
                    break;
360
                }
361
362
                $_value8[] = $this->value;
363
            }
364
365
            if (!$this->cut) {
366
                $_success = true;
367
                $this->position = $_position7;
0 ignored issues
show
Bug introduced by
The variable $_position7 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
368
                $this->value = $_value8;
369
            }
370
371
            $this->cut = $_cut9;
372
        }
373
374
        if ($_success) {
375
            $layouts = $this->value;
376
        }
377
378
        if ($_success) {
379
            $this->value = call_user_func(function () use (&$layouts) {
380
                return new FileNode(...$layouts);
381
            });
382
        }
383
384
        $this->cache['L_REQ_CONTAINER'][$_position] = array(
385
            'success' => $_success,
386
            'position' => $this->position,
387
            'value' => $this->value
388
        );
389
390
        if (!$_success) {
391
            $this->report($_position, 'L_REQ_CONTAINER');
392
        }
393
394
        return $_success;
395
    }
396
397
    protected function parseR_REQ_OPENING()
398
    {
399
        $_position = $this->position;
400
401
        if (isset($this->cache['R_REQ_OPENING'][$_position])) {
402
            $_success = $this->cache['R_REQ_OPENING'][$_position]['success'];
403
            $this->position = $this->cache['R_REQ_OPENING'][$_position]['position'];
404
            $this->value = $this->cache['R_REQ_OPENING'][$_position]['value'];
405
406
            return $_success;
407
        }
408
409
        $_value10 = array();
410
411
        if (substr($this->string, $this->position, strlen('01')) === '01') {
412
            $_success = true;
413
            $this->value = substr($this->string, $this->position, strlen('01'));
414
            $this->position += strlen('01');
415
        } else {
416
            $_success = false;
417
418
            $this->report($this->position, '\'01\'');
419
        }
420
421
        if ($_success) {
422
            $_value10[] = $this->value;
423
424
            $_success = $this->parseDATE();
425
426
            if ($_success) {
427
                $date = $this->value;
428
            }
429
        }
430
431 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
            $_value10[] = $this->value;
433
434
            if (substr($this->string, $this->position, strlen('AUTOGIRO')) === 'AUTOGIRO') {
435
                $_success = true;
436
                $this->value = substr($this->string, $this->position, strlen('AUTOGIRO'));
437
                $this->position += strlen('AUTOGIRO');
438
            } else {
439
                $_success = false;
440
441
                $this->report($this->position, '\'AUTOGIRO\'');
442
            }
443
        }
444
445
        if ($_success) {
446
            $_value10[] = $this->value;
447
448
            $_success = $this->parseS20();
449
        }
450
451
        if ($_success) {
452
            $_value10[] = $this->value;
453
454
            $_success = $this->parseS20();
455
        }
456
457
        if ($_success) {
458
            $_value10[] = $this->value;
459
460
            $_success = $this->parseS();
461
        }
462
463
        if ($_success) {
464
            $_value10[] = $this->value;
465
466
            $_success = $this->parseS();
467
        }
468
469
        if ($_success) {
470
            $_value10[] = $this->value;
471
472
            $_success = $this->parseS();
473
        }
474
475
        if ($_success) {
476
            $_value10[] = $this->value;
477
478
            $_success = $this->parseS();
479
        }
480
481 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
482
            $_value10[] = $this->value;
483
484
            $_success = $this->parseCUST_NR();
485
486
            if ($_success) {
487
                $custNr = $this->value;
488
            }
489
        }
490
491 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
492
            $_value10[] = $this->value;
493
494
            $_success = $this->parseBANKGIRO();
495
496
            if ($_success) {
497
                $bg = $this->value;
498
            }
499
        }
500
501
        if ($_success) {
502
            $_value10[] = $this->value;
503
504
            $_success = $this->parseEOR();
505
        }
506
507
        if ($_success) {
508
            $_value10[] = $this->value;
509
510
            $this->value = $_value10;
511
        }
512
513
        if ($_success) {
514
            $this->value = call_user_func(function () use (&$date, &$custNr, &$bg) {
515
                // TODO layout_request kan vara ''
516
                    // kanske lägga in ett test i visitor som kontrollerar att layoutId är ett känt värde... ??
517
                return new OpeningNode('', $date, $custNr, $bg, $this->currentLineNr);
518
            });
519
        }
520
521
        $this->cache['R_REQ_OPENING'][$_position] = array(
522
            'success' => $_success,
523
            'position' => $this->position,
524
            'value' => $this->value
525
        );
526
527
        if (!$_success) {
528
            $this->report($_position, 'R_REQ_OPENING');
529
        }
530
531
        return $_success;
532
    }
533
534
    protected function parseL_REQ_MANDATE()
535
    {
536
        $_position = $this->position;
537
538
        if (isset($this->cache['L_REQ_MANDATE'][$_position])) {
539
            $_success = $this->cache['L_REQ_MANDATE'][$_position]['success'];
540
            $this->position = $this->cache['L_REQ_MANDATE'][$_position]['position'];
541
            $this->value = $this->cache['L_REQ_MANDATE'][$_position]['value'];
542
543
            return $_success;
544
        }
545
546
        $_value16 = array();
547
548
        $_success = $this->parseR_REQ_OPENING();
549
550
        if ($_success) {
551
            $opening = $this->value;
552
        }
553
554
        if ($_success) {
555
            $_value16[] = $this->value;
556
557
            $_position11 = $this->position;
558
            $_cut12 = $this->cut;
559
560
            $this->cut = false;
561
            $_success = $this->parseR_REQ_CREATE_MANDATE();
562
563
            if (!$_success && !$this->cut) {
564
                $this->position = $_position11;
565
566
                $_success = $this->parseR_REQ_CONFIRM_MANDATE();
567
            }
568
569
            if (!$_success && !$this->cut) {
570
                $this->position = $_position11;
571
572
                $_success = $this->parseR_REQ_UPDATE_MANDATE();
573
            }
574
575
            if (!$_success && !$this->cut) {
576
                $this->position = $_position11;
577
578
                $_success = $this->parseR_REQ_DEL_MANDATE();
579
            }
580
581
            $this->cut = $_cut12;
582
583
            if ($_success) {
584
                $_value14 = array($this->value);
585
                $_cut15 = $this->cut;
586
587
                while (true) {
588
                    $_position13 = $this->position;
589
590
                    $this->cut = false;
591
                    $_position11 = $this->position;
592
                    $_cut12 = $this->cut;
593
594
                    $this->cut = false;
595
                    $_success = $this->parseR_REQ_CREATE_MANDATE();
596
597
                    if (!$_success && !$this->cut) {
598
                        $this->position = $_position11;
599
600
                        $_success = $this->parseR_REQ_CONFIRM_MANDATE();
601
                    }
602
603
                    if (!$_success && !$this->cut) {
604
                        $this->position = $_position11;
605
606
                        $_success = $this->parseR_REQ_UPDATE_MANDATE();
607
                    }
608
609
                    if (!$_success && !$this->cut) {
610
                        $this->position = $_position11;
611
612
                        $_success = $this->parseR_REQ_DEL_MANDATE();
613
                    }
614
615
                    $this->cut = $_cut12;
616
617
                    if (!$_success) {
618
                        break;
619
                    }
620
621
                    $_value14[] = $this->value;
622
                }
623
624
                if (!$this->cut) {
625
                    $_success = true;
626
                    $this->position = $_position13;
0 ignored issues
show
Bug introduced by
The variable $_position13 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
627
                    $this->value = $_value14;
628
                }
629
630
                $this->cut = $_cut15;
631
            }
632
633
            if ($_success) {
634
                $records = $this->value;
635
            }
636
        }
637
638
        if ($_success) {
639
            $_value16[] = $this->value;
640
641
            $this->value = $_value16;
642
        }
643
644
        if ($_success) {
645
            $this->value = call_user_func(function () use (&$opening, &$records) {
646
                $opening->setAttribute('layout_name', Layouts::LAYOUT_MANDATE_REQUEST);
647
648
                return new LayoutNode(
649
                    $opening,
650
                    new ClosingNode($opening->getAttribute('date'), count($records), $this->currentLineNr),
651
                    ...$records
652
                );
653
            });
654
        }
655
656
        $this->cache['L_REQ_MANDATE'][$_position] = array(
657
            'success' => $_success,
658
            'position' => $this->position,
659
            'value' => $this->value
660
        );
661
662
        if (!$_success) {
663
            $this->report($_position, 'L_REQ_MANDATE');
664
        }
665
666
        return $_success;
667
    }
668
669
    protected function parseR_REQ_CREATE_MANDATE()
670
    {
671
        $_position = $this->position;
672
673
        if (isset($this->cache['R_REQ_CREATE_MANDATE'][$_position])) {
674
            $_success = $this->cache['R_REQ_CREATE_MANDATE'][$_position]['success'];
675
            $this->position = $this->cache['R_REQ_CREATE_MANDATE'][$_position]['position'];
676
            $this->value = $this->cache['R_REQ_CREATE_MANDATE'][$_position]['value'];
677
678
            return $_success;
679
        }
680
681
        $_value20 = array();
682
683
        if (substr($this->string, $this->position, strlen('04')) === '04') {
684
            $_success = true;
685
            $this->value = substr($this->string, $this->position, strlen('04'));
686
            $this->position += strlen('04');
687
        } else {
688
            $_success = false;
689
690
            $this->report($this->position, '\'04\'');
691
        }
692
693 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
694
            $_value20[] = $this->value;
695
696
            $_success = $this->parseBANKGIRO();
697
698
            if ($_success) {
699
                $bg = $this->value;
700
            }
701
        }
702
703 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
704
            $_value20[] = $this->value;
705
706
            $_success = $this->parsePAYER_NR();
707
708
            if ($_success) {
709
                $payerNr = $this->value;
710
            }
711
        }
712
713
        if ($_success) {
714
            $_value20[] = $this->value;
715
716
            $_success = $this->parseACCOUNT();
717
718
            if ($_success) {
719
                $account = $this->value;
720
            }
721
        }
722
723
        if ($_success) {
724
            $_value20[] = $this->value;
725
726
            $_success = $this->parseID();
727
728
            if ($_success) {
729
                $id = $this->value;
730
            }
731
        }
732
733
        if ($_success) {
734
            $_value20[] = $this->value;
735
736
            $_position18 = $this->position;
737
            $_cut19 = $this->cut;
738
739
            $this->cut = false;
740
            $_value17 = array();
741
742
            $_success = $this->parseS20();
743
744
            if ($_success) {
745
                $_value17[] = $this->value;
746
747
                $_success = $this->parseS();
748
            }
749
750
            if ($_success) {
751
                $_value17[] = $this->value;
752
753
                $_success = $this->parseS();
754
            }
755
756
            if ($_success) {
757
                $_value17[] = $this->value;
758
759
                $this->value = $_value17;
760
            }
761
762
            if (!$_success && !$this->cut) {
763
                $_success = true;
764
                $this->position = $_position18;
765
                $this->value = null;
766
            }
767
768
            $this->cut = $_cut19;
769
        }
770
771
        if ($_success) {
772
            $_value20[] = $this->value;
773
774
            $_success = $this->parseEOR();
775
        }
776
777
        if ($_success) {
778
            $_value20[] = $this->value;
779
780
            $this->value = $_value20;
781
        }
782
783 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
784
            $this->value = call_user_func(function () use (&$bg, &$payerNr, &$account, &$id) {
785
                return new RequestMandateCreationNode($bg, $payerNr, $account, $id, $this->currentLineNr);
786
            });
787
        }
788
789
        $this->cache['R_REQ_CREATE_MANDATE'][$_position] = array(
790
            'success' => $_success,
791
            'position' => $this->position,
792
            'value' => $this->value
793
        );
794
795
        if (!$_success) {
796
            $this->report($_position, 'R_REQ_CREATE_MANDATE');
797
        }
798
799
        return $_success;
800
    }
801
802
    protected function parseR_REQ_CONFIRM_MANDATE()
803
    {
804
        $_position = $this->position;
805
806
        if (isset($this->cache['R_REQ_CONFIRM_MANDATE'][$_position])) {
807
            $_success = $this->cache['R_REQ_CONFIRM_MANDATE'][$_position]['success'];
808
            $this->position = $this->cache['R_REQ_CONFIRM_MANDATE'][$_position]['position'];
809
            $this->value = $this->cache['R_REQ_CONFIRM_MANDATE'][$_position]['value'];
810
811
            return $_success;
812
        }
813
814
        $_value24 = array();
815
816
        if (substr($this->string, $this->position, strlen('04')) === '04') {
817
            $_success = true;
818
            $this->value = substr($this->string, $this->position, strlen('04'));
819
            $this->position += strlen('04');
820
        } else {
821
            $_success = false;
822
823
            $this->report($this->position, '\'04\'');
824
        }
825
826 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
827
            $_value24[] = $this->value;
828
829
            $_success = $this->parseBANKGIRO();
830
831
            if ($_success) {
832
                $bg = $this->value;
833
            }
834
        }
835
836 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
837
            $_value24[] = $this->value;
838
839
            $_success = $this->parsePAYER_NR();
840
841
            if ($_success) {
842
                $payerNr = $this->value;
843
            }
844
        }
845
846
        if ($_success) {
847
            $_value24[] = $this->value;
848
849
            $_position22 = $this->position;
850
            $_cut23 = $this->cut;
851
852
            $this->cut = false;
853
            $_value21 = array();
854
855
            $_success = $this->parseA40();
856
857
            if ($_success) {
858
                $_value21[] = $this->value;
859
860
                $_success = $this->parseA5();
861
            }
862
863
            if ($_success) {
864
                $_value21[] = $this->value;
865
866
                $_success = $this->parseA();
867
            }
868
869
            if ($_success) {
870
                $_value21[] = $this->value;
871
872
                $_success = $this->parseA();
873
            }
874
875
            if ($_success) {
876
                $_value21[] = $this->value;
877
878
                $_success = $this->parseA();
879
            }
880
881 View Code Duplication
            if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
882
                $_value21[] = $this->value;
883
884
                if (substr($this->string, $this->position, strlen('AV')) === 'AV') {
885
                    $_success = true;
886
                    $this->value = substr($this->string, $this->position, strlen('AV'));
887
                    $this->position += strlen('AV');
888
                } else {
889
                    $_success = false;
890
891
                    $this->report($this->position, '\'AV\'');
892
                }
893
894
                if ($_success) {
895
                    $reject = $this->value;
896
                }
897
            }
898
899
            if ($_success) {
900
                $_value21[] = $this->value;
901
902
                $this->value = $_value21;
903
            }
904
905
            if (!$_success && !$this->cut) {
906
                $_success = true;
907
                $this->position = $_position22;
908
                $this->value = null;
909
            }
910
911
            $this->cut = $_cut23;
912
        }
913
914
        if ($_success) {
915
            $_value24[] = $this->value;
916
917
            $_success = $this->parseEOR();
918
        }
919
920
        if ($_success) {
921
            $_value24[] = $this->value;
922
923
            $this->value = $_value24;
924
        }
925
926 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
927
            $this->value = call_user_func(function () use (&$bg, &$payerNr, &$reject) {
928
                return $reject == 'AV'
929
                    ? new RequestMandateRejectionNode($bg, $payerNr, $this->currentLineNr)
930
                    : new RequestMandateAcceptanceNode($bg, $payerNr, $this->currentLineNr);
931
            });
932
        }
933
934
        $this->cache['R_REQ_CONFIRM_MANDATE'][$_position] = array(
935
            'success' => $_success,
936
            'position' => $this->position,
937
            'value' => $this->value
938
        );
939
940
        if (!$_success) {
941
            $this->report($_position, 'R_REQ_CONFIRM_MANDATE');
942
        }
943
944
        return $_success;
945
    }
946
947
    protected function parseR_REQ_UPDATE_MANDATE()
948
    {
949
        $_position = $this->position;
950
951
        if (isset($this->cache['R_REQ_UPDATE_MANDATE'][$_position])) {
952
            $_success = $this->cache['R_REQ_UPDATE_MANDATE'][$_position]['success'];
953
            $this->position = $this->cache['R_REQ_UPDATE_MANDATE'][$_position]['position'];
954
            $this->value = $this->cache['R_REQ_UPDATE_MANDATE'][$_position]['value'];
955
956
            return $_success;
957
        }
958
959
        $_value25 = array();
960
961
        if (substr($this->string, $this->position, strlen('05')) === '05') {
962
            $_success = true;
963
            $this->value = substr($this->string, $this->position, strlen('05'));
964
            $this->position += strlen('05');
965
        } else {
966
            $_success = false;
967
968
            $this->report($this->position, '\'05\'');
969
        }
970
971 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
972
            $_value25[] = $this->value;
973
974
            $_success = $this->parseBANKGIRO();
975
976
            if ($_success) {
977
                $oldBg = $this->value;
978
            }
979
        }
980
981 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
982
            $_value25[] = $this->value;
983
984
            $_success = $this->parsePAYER_NR();
985
986
            if ($_success) {
987
                $oldPayerNr = $this->value;
988
            }
989
        }
990
991 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
992
            $_value25[] = $this->value;
993
994
            $_success = $this->parseBANKGIRO();
995
996
            if ($_success) {
997
                $newBg = $this->value;
998
            }
999
        }
1000
1001 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1002
            $_value25[] = $this->value;
1003
1004
            $_success = $this->parsePAYER_NR();
1005
1006
            if ($_success) {
1007
                $newPayerNr = $this->value;
1008
            }
1009
        }
1010
1011
        if ($_success) {
1012
            $_value25[] = $this->value;
1013
1014
            $_success = $this->parseEOR();
1015
        }
1016
1017
        if ($_success) {
1018
            $_value25[] = $this->value;
1019
1020
            $this->value = $_value25;
1021
        }
1022
1023
        if ($_success) {
1024
            $this->value = call_user_func(function () use (&$oldBg, &$oldPayerNr, &$newBg, &$newPayerNr) {
1025
                return new RequestMandateUpdateNode($oldBg, $oldPayerNr, $newBg, $newPayerNr, $this->currentLineNr);
1026
            });
1027
        }
1028
1029
        $this->cache['R_REQ_UPDATE_MANDATE'][$_position] = array(
1030
            'success' => $_success,
1031
            'position' => $this->position,
1032
            'value' => $this->value
1033
        );
1034
1035
        if (!$_success) {
1036
            $this->report($_position, 'R_REQ_UPDATE_MANDATE');
1037
        }
1038
1039
        return $_success;
1040
    }
1041
1042
    protected function parseR_REQ_DEL_MANDATE()
1043
    {
1044
        $_position = $this->position;
1045
1046
        if (isset($this->cache['R_REQ_DEL_MANDATE'][$_position])) {
1047
            $_success = $this->cache['R_REQ_DEL_MANDATE'][$_position]['success'];
1048
            $this->position = $this->cache['R_REQ_DEL_MANDATE'][$_position]['position'];
1049
            $this->value = $this->cache['R_REQ_DEL_MANDATE'][$_position]['value'];
1050
1051
            return $_success;
1052
        }
1053
1054
        $_value26 = array();
1055
1056
        if (substr($this->string, $this->position, strlen('03')) === '03') {
1057
            $_success = true;
1058
            $this->value = substr($this->string, $this->position, strlen('03'));
1059
            $this->position += strlen('03');
1060
        } else {
1061
            $_success = false;
1062
1063
            $this->report($this->position, '\'03\'');
1064
        }
1065
1066 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1067
            $_value26[] = $this->value;
1068
1069
            $_success = $this->parseBANKGIRO();
1070
1071
            if ($_success) {
1072
                $bg = $this->value;
1073
            }
1074
        }
1075
1076 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1077
            $_value26[] = $this->value;
1078
1079
            $_success = $this->parsePAYER_NR();
1080
1081
            if ($_success) {
1082
                $payerNr = $this->value;
1083
            }
1084
        }
1085
1086
        if ($_success) {
1087
            $_value26[] = $this->value;
1088
1089
            $_success = $this->parseEOR();
1090
        }
1091
1092
        if ($_success) {
1093
            $_value26[] = $this->value;
1094
1095
            $this->value = $_value26;
1096
        }
1097
1098 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1099
            $this->value = call_user_func(function () use (&$bg, &$payerNr) {
1100
                return new RequestMandateDeletionNode($bg, $payerNr, $this->currentLineNr);
1101
            });
1102
        }
1103
1104
        $this->cache['R_REQ_DEL_MANDATE'][$_position] = array(
1105
            'success' => $_success,
1106
            'position' => $this->position,
1107
            'value' => $this->value
1108
        );
1109
1110
        if (!$_success) {
1111
            $this->report($_position, 'R_REQ_DEL_MANDATE');
1112
        }
1113
1114
        return $_success;
1115
    }
1116
1117 View Code Duplication
    protected function parseL_REQ_PAYMENT()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1118
    {
1119
        $_position = $this->position;
1120
1121
        if (isset($this->cache['L_REQ_PAYMENT'][$_position])) {
1122
            $_success = $this->cache['L_REQ_PAYMENT'][$_position]['success'];
1123
            $this->position = $this->cache['L_REQ_PAYMENT'][$_position]['position'];
1124
            $this->value = $this->cache['L_REQ_PAYMENT'][$_position]['value'];
1125
1126
            return $_success;
1127
        }
1128
1129
        $_value30 = array();
1130
1131
        $_success = $this->parseR_REQ_OPENING();
1132
1133
        if ($_success) {
1134
            $opening = $this->value;
1135
        }
1136
1137
        if ($_success) {
1138
            $_value30[] = $this->value;
1139
1140
            if (substr($this->string, $this->position, strlen('')) === '') {
1141
                $_success = true;
1142
                $this->value = substr($this->string, $this->position, strlen(''));
1143
                $this->position += strlen('');
1144
            } else {
1145
                $_success = false;
1146
1147
                $this->report($this->position, '\'\'');
1148
            }
1149
1150
            if ($_success) {
1151
                $_value28 = array($this->value);
1152
                $_cut29 = $this->cut;
1153
1154
                while (true) {
1155
                    $_position27 = $this->position;
1156
1157
                    $this->cut = false;
1158
                    if (substr($this->string, $this->position, strlen('')) === '') {
1159
                        $_success = true;
1160
                        $this->value = substr($this->string, $this->position, strlen(''));
1161
                        $this->position += strlen('');
1162
                    } else {
1163
                        $_success = false;
1164
1165
                        $this->report($this->position, '\'\'');
1166
                    }
1167
1168
                    if (!$_success) {
1169
                        break;
1170
                    }
1171
1172
                    $_value28[] = $this->value;
1173
                }
1174
1175
                if (!$this->cut) {
1176
                    $_success = true;
1177
                    $this->position = $_position27;
0 ignored issues
show
Bug introduced by
The variable $_position27 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1178
                    $this->value = $_value28;
1179
                }
1180
1181
                $this->cut = $_cut29;
1182
            }
1183
1184
            if ($_success) {
1185
                $records = $this->value;
1186
            }
1187
        }
1188
1189
        if ($_success) {
1190
            $_value30[] = $this->value;
1191
1192
            $this->value = $_value30;
1193
        }
1194
1195
        if ($_success) {
1196
            $this->value = call_user_func(function () use (&$opening, &$records) {
1197
                $opening->setAttribute('layout_name', Layouts::LAYOUT_PAYMENT_REQUEST);
1198
1199
                return new LayoutNode(
1200
                    $opening,
1201
                    new ClosingNode($opening->getAttribute('date'), count($records), $this->currentLineNr),
1202
                    ...$records
1203
                );
1204
            });
1205
        }
1206
1207
        $this->cache['L_REQ_PAYMENT'][$_position] = array(
1208
            'success' => $_success,
1209
            'position' => $this->position,
1210
            'value' => $this->value
1211
        );
1212
1213
        if (!$_success) {
1214
            $this->report($_position, 'L_REQ_PAYMENT');
1215
        }
1216
1217
        return $_success;
1218
    }
1219
1220 View Code Duplication
    protected function parseL_REQ_AMENDMENT()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1221
    {
1222
        $_position = $this->position;
1223
1224
        if (isset($this->cache['L_REQ_AMENDMENT'][$_position])) {
1225
            $_success = $this->cache['L_REQ_AMENDMENT'][$_position]['success'];
1226
            $this->position = $this->cache['L_REQ_AMENDMENT'][$_position]['position'];
1227
            $this->value = $this->cache['L_REQ_AMENDMENT'][$_position]['value'];
1228
1229
            return $_success;
1230
        }
1231
1232
        $_value34 = array();
1233
1234
        $_success = $this->parseR_REQ_OPENING();
1235
1236
        if ($_success) {
1237
            $opening = $this->value;
1238
        }
1239
1240
        if ($_success) {
1241
            $_value34[] = $this->value;
1242
1243
            if (substr($this->string, $this->position, strlen('')) === '') {
1244
                $_success = true;
1245
                $this->value = substr($this->string, $this->position, strlen(''));
1246
                $this->position += strlen('');
1247
            } else {
1248
                $_success = false;
1249
1250
                $this->report($this->position, '\'\'');
1251
            }
1252
1253
            if ($_success) {
1254
                $_value32 = array($this->value);
1255
                $_cut33 = $this->cut;
1256
1257
                while (true) {
1258
                    $_position31 = $this->position;
1259
1260
                    $this->cut = false;
1261
                    if (substr($this->string, $this->position, strlen('')) === '') {
1262
                        $_success = true;
1263
                        $this->value = substr($this->string, $this->position, strlen(''));
1264
                        $this->position += strlen('');
1265
                    } else {
1266
                        $_success = false;
1267
1268
                        $this->report($this->position, '\'\'');
1269
                    }
1270
1271
                    if (!$_success) {
1272
                        break;
1273
                    }
1274
1275
                    $_value32[] = $this->value;
1276
                }
1277
1278
                if (!$this->cut) {
1279
                    $_success = true;
1280
                    $this->position = $_position31;
0 ignored issues
show
Bug introduced by
The variable $_position31 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1281
                    $this->value = $_value32;
1282
                }
1283
1284
                $this->cut = $_cut33;
1285
            }
1286
1287
            if ($_success) {
1288
                $records = $this->value;
1289
            }
1290
        }
1291
1292
        if ($_success) {
1293
            $_value34[] = $this->value;
1294
1295
            $this->value = $_value34;
1296
        }
1297
1298
        if ($_success) {
1299
            $this->value = call_user_func(function () use (&$opening, &$records) {
1300
                $opening->setAttribute('layout_name', Layouts::LAYOUT_AMENDMENT_REQUEST);
1301
1302
                return new LayoutNode(
1303
                    $opening,
1304
                    new ClosingNode($opening->getAttribute('date'), count($records), $this->currentLineNr),
1305
                    ...$records
1306
                );
1307
            });
1308
        }
1309
1310
        $this->cache['L_REQ_AMENDMENT'][$_position] = array(
1311
            'success' => $_success,
1312
            'position' => $this->position,
1313
            'value' => $this->value
1314
        );
1315
1316
        if (!$_success) {
1317
            $this->report($_position, 'L_REQ_AMENDMENT');
1318
        }
1319
1320
        return $_success;
1321
    }
1322
1323
    protected function parseL_RESP_MANDATE()
1324
    {
1325
        $_position = $this->position;
1326
1327
        if (isset($this->cache['L_RESP_MANDATE'][$_position])) {
1328
            $_success = $this->cache['L_RESP_MANDATE'][$_position]['success'];
1329
            $this->position = $this->cache['L_RESP_MANDATE'][$_position]['position'];
1330
            $this->value = $this->cache['L_RESP_MANDATE'][$_position]['value'];
1331
1332
            return $_success;
1333
        }
1334
1335
        $_value40 = array();
1336
1337
        $_position35 = $this->position;
1338
        $_cut36 = $this->cut;
1339
1340
        $this->cut = false;
1341
        $_success = $this->parseR_GENERIC_OPENING();
1342
1343
        if (!$_success && !$this->cut) {
1344
            $this->position = $_position35;
1345
1346
            $_success = $this->parseR_RESP_MANDATE_OPENING_OLD();
1347
        }
1348
1349
        $this->cut = $_cut36;
1350
1351
        if ($_success) {
1352
            $opening = $this->value;
1353
        }
1354
1355
        if ($_success) {
1356
            $_value40[] = $this->value;
1357
1358
            $_value38 = array();
1359
            $_cut39 = $this->cut;
1360
1361
            while (true) {
1362
                $_position37 = $this->position;
1363
1364
                $this->cut = false;
1365
                $_success = $this->parseR_RESP_MANDATE();
1366
1367
                if (!$_success) {
1368
                    break;
1369
                }
1370
1371
                $_value38[] = $this->value;
1372
            }
1373
1374
            if (!$this->cut) {
1375
                $_success = true;
1376
                $this->position = $_position37;
0 ignored issues
show
Bug introduced by
The variable $_position37 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1377
                $this->value = $_value38;
1378
            }
1379
1380
            $this->cut = $_cut39;
1381
1382
            if ($_success) {
1383
                $mandates = $this->value;
1384
            }
1385
        }
1386
1387
        if ($_success) {
1388
            $_value40[] = $this->value;
1389
1390
            $_success = $this->parseR_RESP_MANDATE_CLOSING();
1391
1392
            if ($_success) {
1393
                $closing = $this->value;
1394
            }
1395
        }
1396
1397
        if ($_success) {
1398
            $_value40[] = $this->value;
1399
1400
            $this->value = $_value40;
1401
        }
1402
1403
        if ($_success) {
1404
            $this->value = call_user_func(function () use (&$opening, &$mandates, &$closing) {
1405
                return new FileNode(new LayoutNode($opening, $closing, ...$mandates));
1406
            });
1407
        }
1408
1409
        $this->cache['L_RESP_MANDATE'][$_position] = array(
1410
            'success' => $_success,
1411
            'position' => $this->position,
1412
            'value' => $this->value
1413
        );
1414
1415
        if (!$_success) {
1416
            $this->report($_position, 'L_RESP_MANDATE');
1417
        }
1418
1419
        return $_success;
1420
    }
1421
1422
    protected function parseR_RESP_MANDATE_OPENING_OLD()
1423
    {
1424
        $_position = $this->position;
1425
1426
        if (isset($this->cache['R_RESP_MANDATE_OPENING_OLD'][$_position])) {
1427
            $_success = $this->cache['R_RESP_MANDATE_OPENING_OLD'][$_position]['success'];
1428
            $this->position = $this->cache['R_RESP_MANDATE_OPENING_OLD'][$_position]['position'];
1429
            $this->value = $this->cache['R_RESP_MANDATE_OPENING_OLD'][$_position]['value'];
1430
1431
            return $_success;
1432
        }
1433
1434
        $_value41 = array();
1435
1436
        if (substr($this->string, $this->position, strlen('01')) === '01') {
1437
            $_success = true;
1438
            $this->value = substr($this->string, $this->position, strlen('01'));
1439
            $this->position += strlen('01');
1440
        } else {
1441
            $_success = false;
1442
1443
            $this->report($this->position, '\'01\'');
1444
        }
1445
1446
        if ($_success) {
1447
            $_value41[] = $this->value;
1448
1449
            $_success = $this->parseDATE();
1450
1451
            if ($_success) {
1452
                $date = $this->value;
1453
            }
1454
        }
1455
1456
        if ($_success) {
1457
            $_value41[] = $this->value;
1458
1459
            $_success = $this->parseBGC_CLEARING();
1460
        }
1461
1462 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1463
            $_value41[] = $this->value;
1464
1465
            $_success = $this->parseBANKGIRO();
1466
1467
            if ($_success) {
1468
                $bg = $this->value;
1469
            }
1470
        }
1471
1472 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1473
            $_value41[] = $this->value;
1474
1475
            if (substr($this->string, $this->position, strlen('AG-MEDAVI')) === 'AG-MEDAVI') {
1476
                $_success = true;
1477
                $this->value = substr($this->string, $this->position, strlen('AG-MEDAVI'));
1478
                $this->position += strlen('AG-MEDAVI');
1479
            } else {
1480
                $_success = false;
1481
1482
                $this->report($this->position, '\'AG-MEDAVI\'');
1483
            }
1484
        }
1485
1486
        if ($_success) {
1487
            $_value41[] = $this->value;
1488
1489
            $_success = $this->parseEOR();
1490
        }
1491
1492
        if ($_success) {
1493
            $_value41[] = $this->value;
1494
1495
            $this->value = $_value41;
1496
        }
1497
1498
        if ($_success) {
1499
            $this->value = call_user_func(function () use (&$date, &$bg) {
1500
                return new OpeningNode('AG-MEDAVI', $date, '', $bg, $this->currentLineNr);
1501
            });
1502
        }
1503
1504
        $this->cache['R_RESP_MANDATE_OPENING_OLD'][$_position] = array(
1505
            'success' => $_success,
1506
            'position' => $this->position,
1507
            'value' => $this->value
1508
        );
1509
1510
        if (!$_success) {
1511
            $this->report($_position, 'R_RESP_MANDATE_OPENING_OLD');
1512
        }
1513
1514
        return $_success;
1515
    }
1516
1517
    protected function parseR_RESP_MANDATE()
1518
    {
1519
        $_position = $this->position;
1520
1521
        if (isset($this->cache['R_RESP_MANDATE'][$_position])) {
1522
            $_success = $this->cache['R_RESP_MANDATE'][$_position]['success'];
1523
            $this->position = $this->cache['R_RESP_MANDATE'][$_position]['position'];
1524
            $this->value = $this->cache['R_RESP_MANDATE'][$_position]['value'];
1525
1526
            return $_success;
1527
        }
1528
1529
        $_value50 = array();
1530
1531
        if (substr($this->string, $this->position, strlen('73')) === '73') {
1532
            $_success = true;
1533
            $this->value = substr($this->string, $this->position, strlen('73'));
1534
            $this->position += strlen('73');
1535
        } else {
1536
            $_success = false;
1537
1538
            $this->report($this->position, '\'73\'');
1539
        }
1540
1541 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1542
            $_value50[] = $this->value;
1543
1544
            $_success = $this->parseBANKGIRO();
1545
1546
            if ($_success) {
1547
                $bg = $this->value;
1548
            }
1549
        }
1550
1551 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1552
            $_value50[] = $this->value;
1553
1554
            $_success = $this->parsePAYER_NR();
1555
1556
            if ($_success) {
1557
                $payerNr = $this->value;
1558
            }
1559
        }
1560
1561 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1562
            $_value50[] = $this->value;
1563
1564
            $_position43 = $this->position;
1565
1566
            $_value42 = array();
1567
1568
            $_success = $this->parseA10();
1569
1570
            if ($_success) {
1571
                $_value42[] = $this->value;
1572
1573
                $_success = $this->parseA5();
1574
            }
1575
1576
            if ($_success) {
1577
                $_value42[] = $this->value;
1578
1579
                $_success = $this->parseA();
1580
            }
1581
1582
            if ($_success) {
1583
                $_value42[] = $this->value;
1584
1585
                $this->value = $_value42;
1586
            }
1587
1588
            if ($_success) {
1589
                $this->value = strval(substr($this->string, $_position43, $this->position - $_position43));
1590
            }
1591
1592
            if ($_success) {
1593
                $accountNr = $this->value;
1594
            }
1595
        }
1596
1597
        if ($_success) {
1598
            $_value50[] = $this->value;
1599
1600
            $_success = $this->parseID();
1601
1602
            if ($_success) {
1603
                $id = $this->value;
1604
            }
1605
        }
1606
1607
        if ($_success) {
1608
            $_value50[] = $this->value;
1609
1610
            $_success = $this->parseA5();
1611
        }
1612
1613 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1614
            $_value50[] = $this->value;
1615
1616
            $_position45 = $this->position;
1617
1618
            $_value44 = array();
1619
1620
            $_success = $this->parseN();
1621
1622
            if ($_success) {
1623
                $_value44[] = $this->value;
1624
1625
                $_success = $this->parseN();
1626
            }
1627
1628
            if ($_success) {
1629
                $_value44[] = $this->value;
1630
1631
                $this->value = $_value44;
1632
            }
1633
1634
            if ($_success) {
1635
                $this->value = strval(substr($this->string, $_position45, $this->position - $_position45));
1636
            }
1637
1638
            if ($_success) {
1639
                $info = $this->value;
1640
            }
1641
        }
1642
1643 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1644
            $_value50[] = $this->value;
1645
1646
            $_position47 = $this->position;
1647
1648
            $_value46 = array();
1649
1650
            $_success = $this->parseN();
1651
1652
            if ($_success) {
1653
                $_value46[] = $this->value;
1654
1655
                $_success = $this->parseN();
1656
            }
1657
1658
            if ($_success) {
1659
                $_value46[] = $this->value;
1660
1661
                $this->value = $_value46;
1662
            }
1663
1664
            if ($_success) {
1665
                $this->value = strval(substr($this->string, $_position47, $this->position - $_position47));
1666
            }
1667
1668
            if ($_success) {
1669
                $comment = $this->value;
1670
            }
1671
        }
1672
1673
        if ($_success) {
1674
            $_value50[] = $this->value;
1675
1676
            $_position48 = $this->position;
1677
            $_cut49 = $this->cut;
1678
1679
            $this->cut = false;
1680
            $_success = $this->parseDATE();
1681
1682
            if (!$_success && !$this->cut) {
1683
                $_success = true;
1684
                $this->position = $_position48;
1685
                $this->value = null;
1686
            }
1687
1688
            $this->cut = $_cut49;
1689
1690
            if ($_success) {
1691
                $date = $this->value;
1692
            }
1693
        }
1694
1695
        if ($_success) {
1696
            $_value50[] = $this->value;
1697
1698
            $_success = $this->parseEOR();
1699
        }
1700
1701
        if ($_success) {
1702
            $_value50[] = $this->value;
1703
1704
            $this->value = $_value50;
1705
        }
1706
1707
        if ($_success) {
1708
            $this->value = call_user_func(function () use (&$bg, &$payerNr, &$accountNr, &$id, &$info, &$comment, &$date) {
1709
                // TODO fundera om jag kan dela upp denna i flera R_ så att jag kan använda ACCOUNT ...
1710
                $accountNr = trim(ltrim($accountNr, '0'));
1711
1712
                return new MandateResponseNode(
1713
                    $bg,
1714
                    $payerNr,
1715
                    new AccountNode($this->currentLineNr, $accountNr ?: $payerNr->getValue()),
1716
                    $id,
1717
                    new MessageNode($this->currentLineNr, "73.$info"),
1718
                    new MessageNode($this->currentLineNr, "73.comment.$comment"),
1719
                    $date ?: new \DateTimeImmutable('@0'),
1720
                    $this->currentLineNr
1721
                );
1722
            });
1723
        }
1724
1725
        $this->cache['R_RESP_MANDATE'][$_position] = array(
1726
            'success' => $_success,
1727
            'position' => $this->position,
1728
            'value' => $this->value
1729
        );
1730
1731
        if (!$_success) {
1732
            $this->report($_position, 'R_RESP_MANDATE');
1733
        }
1734
1735
        return $_success;
1736
    }
1737
1738
    protected function parseR_RESP_MANDATE_CLOSING()
1739
    {
1740
        $_position = $this->position;
1741
1742
        if (isset($this->cache['R_RESP_MANDATE_CLOSING'][$_position])) {
1743
            $_success = $this->cache['R_RESP_MANDATE_CLOSING'][$_position]['success'];
1744
            $this->position = $this->cache['R_RESP_MANDATE_CLOSING'][$_position]['position'];
1745
            $this->value = $this->cache['R_RESP_MANDATE_CLOSING'][$_position]['value'];
1746
1747
            return $_success;
1748
        }
1749
1750
        $_value53 = array();
1751
1752
        if (substr($this->string, $this->position, strlen('09')) === '09') {
1753
            $_success = true;
1754
            $this->value = substr($this->string, $this->position, strlen('09'));
1755
            $this->position += strlen('09');
1756
        } else {
1757
            $_success = false;
1758
1759
            $this->report($this->position, '\'09\'');
1760
        }
1761
1762
        if ($_success) {
1763
            $_value53[] = $this->value;
1764
1765
            $_success = $this->parseDATE();
1766
1767
            if ($_success) {
1768
                $date = $this->value;
1769
            }
1770
        }
1771
1772
        if ($_success) {
1773
            $_value53[] = $this->value;
1774
1775
            $_success = $this->parseBGC_CLEARING();
1776
        }
1777
1778 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1779
            $_value53[] = $this->value;
1780
1781
            $_position52 = $this->position;
1782
1783
            $_value51 = array();
1784
1785
            $_success = $this->parseN5();
1786
1787
            if ($_success) {
1788
                $_value51[] = $this->value;
1789
1790
                $_success = $this->parseN();
1791
            }
1792
1793
            if ($_success) {
1794
                $_value51[] = $this->value;
1795
1796
                $_success = $this->parseN();
1797
            }
1798
1799
            if ($_success) {
1800
                $_value51[] = $this->value;
1801
1802
                $this->value = $_value51;
1803
            }
1804
1805
            if ($_success) {
1806
                $this->value = strval(substr($this->string, $_position52, $this->position - $_position52));
1807
            }
1808
1809
            if ($_success) {
1810
                $nrOfPosts = $this->value;
1811
            }
1812
        }
1813
1814
        if ($_success) {
1815
            $_value53[] = $this->value;
1816
1817
            $_success = $this->parseEOR();
1818
        }
1819
1820
        if ($_success) {
1821
            $_value53[] = $this->value;
1822
1823
            $this->value = $_value53;
1824
        }
1825
1826
        if ($_success) {
1827
            $this->value = call_user_func(function () use (&$date, &$nrOfPosts) {
1828
                return new ClosingNode($date, intval($nrOfPosts), $this->currentLineNr);
1829
            });
1830
        }
1831
1832
        $this->cache['R_RESP_MANDATE_CLOSING'][$_position] = array(
1833
            'success' => $_success,
1834
            'position' => $this->position,
1835
            'value' => $this->value
1836
        );
1837
1838
        if (!$_success) {
1839
            $this->report($_position, 'R_RESP_MANDATE_CLOSING');
1840
        }
1841
1842
        return $_success;
1843
    }
1844
1845 View Code Duplication
    protected function parseACCOUNT()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1846
    {
1847
        $_position = $this->position;
1848
1849
        if (isset($this->cache['ACCOUNT'][$_position])) {
1850
            $_success = $this->cache['ACCOUNT'][$_position]['success'];
1851
            $this->position = $this->cache['ACCOUNT'][$_position]['position'];
1852
            $this->value = $this->cache['ACCOUNT'][$_position]['value'];
1853
1854
            return $_success;
1855
        }
1856
1857
        $_position55 = $this->position;
1858
1859
        $_value54 = array();
1860
1861
        $_success = $this->parseN10();
1862
1863
        if ($_success) {
1864
            $_value54[] = $this->value;
1865
1866
            $_success = $this->parseN5();
1867
        }
1868
1869
        if ($_success) {
1870
            $_value54[] = $this->value;
1871
1872
            $_success = $this->parseN();
1873
        }
1874
1875
        if ($_success) {
1876
            $_value54[] = $this->value;
1877
1878
            $this->value = $_value54;
1879
        }
1880
1881
        if ($_success) {
1882
            $this->value = strval(substr($this->string, $_position55, $this->position - $_position55));
1883
        }
1884
1885
        if ($_success) {
1886
            $number = $this->value;
1887
        }
1888
1889
        if ($_success) {
1890
            $this->value = call_user_func(function () use (&$number) {
1891
                return new AccountNode($this->currentLineNr, ltrim($number, '0'));
1892
            });
1893
        }
1894
1895
        $this->cache['ACCOUNT'][$_position] = array(
1896
            'success' => $_success,
1897
            'position' => $this->position,
1898
            'value' => $this->value
1899
        );
1900
1901
        if (!$_success) {
1902
            $this->report($_position, 'ACCOUNT');
1903
        }
1904
1905
        return $_success;
1906
    }
1907
1908
    protected function parseBANKGIRO()
1909
    {
1910
        $_position = $this->position;
1911
1912
        if (isset($this->cache['BANKGIRO'][$_position])) {
1913
            $_success = $this->cache['BANKGIRO'][$_position]['success'];
1914
            $this->position = $this->cache['BANKGIRO'][$_position]['position'];
1915
            $this->value = $this->cache['BANKGIRO'][$_position]['value'];
1916
1917
            return $_success;
1918
        }
1919
1920
        $_success = $this->parseN10();
1921
1922
        if ($_success) {
1923
            $number = $this->value;
1924
        }
1925
1926
        if ($_success) {
1927
            $this->value = call_user_func(function () use (&$number) {
1928
                return new BankgiroNode($this->currentLineNr, ltrim($number, '0'));
1929
            });
1930
        }
1931
1932
        $this->cache['BANKGIRO'][$_position] = array(
1933
            'success' => $_success,
1934
            'position' => $this->position,
1935
            'value' => $this->value
1936
        );
1937
1938
        if (!$_success) {
1939
            $this->report($_position, 'BANKGIRO');
1940
        }
1941
1942
        return $_success;
1943
    }
1944
1945 View Code Duplication
    protected function parseBGC_CLEARING()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1946
    {
1947
        $_position = $this->position;
1948
1949
        if (isset($this->cache['BGC_CLEARING'][$_position])) {
1950
            $_success = $this->cache['BGC_CLEARING'][$_position]['success'];
1951
            $this->position = $this->cache['BGC_CLEARING'][$_position]['position'];
1952
            $this->value = $this->cache['BGC_CLEARING'][$_position]['value'];
1953
1954
            return $_success;
1955
        }
1956
1957
        if (substr($this->string, $this->position, strlen('9900')) === '9900') {
1958
            $_success = true;
1959
            $this->value = substr($this->string, $this->position, strlen('9900'));
1960
            $this->position += strlen('9900');
1961
        } else {
1962
            $_success = false;
1963
1964
            $this->report($this->position, '\'9900\'');
1965
        }
1966
1967
        $this->cache['BGC_CLEARING'][$_position] = array(
1968
            'success' => $_success,
1969
            'position' => $this->position,
1970
            'value' => $this->value
1971
        );
1972
1973
        if (!$_success) {
1974
            $this->report($_position, 'BGC_CLEARING');
1975
        }
1976
1977
        return $_success;
1978
    }
1979
1980
    protected function parseCUST_NR()
1981
    {
1982
        $_position = $this->position;
1983
1984
        if (isset($this->cache['CUST_NR'][$_position])) {
1985
            $_success = $this->cache['CUST_NR'][$_position]['success'];
1986
            $this->position = $this->cache['CUST_NR'][$_position]['position'];
1987
            $this->value = $this->cache['CUST_NR'][$_position]['value'];
1988
1989
            return $_success;
1990
        }
1991
1992
        $_position57 = $this->position;
1993
1994
        $_value56 = array();
1995
1996
        $_success = $this->parseN5();
1997
1998
        if ($_success) {
1999
            $_value56[] = $this->value;
2000
2001
            $_success = $this->parseN();
2002
        }
2003
2004
        if ($_success) {
2005
            $_value56[] = $this->value;
2006
2007
            $this->value = $_value56;
2008
        }
2009
2010
        if ($_success) {
2011
            $this->value = strval(substr($this->string, $_position57, $this->position - $_position57));
2012
        }
2013
2014
        if ($_success) {
2015
            $nr = $this->value;
2016
        }
2017
2018
        if ($_success) {
2019
            $this->value = call_user_func(function () use (&$nr) {
2020
                return ltrim($nr, '0');
2021
            });
2022
        }
2023
2024
        $this->cache['CUST_NR'][$_position] = array(
2025
            'success' => $_success,
2026
            'position' => $this->position,
2027
            'value' => $this->value
2028
        );
2029
2030
        if (!$_success) {
2031
            $this->report($_position, 'CUST_NR');
2032
        }
2033
2034
        return $_success;
2035
    }
2036
2037
    protected function parseDATE()
2038
    {
2039
        $_position = $this->position;
2040
2041
        if (isset($this->cache['DATE'][$_position])) {
2042
            $_success = $this->cache['DATE'][$_position]['success'];
2043
            $this->position = $this->cache['DATE'][$_position]['position'];
2044
            $this->value = $this->cache['DATE'][$_position]['value'];
2045
2046
            return $_success;
2047
        }
2048
2049
        $_position59 = $this->position;
2050
2051
        $_value58 = array();
2052
2053
        $_success = $this->parseN5();
2054
2055
        if ($_success) {
2056
            $_value58[] = $this->value;
2057
2058
            $_success = $this->parseN();
2059
        }
2060
2061
        if ($_success) {
2062
            $_value58[] = $this->value;
2063
2064
            $_success = $this->parseN();
2065
        }
2066
2067
        if ($_success) {
2068
            $_value58[] = $this->value;
2069
2070
            $_success = $this->parseN();
2071
        }
2072
2073
        if ($_success) {
2074
            $_value58[] = $this->value;
2075
2076
            $this->value = $_value58;
2077
        }
2078
2079
        if ($_success) {
2080
            $this->value = strval(substr($this->string, $_position59, $this->position - $_position59));
2081
        }
2082
2083
        if ($_success) {
2084
            $date = $this->value;
2085
        }
2086
2087
        if ($_success) {
2088
            $this->value = call_user_func(function () use (&$date) {
2089
                return new \DateTimeImmutable($date . '000000');
2090
            });
2091
        }
2092
2093
        $this->cache['DATE'][$_position] = array(
2094
            'success' => $_success,
2095
            'position' => $this->position,
2096
            'value' => $this->value
2097
        );
2098
2099
        if (!$_success) {
2100
            $this->report($_position, 'DATE');
2101
        }
2102
2103
        return $_success;
2104
    }
2105
2106
    protected function parseID()
2107
    {
2108
        $_position = $this->position;
2109
2110
        if (isset($this->cache['ID'][$_position])) {
2111
            $_success = $this->cache['ID'][$_position]['success'];
2112
            $this->position = $this->cache['ID'][$_position]['position'];
2113
            $this->value = $this->cache['ID'][$_position]['value'];
2114
2115
            return $_success;
2116
        }
2117
2118
        $_value62 = array();
2119
2120
        $_position61 = $this->position;
2121
2122
        $_value60 = array();
2123
2124
        $_success = $this->parseA();
2125
2126
        if ($_success) {
2127
            $_value60[] = $this->value;
2128
2129
            $_success = $this->parseA();
2130
        }
2131
2132
        if ($_success) {
2133
            $_value60[] = $this->value;
2134
2135
            $this->value = $_value60;
2136
        }
2137
2138
        if ($_success) {
2139
            $this->value = strval(substr($this->string, $_position61, $this->position - $_position61));
2140
        }
2141
2142
        if ($_success) {
2143
            $century = $this->value;
2144
        }
2145
2146
        if ($_success) {
2147
            $_value62[] = $this->value;
2148
2149
            $_success = $this->parseA10();
2150
2151
            if ($_success) {
2152
                $number = $this->value;
2153
            }
2154
        }
2155
2156
        if ($_success) {
2157
            $_value62[] = $this->value;
2158
2159
            $this->value = $_value62;
2160
        }
2161
2162
        if ($_success) {
2163
            $this->value = call_user_func(function () use (&$century, &$number) {
2164
                return in_array($century, ['00', '99'])
2165
                    ? new OrganizationIdNode($this->currentLineNr, $number)
2166
                    : new PersonalIdNode($this->currentLineNr, $century.$number);
2167
            });
2168
        }
2169
2170
        $this->cache['ID'][$_position] = array(
2171
            'success' => $_success,
2172
            'position' => $this->position,
2173
            'value' => $this->value
2174
        );
2175
2176
        if (!$_success) {
2177
            $this->report($_position, 'ID');
2178
        }
2179
2180
        return $_success;
2181
    }
2182
2183 View Code Duplication
    protected function parsePAYER_NR()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2184
    {
2185
        $_position = $this->position;
2186
2187
        if (isset($this->cache['PAYER_NR'][$_position])) {
2188
            $_success = $this->cache['PAYER_NR'][$_position]['success'];
2189
            $this->position = $this->cache['PAYER_NR'][$_position]['position'];
2190
            $this->value = $this->cache['PAYER_NR'][$_position]['value'];
2191
2192
            return $_success;
2193
        }
2194
2195
        $_position64 = $this->position;
2196
2197
        $_value63 = array();
2198
2199
        $_success = $this->parseN10();
2200
2201
        if ($_success) {
2202
            $_value63[] = $this->value;
2203
2204
            $_success = $this->parseN5();
2205
        }
2206
2207
        if ($_success) {
2208
            $_value63[] = $this->value;
2209
2210
            $_success = $this->parseN();
2211
        }
2212
2213
        if ($_success) {
2214
            $_value63[] = $this->value;
2215
2216
            $this->value = $_value63;
2217
        }
2218
2219
        if ($_success) {
2220
            $this->value = strval(substr($this->string, $_position64, $this->position - $_position64));
2221
        }
2222
2223
        if ($_success) {
2224
            $nr = $this->value;
2225
        }
2226
2227
        if ($_success) {
2228
            $this->value = call_user_func(function () use (&$nr) {
2229
                return new PayerNumberNode($this->currentLineNr, ltrim($nr, '0'));
2230
            });
2231
        }
2232
2233
        $this->cache['PAYER_NR'][$_position] = array(
2234
            'success' => $_success,
2235
            'position' => $this->position,
2236
            'value' => $this->value
2237
        );
2238
2239
        if (!$_success) {
2240
            $this->report($_position, 'PAYER_NR');
2241
        }
2242
2243
        return $_success;
2244
    }
2245
2246 View Code Duplication
    protected function parseA()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2247
    {
2248
        $_position = $this->position;
2249
2250
        if (isset($this->cache['A'][$_position])) {
2251
            $_success = $this->cache['A'][$_position]['success'];
2252
            $this->position = $this->cache['A'][$_position]['position'];
2253
            $this->value = $this->cache['A'][$_position]['value'];
2254
2255
            return $_success;
2256
        }
2257
2258
        if (preg_match('/^[a-zA-Z0-9 -\\/&]$/', substr($this->string, $this->position, 1))) {
2259
            $_success = true;
2260
            $this->value = substr($this->string, $this->position, 1);
2261
            $this->position += 1;
2262
        } else {
2263
            $_success = false;
2264
        }
2265
2266
        $this->cache['A'][$_position] = array(
2267
            'success' => $_success,
2268
            'position' => $this->position,
2269
            'value' => $this->value
2270
        );
2271
2272
        if (!$_success) {
2273
            $this->report($_position, "ALPHA-NUMERIC");
2274
        }
2275
2276
        return $_success;
2277
    }
2278
2279 View Code Duplication
    protected function parseA5()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2280
    {
2281
        $_position = $this->position;
2282
2283
        if (isset($this->cache['A5'][$_position])) {
2284
            $_success = $this->cache['A5'][$_position]['success'];
2285
            $this->position = $this->cache['A5'][$_position]['position'];
2286
            $this->value = $this->cache['A5'][$_position]['value'];
2287
2288
            return $_success;
2289
        }
2290
2291
        $_position66 = $this->position;
2292
2293
        $_value65 = array();
2294
2295
        $_success = $this->parseA();
2296
2297
        if ($_success) {
2298
            $_value65[] = $this->value;
2299
2300
            $_success = $this->parseA();
2301
        }
2302
2303
        if ($_success) {
2304
            $_value65[] = $this->value;
2305
2306
            $_success = $this->parseA();
2307
        }
2308
2309
        if ($_success) {
2310
            $_value65[] = $this->value;
2311
2312
            $_success = $this->parseA();
2313
        }
2314
2315
        if ($_success) {
2316
            $_value65[] = $this->value;
2317
2318
            $_success = $this->parseA();
2319
        }
2320
2321
        if ($_success) {
2322
            $_value65[] = $this->value;
2323
2324
            $this->value = $_value65;
2325
        }
2326
2327
        if ($_success) {
2328
            $this->value = strval(substr($this->string, $_position66, $this->position - $_position66));
2329
        }
2330
2331
        $this->cache['A5'][$_position] = array(
2332
            'success' => $_success,
2333
            'position' => $this->position,
2334
            'value' => $this->value
2335
        );
2336
2337
        if (!$_success) {
2338
            $this->report($_position, 'A5');
2339
        }
2340
2341
        return $_success;
2342
    }
2343
2344 View Code Duplication
    protected function parseA10()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2345
    {
2346
        $_position = $this->position;
2347
2348
        if (isset($this->cache['A10'][$_position])) {
2349
            $_success = $this->cache['A10'][$_position]['success'];
2350
            $this->position = $this->cache['A10'][$_position]['position'];
2351
            $this->value = $this->cache['A10'][$_position]['value'];
2352
2353
            return $_success;
2354
        }
2355
2356
        $_position68 = $this->position;
2357
2358
        $_value67 = array();
2359
2360
        $_success = $this->parseA5();
2361
2362
        if ($_success) {
2363
            $_value67[] = $this->value;
2364
2365
            $_success = $this->parseA5();
2366
        }
2367
2368
        if ($_success) {
2369
            $_value67[] = $this->value;
2370
2371
            $this->value = $_value67;
2372
        }
2373
2374
        if ($_success) {
2375
            $this->value = strval(substr($this->string, $_position68, $this->position - $_position68));
2376
        }
2377
2378
        $this->cache['A10'][$_position] = array(
2379
            'success' => $_success,
2380
            'position' => $this->position,
2381
            'value' => $this->value
2382
        );
2383
2384
        if (!$_success) {
2385
            $this->report($_position, 'A10');
2386
        }
2387
2388
        return $_success;
2389
    }
2390
2391 View Code Duplication
    protected function parseA20()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2392
    {
2393
        $_position = $this->position;
2394
2395
        if (isset($this->cache['A20'][$_position])) {
2396
            $_success = $this->cache['A20'][$_position]['success'];
2397
            $this->position = $this->cache['A20'][$_position]['position'];
2398
            $this->value = $this->cache['A20'][$_position]['value'];
2399
2400
            return $_success;
2401
        }
2402
2403
        $_position70 = $this->position;
2404
2405
        $_value69 = array();
2406
2407
        $_success = $this->parseA10();
2408
2409
        if ($_success) {
2410
            $_value69[] = $this->value;
2411
2412
            $_success = $this->parseA10();
2413
        }
2414
2415
        if ($_success) {
2416
            $_value69[] = $this->value;
2417
2418
            $this->value = $_value69;
2419
        }
2420
2421
        if ($_success) {
2422
            $this->value = strval(substr($this->string, $_position70, $this->position - $_position70));
2423
        }
2424
2425
        $this->cache['A20'][$_position] = array(
2426
            'success' => $_success,
2427
            'position' => $this->position,
2428
            'value' => $this->value
2429
        );
2430
2431
        if (!$_success) {
2432
            $this->report($_position, 'A20');
2433
        }
2434
2435
        return $_success;
2436
    }
2437
2438 View Code Duplication
    protected function parseA40()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2439
    {
2440
        $_position = $this->position;
2441
2442
        if (isset($this->cache['A40'][$_position])) {
2443
            $_success = $this->cache['A40'][$_position]['success'];
2444
            $this->position = $this->cache['A40'][$_position]['position'];
2445
            $this->value = $this->cache['A40'][$_position]['value'];
2446
2447
            return $_success;
2448
        }
2449
2450
        $_position72 = $this->position;
2451
2452
        $_value71 = array();
2453
2454
        $_success = $this->parseA20();
2455
2456
        if ($_success) {
2457
            $_value71[] = $this->value;
2458
2459
            $_success = $this->parseA20();
2460
        }
2461
2462
        if ($_success) {
2463
            $_value71[] = $this->value;
2464
2465
            $this->value = $_value71;
2466
        }
2467
2468
        if ($_success) {
2469
            $this->value = strval(substr($this->string, $_position72, $this->position - $_position72));
2470
        }
2471
2472
        $this->cache['A40'][$_position] = array(
2473
            'success' => $_success,
2474
            'position' => $this->position,
2475
            'value' => $this->value
2476
        );
2477
2478
        if (!$_success) {
2479
            $this->report($_position, 'A40');
2480
        }
2481
2482
        return $_success;
2483
    }
2484
2485 View Code Duplication
    protected function parseN()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2486
    {
2487
        $_position = $this->position;
2488
2489
        if (isset($this->cache['N'][$_position])) {
2490
            $_success = $this->cache['N'][$_position]['success'];
2491
            $this->position = $this->cache['N'][$_position]['position'];
2492
            $this->value = $this->cache['N'][$_position]['value'];
2493
2494
            return $_success;
2495
        }
2496
2497
        if (preg_match('/^[0-9]$/', substr($this->string, $this->position, 1))) {
2498
            $_success = true;
2499
            $this->value = substr($this->string, $this->position, 1);
2500
            $this->position += 1;
2501
        } else {
2502
            $_success = false;
2503
        }
2504
2505
        $this->cache['N'][$_position] = array(
2506
            'success' => $_success,
2507
            'position' => $this->position,
2508
            'value' => $this->value
2509
        );
2510
2511
        if (!$_success) {
2512
            $this->report($_position, "NUMBER");
2513
        }
2514
2515
        return $_success;
2516
    }
2517
2518 View Code Duplication
    protected function parseN5()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2519
    {
2520
        $_position = $this->position;
2521
2522
        if (isset($this->cache['N5'][$_position])) {
2523
            $_success = $this->cache['N5'][$_position]['success'];
2524
            $this->position = $this->cache['N5'][$_position]['position'];
2525
            $this->value = $this->cache['N5'][$_position]['value'];
2526
2527
            return $_success;
2528
        }
2529
2530
        $_position74 = $this->position;
2531
2532
        $_value73 = array();
2533
2534
        $_success = $this->parseN();
2535
2536
        if ($_success) {
2537
            $_value73[] = $this->value;
2538
2539
            $_success = $this->parseN();
2540
        }
2541
2542
        if ($_success) {
2543
            $_value73[] = $this->value;
2544
2545
            $_success = $this->parseN();
2546
        }
2547
2548
        if ($_success) {
2549
            $_value73[] = $this->value;
2550
2551
            $_success = $this->parseN();
2552
        }
2553
2554
        if ($_success) {
2555
            $_value73[] = $this->value;
2556
2557
            $_success = $this->parseN();
2558
        }
2559
2560
        if ($_success) {
2561
            $_value73[] = $this->value;
2562
2563
            $this->value = $_value73;
2564
        }
2565
2566
        if ($_success) {
2567
            $this->value = strval(substr($this->string, $_position74, $this->position - $_position74));
2568
        }
2569
2570
        $this->cache['N5'][$_position] = array(
2571
            'success' => $_success,
2572
            'position' => $this->position,
2573
            'value' => $this->value
2574
        );
2575
2576
        if (!$_success) {
2577
            $this->report($_position, 'N5');
2578
        }
2579
2580
        return $_success;
2581
    }
2582
2583 View Code Duplication
    protected function parseN10()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2584
    {
2585
        $_position = $this->position;
2586
2587
        if (isset($this->cache['N10'][$_position])) {
2588
            $_success = $this->cache['N10'][$_position]['success'];
2589
            $this->position = $this->cache['N10'][$_position]['position'];
2590
            $this->value = $this->cache['N10'][$_position]['value'];
2591
2592
            return $_success;
2593
        }
2594
2595
        $_position76 = $this->position;
2596
2597
        $_value75 = array();
2598
2599
        $_success = $this->parseN5();
2600
2601
        if ($_success) {
2602
            $_value75[] = $this->value;
2603
2604
            $_success = $this->parseN5();
2605
        }
2606
2607
        if ($_success) {
2608
            $_value75[] = $this->value;
2609
2610
            $this->value = $_value75;
2611
        }
2612
2613
        if ($_success) {
2614
            $this->value = strval(substr($this->string, $_position76, $this->position - $_position76));
2615
        }
2616
2617
        $this->cache['N10'][$_position] = array(
2618
            'success' => $_success,
2619
            'position' => $this->position,
2620
            'value' => $this->value
2621
        );
2622
2623
        if (!$_success) {
2624
            $this->report($_position, 'N10');
2625
        }
2626
2627
        return $_success;
2628
    }
2629
2630 View Code Duplication
    protected function parseN20()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2631
    {
2632
        $_position = $this->position;
2633
2634
        if (isset($this->cache['N20'][$_position])) {
2635
            $_success = $this->cache['N20'][$_position]['success'];
2636
            $this->position = $this->cache['N20'][$_position]['position'];
2637
            $this->value = $this->cache['N20'][$_position]['value'];
2638
2639
            return $_success;
2640
        }
2641
2642
        $_position78 = $this->position;
2643
2644
        $_value77 = array();
2645
2646
        $_success = $this->parseN10();
2647
2648
        if ($_success) {
2649
            $_value77[] = $this->value;
2650
2651
            $_success = $this->parseN10();
2652
        }
2653
2654
        if ($_success) {
2655
            $_value77[] = $this->value;
2656
2657
            $this->value = $_value77;
2658
        }
2659
2660
        if ($_success) {
2661
            $this->value = strval(substr($this->string, $_position78, $this->position - $_position78));
2662
        }
2663
2664
        $this->cache['N20'][$_position] = array(
2665
            'success' => $_success,
2666
            'position' => $this->position,
2667
            'value' => $this->value
2668
        );
2669
2670
        if (!$_success) {
2671
            $this->report($_position, 'N20');
2672
        }
2673
2674
        return $_success;
2675
    }
2676
2677 View Code Duplication
    protected function parseS()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2678
    {
2679
        $_position = $this->position;
2680
2681
        if (isset($this->cache['S'][$_position])) {
2682
            $_success = $this->cache['S'][$_position]['success'];
2683
            $this->position = $this->cache['S'][$_position]['position'];
2684
            $this->value = $this->cache['S'][$_position]['value'];
2685
2686
            return $_success;
2687
        }
2688
2689
        if (substr($this->string, $this->position, strlen(' ')) === ' ') {
2690
            $_success = true;
2691
            $this->value = substr($this->string, $this->position, strlen(' '));
2692
            $this->position += strlen(' ');
2693
        } else {
2694
            $_success = false;
2695
2696
            $this->report($this->position, '\' \'');
2697
        }
2698
2699
        $this->cache['S'][$_position] = array(
2700
            'success' => $_success,
2701
            'position' => $this->position,
2702
            'value' => $this->value
2703
        );
2704
2705
        if (!$_success) {
2706
            $this->report($_position, "SPACE");
2707
        }
2708
2709
        return $_success;
2710
    }
2711
2712 View Code Duplication
    protected function parseS5()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2713
    {
2714
        $_position = $this->position;
2715
2716
        if (isset($this->cache['S5'][$_position])) {
2717
            $_success = $this->cache['S5'][$_position]['success'];
2718
            $this->position = $this->cache['S5'][$_position]['position'];
2719
            $this->value = $this->cache['S5'][$_position]['value'];
2720
2721
            return $_success;
2722
        }
2723
2724
        $_position80 = $this->position;
2725
2726
        $_value79 = array();
2727
2728
        $_success = $this->parseS();
2729
2730
        if ($_success) {
2731
            $_value79[] = $this->value;
2732
2733
            $_success = $this->parseS();
2734
        }
2735
2736
        if ($_success) {
2737
            $_value79[] = $this->value;
2738
2739
            $_success = $this->parseS();
2740
        }
2741
2742
        if ($_success) {
2743
            $_value79[] = $this->value;
2744
2745
            $_success = $this->parseS();
2746
        }
2747
2748
        if ($_success) {
2749
            $_value79[] = $this->value;
2750
2751
            $_success = $this->parseS();
2752
        }
2753
2754
        if ($_success) {
2755
            $_value79[] = $this->value;
2756
2757
            $this->value = $_value79;
2758
        }
2759
2760
        if ($_success) {
2761
            $this->value = strval(substr($this->string, $_position80, $this->position - $_position80));
2762
        }
2763
2764
        $this->cache['S5'][$_position] = array(
2765
            'success' => $_success,
2766
            'position' => $this->position,
2767
            'value' => $this->value
2768
        );
2769
2770
        if (!$_success) {
2771
            $this->report($_position, 'S5');
2772
        }
2773
2774
        return $_success;
2775
    }
2776
2777 View Code Duplication
    protected function parseS10()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2778
    {
2779
        $_position = $this->position;
2780
2781
        if (isset($this->cache['S10'][$_position])) {
2782
            $_success = $this->cache['S10'][$_position]['success'];
2783
            $this->position = $this->cache['S10'][$_position]['position'];
2784
            $this->value = $this->cache['S10'][$_position]['value'];
2785
2786
            return $_success;
2787
        }
2788
2789
        $_position82 = $this->position;
2790
2791
        $_value81 = array();
2792
2793
        $_success = $this->parseS5();
2794
2795
        if ($_success) {
2796
            $_value81[] = $this->value;
2797
2798
            $_success = $this->parseS5();
2799
        }
2800
2801
        if ($_success) {
2802
            $_value81[] = $this->value;
2803
2804
            $this->value = $_value81;
2805
        }
2806
2807
        if ($_success) {
2808
            $this->value = strval(substr($this->string, $_position82, $this->position - $_position82));
2809
        }
2810
2811
        $this->cache['S10'][$_position] = array(
2812
            'success' => $_success,
2813
            'position' => $this->position,
2814
            'value' => $this->value
2815
        );
2816
2817
        if (!$_success) {
2818
            $this->report($_position, 'S10');
2819
        }
2820
2821
        return $_success;
2822
    }
2823
2824 View Code Duplication
    protected function parseS20()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2825
    {
2826
        $_position = $this->position;
2827
2828
        if (isset($this->cache['S20'][$_position])) {
2829
            $_success = $this->cache['S20'][$_position]['success'];
2830
            $this->position = $this->cache['S20'][$_position]['position'];
2831
            $this->value = $this->cache['S20'][$_position]['value'];
2832
2833
            return $_success;
2834
        }
2835
2836
        $_position84 = $this->position;
2837
2838
        $_value83 = array();
2839
2840
        $_success = $this->parseS10();
2841
2842
        if ($_success) {
2843
            $_value83[] = $this->value;
2844
2845
            $_success = $this->parseS10();
2846
        }
2847
2848
        if ($_success) {
2849
            $_value83[] = $this->value;
2850
2851
            $this->value = $_value83;
2852
        }
2853
2854
        if ($_success) {
2855
            $this->value = strval(substr($this->string, $_position84, $this->position - $_position84));
2856
        }
2857
2858
        $this->cache['S20'][$_position] = array(
2859
            'success' => $_success,
2860
            'position' => $this->position,
2861
            'value' => $this->value
2862
        );
2863
2864
        if (!$_success) {
2865
            $this->report($_position, 'S20');
2866
        }
2867
2868
        return $_success;
2869
    }
2870
2871
    protected function parseEOL()
2872
    {
2873
        $_position = $this->position;
2874
2875
        if (isset($this->cache['EOL'][$_position])) {
2876
            $_success = $this->cache['EOL'][$_position]['success'];
2877
            $this->position = $this->cache['EOL'][$_position]['position'];
2878
            $this->value = $this->cache['EOL'][$_position]['value'];
2879
2880
            return $_success;
2881
        }
2882
2883
        $_value87 = array();
2884
2885
        $_position85 = $this->position;
2886
        $_cut86 = $this->cut;
2887
2888
        $this->cut = false;
2889
        if (substr($this->string, $this->position, strlen("\r")) === "\r") {
2890
            $_success = true;
2891
            $this->value = substr($this->string, $this->position, strlen("\r"));
2892
            $this->position += strlen("\r");
2893
        } else {
2894
            $_success = false;
2895
2896
            $this->report($this->position, '"\\r"');
2897
        }
2898
2899
        if (!$_success && !$this->cut) {
2900
            $_success = true;
2901
            $this->position = $_position85;
2902
            $this->value = null;
2903
        }
2904
2905
        $this->cut = $_cut86;
2906
2907 View Code Duplication
        if ($_success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2908
            $_value87[] = $this->value;
2909
2910
            if (substr($this->string, $this->position, strlen("\n")) === "\n") {
2911
                $_success = true;
2912
                $this->value = substr($this->string, $this->position, strlen("\n"));
2913
                $this->position += strlen("\n");
2914
            } else {
2915
                $_success = false;
2916
2917
                $this->report($this->position, '"\\n"');
2918
            }
2919
        }
2920
2921
        if ($_success) {
2922
            $_value87[] = $this->value;
2923
2924
            $this->value = $_value87;
2925
        }
2926
2927
        if ($_success) {
2928
            $this->value = call_user_func(function () {
2929
                $this->currentLineNr++;
2930
            });
2931
        }
2932
2933
        $this->cache['EOL'][$_position] = array(
2934
            'success' => $_success,
2935
            'position' => $this->position,
2936
            'value' => $this->value
2937
        );
2938
2939
        if (!$_success) {
2940
            $this->report($_position, "END_OF_LINE");
2941
        }
2942
2943
        return $_success;
2944
    }
2945
2946
    protected function parseEOR()
2947
    {
2948
        $_position = $this->position;
2949
2950
        if (isset($this->cache['EOR'][$_position])) {
2951
            $_success = $this->cache['EOR'][$_position]['success'];
2952
            $this->position = $this->cache['EOR'][$_position]['position'];
2953
            $this->value = $this->cache['EOR'][$_position]['value'];
2954
2955
            return $_success;
2956
        }
2957
2958
        $_value91 = array();
2959
2960
        $_value89 = array();
2961
        $_cut90 = $this->cut;
2962
2963
        while (true) {
2964
            $_position88 = $this->position;
2965
2966
            $this->cut = false;
2967
            $_success = $this->parseA();
2968
2969
            if (!$_success) {
2970
                break;
2971
            }
2972
2973
            $_value89[] = $this->value;
2974
        }
2975
2976
        if (!$this->cut) {
2977
            $_success = true;
2978
            $this->position = $_position88;
0 ignored issues
show
Bug introduced by
The variable $_position88 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2979
            $this->value = $_value89;
2980
        }
2981
2982
        $this->cut = $_cut90;
2983
2984
        if ($_success) {
0 ignored issues
show
Bug introduced by
The variable $_success does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2985
            $_value91[] = $this->value;
2986
2987
            $_success = $this->parseEOL();
2988
        }
2989
2990
        if ($_success) {
2991
            $_value91[] = $this->value;
2992
2993
            $this->value = $_value91;
2994
        }
2995
2996
        $this->cache['EOR'][$_position] = array(
2997
            'success' => $_success,
2998
            'position' => $this->position,
2999
            'value' => $this->value
3000
        );
3001
3002
        if (!$_success) {
3003
            $this->report($_position, "END_OF_RECORD");
3004
        }
3005
3006
        return $_success;
3007
    }
3008
3009
    private function line()
3010
    {
3011
        if (!empty($this->errors)) {
3012
            $positions = array_keys($this->errors);
3013
        } else {
3014
            $positions = array_keys($this->warnings);
3015
        }
3016
3017
        return count(explode("\n", substr($this->string, 0, max($positions))));
3018
    }
3019
3020
    private function rest()
3021
    {
3022
        return '"' . substr($this->string, $this->position) . '"';
3023
    }
3024
3025
    protected function report($position, $expecting)
3026
    {
3027
        if ($this->cut) {
3028
            $this->errors[$position][] = $expecting;
3029
        } else {
3030
            $this->warnings[$position][] = $expecting;
3031
        }
3032
    }
3033
3034
    private function expecting()
3035
    {
3036
        if (!empty($this->errors)) {
3037
            ksort($this->errors);
3038
3039
            return end($this->errors)[0];
3040
        }
3041
3042
        ksort($this->warnings);
3043
3044
        return implode(', ', end($this->warnings));
3045
    }
3046
3047
    public function parse($_string)
3048
    {
3049
        $this->string = $_string;
3050
        $this->position = 0;
3051
        $this->value = null;
3052
        $this->cache = array();
3053
        $this->cut = false;
3054
        $this->errors = array();
3055
        $this->warnings = array();
3056
3057
        $_success = $this->parseFILE();
3058
3059
        if ($_success && $this->position < strlen($this->string)) {
3060
            $_success = false;
3061
3062
            $this->report($this->position, "end of file");
3063
        }
3064
3065
        if (!$_success) {
3066
            throw new \InvalidArgumentException("Syntax error, expecting {$this->expecting()} on line {$this->line()}");
3067
        }
3068
3069
        return $this->value;
3070
    }
3071
}