ConfigfileLexer::yylex2()   C
last analyzed

Complexity

Conditions 12
Paths 56

Size

Total Lines 51
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 37
nc 56
nop 0
dl 0
loc 51
rs 6.9666
c 0
b 0
f 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 Smarty\Lexer;
4
5
/**
6
* Smarty Internal Plugin ConfigfileLexer
7
*
8
* This is the lexer to break the config file source into tokens 
9
* @package Smarty
10
* @subpackage Config
11
* @author Uwe Tews 
12
*/
13
/**
14
* ConfigfileLexer
15
*
16
* This is the config file lexer.
17
* It is generated from the ConfigfileLexer.plex file
18
*
19
* @package Smarty
20
* @subpackage Compiler
21
* @author Uwe Tews
22
*/
23
class ConfigfileLexer
24
{
25
    /**
26
     * Source
27
     *
28
     * @var string
29
     */
30
    public $data;
31
      /**
32
      * Source length
33
      *
34
      * @var int
35
      */
36
     public $dataLength = null;
37
   /**
38
     * byte counter
39
     *
40
     * @var int
41
     */
42
    public $counter;
43
    /**
44
     * token number
45
     *
46
     * @var int
47
     */
48
    public $token;
49
    /**
50
     * token value
51
     *
52
     * @var string
53
     */
54
    public $value;
55
    /**
56
     * current line
57
     *
58
     * @var int
59
     */
60
    public $line;
61
    /**
62
     * state number
63
     *
64
     * @var int
65
     */
66
    public $state = 1;
67
    /**
68
     * Smarty object
0 ignored issues
show
Bug introduced by
The type Smarty\Lexer\Smarty was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
     *
70
     * @var Smarty
71
     */
72
    public $smarty = null;
73
    /**
74
     * compiler object
75
     *
76
     * @var \Smarty\Compiler\Configfile
77
     */
78
    private $compiler = null;
79
    /**
80
     * copy of config_booleanize
81
     *
82
     * @var bool
83
     */
84
    private $configBooleanize = false;
85
    /**
86
     * trace file
87
     *
88
     * @var resource
89
     */
90
    public $yyTraceFILE;
91
    /**
92
     * trace prompt
93
     *
94
     * @var string
95
     */
96
    public $yyTracePrompt;
97
    /**
98
     * state names
99
     *
100
     * @var array
101
     */
102
    public $state_name = array(1 => 'START', 2 => 'VALUE', 3 => 'NAKED_STRING_VALUE', 4 => 'COMMENT', 5 => 'SECTION', 6 => 'TRIPPLE');
103
104
    /**
105
     * storage for assembled token patterns
106
     *
107
     * @var string
108
     */
109
    private $yy_global_pattern1 = null;
110
    private $yy_global_pattern2 = null;
111
    private $yy_global_pattern3 = null;
112
    private $yy_global_pattern4 = null;
113
    private $yy_global_pattern5 = null;
114
    private $yy_global_pattern6 = null;
115
116
    /**
117
     * token names
118
     *
119
     * @var array
120
     */
121
    public $smarty_token_names = array(        // Text for parser error messages
122
    );
123
124
    /**
125
     * constructor
126
     *
127
     * @param   string                             $data template source
128
     * @param \Smarty\Compiler\Configfile $compiler
129
     */
130
    public function __construct($data, \Smarty\Compiler\Configfile $compiler)
131
    {
132
        $this->data = $data . "\n"; //now all lines are \n-terminated
133
        $this->dataLength = strlen($data);
134
        $this->counter = 0;
135
        if (preg_match('/^\xEF\xBB\xBF/', $this->data, $match)) {
136
            $this->counter += strlen($match[0]);
137
        }
138
        $this->line = 1;
139
        $this->compiler = $compiler;
140
        $this->smarty = $compiler->smarty;
0 ignored issues
show
Documentation Bug introduced by
It seems like $compiler->smarty of type Smarty\Smarty is incompatible with the declared type Smarty\Lexer\Smarty of property $smarty.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
141
        $this->configBooleanize = $this->smarty->config_booleanize;
142
    }
143
144
   public function replace ($input) {
145
        return $input;
146
   }
147
148
    public function PrintTrace()
149
    {
150
        $this->yyTraceFILE = fopen('php://output', 'w');
151
        $this->yyTracePrompt = '<br>';
152
    }
153
154
155
156
    private $_yy_state = 1;
157
    private $_yy_stack = array();
158
159
    public function yylex()
160
    {
161
        return $this->{'yylex' . $this->_yy_state}();
162
    }
163
164
    public function yypushstate($state)
165
    {
166
        if ($this->yyTraceFILE) {
167
             fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
168
        }
169
        array_push($this->_yy_stack, $this->_yy_state);
170
        $this->_yy_state = $state;
171
        if ($this->yyTraceFILE) {
172
             fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
173
        }
174
    }
175
176
    public function yypopstate()
177
    {
178
       if ($this->yyTraceFILE) {
179
             fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt,  isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
180
        }
181
       $this->_yy_state = array_pop($this->_yy_stack);
182
        if ($this->yyTraceFILE) {
183
             fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
184
        }
185
186
    }
187
188
    public function yybegin($state)
189
    {
190
       $this->_yy_state = $state;
191
        if ($this->yyTraceFILE) {
192
             fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state);
193
        }
194
    }
195
196
197
198
199
    public function yylex1()
200
    {
201
        if (!isset($this->yy_global_pattern1)) {
202
            $this->yy_global_pattern1 = $this->replace("/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/isS");
203
        }
204
        if (!isset($this->dataLength)) {
205
            $this->dataLength = strlen($this->data);
206
        }
207
        if ($this->counter >=  $this->dataLength) {
208
            return false; // end of input
209
        }
210
        
211
        do {
212
            if (preg_match($this->yy_global_pattern1,$this->data, $yymatches, 0, $this->counter)) {
213
                if (!isset($yymatches[ 0 ][1])) {
214
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
215
                } else {
216
                    $yymatches = array_filter($yymatches);
217
                }
218
                if (empty($yymatches)) {
219
                    throw new Exception('Error: lexing failed because a rule matched' .
0 ignored issues
show
Bug introduced by
The type Smarty\Lexer\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
220
                        ' an empty string.  Input "' . substr($this->data,
221
                        $this->counter, 5) . '... state START');
222
                }
223
                next($yymatches); // skip global match
224
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
225
                $this->value = current($yymatches); // token value
226
                $r = $this->{'yy_r1_' . $this->token}();
227
                if ($r === null) {
228
                    $this->counter += strlen($this->value);
229
                    $this->line += substr_count($this->value, "\n");
230
                    // accept this token
231
                    return true;
232
                } elseif ($r === true) {
233
                    // we have changed state
234
                    // process this token in the new state
235
                    return $this->yylex();
236
                } elseif ($r === false) {
237
                    $this->counter += strlen($this->value);
238
                    $this->line += substr_count($this->value, "\n");
239
                    if ($this->counter >=  $this->dataLength) {
240
                        return false; // end of input
241
                    }
242
                    // skip this token
243
                    continue;
244
                }            } else {
245
                throw new Exception('Unexpected input at line' . $this->line .
246
                    ': ' . $this->data[$this->counter]);
247
            }
248
            break;
249
        } while (true);
250
251
    } // end function
252
253
254
    const START = 1;
255
    public function yy_r1_1()
256
    {
257
258
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_COMMENTSTART;
259
    $this->yypushstate(self::COMMENT);
260
    }
261
    public function yy_r1_2()
262
    {
263
264
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_OPENB;
265
    $this->yypushstate(self::SECTION);
266
    }
267
    public function yy_r1_3()
268
    {
269
270
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_CLOSEB;
271
    }
272
    public function yy_r1_4()
273
    {
274
275
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_EQUAL;
276
    $this->yypushstate(self::VALUE);
277
    }
278
    public function yy_r1_5()
279
    {
280
281
    return false;
282
    }
283
    public function yy_r1_6()
284
    {
285
286
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE;
287
    }
288
    public function yy_r1_7()
289
    {
290
291
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_ID;
292
    }
293
    public function yy_r1_8()
294
    {
295
296
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_OTHER;
297
    }
298
299
300
301
    public function yylex2()
302
    {
303
        if (!isset($this->yy_global_pattern2)) {
304
            $this->yy_global_pattern2 = $this->replace("/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS");
305
        }
306
        if (!isset($this->dataLength)) {
307
            $this->dataLength = strlen($this->data);
308
        }
309
        if ($this->counter >=  $this->dataLength) {
310
            return false; // end of input
311
        }
312
        
313
        do {
314
            if (preg_match($this->yy_global_pattern2,$this->data, $yymatches, 0, $this->counter)) {
315
                if (!isset($yymatches[ 0 ][1])) {
316
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
317
                } else {
318
                    $yymatches = array_filter($yymatches);
319
                }
320
                if (empty($yymatches)) {
321
                    throw new Exception('Error: lexing failed because a rule matched' .
322
                        ' an empty string.  Input "' . substr($this->data,
323
                        $this->counter, 5) . '... state VALUE');
324
                }
325
                next($yymatches); // skip global match
326
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
327
                $this->value = current($yymatches); // token value
328
                $r = $this->{'yy_r2_' . $this->token}();
329
                if ($r === null) {
330
                    $this->counter += strlen($this->value);
331
                    $this->line += substr_count($this->value, "\n");
332
                    // accept this token
333
                    return true;
334
                } elseif ($r === true) {
335
                    // we have changed state
336
                    // process this token in the new state
337
                    return $this->yylex();
338
                } elseif ($r === false) {
339
                    $this->counter += strlen($this->value);
340
                    $this->line += substr_count($this->value, "\n");
341
                    if ($this->counter >=  $this->dataLength) {
342
                        return false; // end of input
343
                    }
344
                    // skip this token
345
                    continue;
346
                }            } else {
347
                throw new Exception('Unexpected input at line' . $this->line .
348
                    ': ' . $this->data[$this->counter]);
349
            }
350
            break;
351
        } while (true);
352
353
    } // end function
354
355
356
    const VALUE = 2;
357
    public function yy_r2_1()
358
    {
359
360
    return false;
361
    }
362
    public function yy_r2_2()
363
    {
364
365
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_FLOAT;
366
    $this->yypopstate();
367
    }
368
    public function yy_r2_3()
369
    {
370
371
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_INT;
372
    $this->yypopstate();
373
    }
374
    public function yy_r2_4()
375
    {
376
377
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES;
378
    $this->yypushstate(self::TRIPPLE);
379
    }
380
    public function yy_r2_5()
381
    {
382
383
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_SINGLE_QUOTED_STRING;
384
    $this->yypopstate();
385
    }
386
    public function yy_r2_6()
387
    {
388
389
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOUBLE_QUOTED_STRING;
390
    $this->yypopstate();
391
    }
392
    public function yy_r2_7()
393
    {
394
395
    if (!$this->configBooleanize || !in_array(strtolower($this->value), array('true', 'false', 'on', 'off', 'yes', 'no')) ) {
396
        $this->yypopstate();
397
        $this->yypushstate(self::NAKED_STRING_VALUE);
398
        return true; //reprocess in new state
399
    } else {
400
        $this->token = \Smarty\Parser\ConfigfileParser::TPC_BOOL;
401
        $this->yypopstate();
402
    }
403
    }
404
    public function yy_r2_8()
405
    {
406
407
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING;
408
    $this->yypopstate();
409
    }
410
    public function yy_r2_9()
411
    {
412
413
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING;
414
    $this->value = '';
415
    $this->yypopstate();
416
    }
417
418
419
420
    public function yylex3()
421
    {
422
        if (!isset($this->yy_global_pattern3)) {
423
            $this->yy_global_pattern3 = $this->replace("/\G([^\n]+?(?=[ \t\r]*\n))/isS");
424
        }
425
        if (!isset($this->dataLength)) {
426
            $this->dataLength = strlen($this->data);
427
        }
428
        if ($this->counter >=  $this->dataLength) {
429
            return false; // end of input
430
        }
431
        
432
        do {
433
            if (preg_match($this->yy_global_pattern3,$this->data, $yymatches, 0, $this->counter)) {
434
                if (!isset($yymatches[ 0 ][1])) {
435
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
436
                } else {
437
                    $yymatches = array_filter($yymatches);
438
                }
439
                if (empty($yymatches)) {
440
                    throw new Exception('Error: lexing failed because a rule matched' .
441
                        ' an empty string.  Input "' . substr($this->data,
442
                        $this->counter, 5) . '... state NAKED_STRING_VALUE');
443
                }
444
                next($yymatches); // skip global match
445
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
446
                $this->value = current($yymatches); // token value
447
                $r = $this->{'yy_r3_' . $this->token}();
448
                if ($r === null) {
449
                    $this->counter += strlen($this->value);
450
                    $this->line += substr_count($this->value, "\n");
451
                    // accept this token
452
                    return true;
453
                } elseif ($r === true) {
454
                    // we have changed state
455
                    // process this token in the new state
456
                    return $this->yylex();
457
                } elseif ($r === false) {
458
                    $this->counter += strlen($this->value);
459
                    $this->line += substr_count($this->value, "\n");
460
                    if ($this->counter >=  $this->dataLength) {
461
                        return false; // end of input
462
                    }
463
                    // skip this token
464
                    continue;
465
                }            } else {
466
                throw new Exception('Unexpected input at line' . $this->line .
467
                    ': ' . $this->data[$this->counter]);
468
            }
469
            break;
470
        } while (true);
471
472
    } // end function
473
474
475
    const NAKED_STRING_VALUE = 3;
476
    public function yy_r3_1()
477
    {
478
479
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING;
480
    $this->yypopstate();
481
    }
482
483
484
485
    public function yylex4()
486
    {
487
        if (!isset($this->yy_global_pattern4)) {
488
            $this->yy_global_pattern4 = $this->replace("/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/isS");
489
        }
490
        if (!isset($this->dataLength)) {
491
            $this->dataLength = strlen($this->data);
492
        }
493
        if ($this->counter >=  $this->dataLength) {
494
            return false; // end of input
495
        }
496
        
497
        do {
498
            if (preg_match($this->yy_global_pattern4,$this->data, $yymatches, 0, $this->counter)) {
499
                if (!isset($yymatches[ 0 ][1])) {
500
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
501
                } else {
502
                    $yymatches = array_filter($yymatches);
503
                }
504
                if (empty($yymatches)) {
505
                    throw new Exception('Error: lexing failed because a rule matched' .
506
                        ' an empty string.  Input "' . substr($this->data,
507
                        $this->counter, 5) . '... state COMMENT');
508
                }
509
                next($yymatches); // skip global match
510
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
511
                $this->value = current($yymatches); // token value
512
                $r = $this->{'yy_r4_' . $this->token}();
513
                if ($r === null) {
514
                    $this->counter += strlen($this->value);
515
                    $this->line += substr_count($this->value, "\n");
516
                    // accept this token
517
                    return true;
518
                } elseif ($r === true) {
519
                    // we have changed state
520
                    // process this token in the new state
521
                    return $this->yylex();
522
                } elseif ($r === false) {
523
                    $this->counter += strlen($this->value);
524
                    $this->line += substr_count($this->value, "\n");
525
                    if ($this->counter >=  $this->dataLength) {
526
                        return false; // end of input
527
                    }
528
                    // skip this token
529
                    continue;
530
                }            } else {
531
                throw new Exception('Unexpected input at line' . $this->line .
532
                    ': ' . $this->data[$this->counter]);
533
            }
534
            break;
535
        } while (true);
536
537
    } // end function
538
539
540
    const COMMENT = 4;
541
    public function yy_r4_1()
542
    {
543
544
    return false;
545
    }
546
    public function yy_r4_2()
547
    {
548
549
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NAKED_STRING;
550
    }
551
    public function yy_r4_3()
552
    {
553
554
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_NEWLINE;
555
    $this->yypopstate();
556
    }
557
558
559
560
    public function yylex5()
561
    {
562
        if (!isset($this->yy_global_pattern5)) {
563
            $this->yy_global_pattern5 = $this->replace("/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/isS");
564
        }
565
        if (!isset($this->dataLength)) {
566
            $this->dataLength = strlen($this->data);
567
        }
568
        if ($this->counter >=  $this->dataLength) {
569
            return false; // end of input
570
        }
571
        
572
        do {
573
            if (preg_match($this->yy_global_pattern5,$this->data, $yymatches, 0, $this->counter)) {
574
                if (!isset($yymatches[ 0 ][1])) {
575
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
576
                } else {
577
                    $yymatches = array_filter($yymatches);
578
                }
579
                if (empty($yymatches)) {
580
                    throw new Exception('Error: lexing failed because a rule matched' .
581
                        ' an empty string.  Input "' . substr($this->data,
582
                        $this->counter, 5) . '... state SECTION');
583
                }
584
                next($yymatches); // skip global match
585
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
586
                $this->value = current($yymatches); // token value
587
                $r = $this->{'yy_r5_' . $this->token}();
588
                if ($r === null) {
589
                    $this->counter += strlen($this->value);
590
                    $this->line += substr_count($this->value, "\n");
591
                    // accept this token
592
                    return true;
593
                } elseif ($r === true) {
594
                    // we have changed state
595
                    // process this token in the new state
596
                    return $this->yylex();
597
                } elseif ($r === false) {
598
                    $this->counter += strlen($this->value);
599
                    $this->line += substr_count($this->value, "\n");
600
                    if ($this->counter >=  $this->dataLength) {
601
                        return false; // end of input
602
                    }
603
                    // skip this token
604
                    continue;
605
                }            } else {
606
                throw new Exception('Unexpected input at line' . $this->line .
607
                    ': ' . $this->data[$this->counter]);
608
            }
609
            break;
610
        } while (true);
611
612
    } // end function
613
614
615
    const SECTION = 5;
616
    public function yy_r5_1()
617
    {
618
619
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_DOT;
620
    }
621
    public function yy_r5_2()
622
    {
623
624
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_SECTION;
625
    $this->yypopstate();
626
    }
627
628
629
    public function yylex6()
630
    {
631
        if (!isset($this->yy_global_pattern6)) {
632
            $this->yy_global_pattern6 = $this->replace("/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/isS");
633
        }
634
        if (!isset($this->dataLength)) {
635
            $this->dataLength = strlen($this->data);
636
        }
637
        if ($this->counter >=  $this->dataLength) {
638
            return false; // end of input
639
        }
640
        
641
        do {
642
            if (preg_match($this->yy_global_pattern6,$this->data, $yymatches, 0, $this->counter)) {
643
                if (!isset($yymatches[ 0 ][1])) {
644
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
645
                } else {
646
                    $yymatches = array_filter($yymatches);
647
                }
648
                if (empty($yymatches)) {
649
                    throw new Exception('Error: lexing failed because a rule matched' .
650
                        ' an empty string.  Input "' . substr($this->data,
651
                        $this->counter, 5) . '... state TRIPPLE');
652
                }
653
                next($yymatches); // skip global match
654
                $this->token = key($yymatches); // token number
0 ignored issues
show
Documentation Bug introduced by
It seems like key($yymatches) can also be of type string. However, the property $token is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
655
                $this->value = current($yymatches); // token value
656
                $r = $this->{'yy_r6_' . $this->token}();
657
                if ($r === null) {
658
                    $this->counter += strlen($this->value);
659
                    $this->line += substr_count($this->value, "\n");
660
                    // accept this token
661
                    return true;
662
                } elseif ($r === true) {
663
                    // we have changed state
664
                    // process this token in the new state
665
                    return $this->yylex();
666
                } elseif ($r === false) {
667
                    $this->counter += strlen($this->value);
668
                    $this->line += substr_count($this->value, "\n");
669
                    if ($this->counter >=  $this->dataLength) {
670
                        return false; // end of input
671
                    }
672
                    // skip this token
673
                    continue;
674
                }            } else {
675
                throw new Exception('Unexpected input at line' . $this->line .
676
                    ': ' . $this->data[$this->counter]);
677
            }
678
            break;
679
        } while (true);
680
681
    } // end function
682
683
684
    const TRIPPLE = 6;
685
    public function yy_r6_1()
686
    {
687
688
    $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_QUOTES_END;
689
    $this->yypopstate();
690
    $this->yypushstate(self::START);
691
    }
692
    public function yy_r6_2()
693
    {
694
695
  $to = strlen($this->data);
696
  preg_match("/\"\"\"[ \t\r]*[\n#;]/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
697
  if (isset($match[0][1])) {
698
    $to = $match[0][1];
699
  } else {
700
    $this->compiler->trigger_config_file_error ('missing or misspelled literal closing tag');
701
  }  
702
  $this->value = substr($this->data,$this->counter,$to-$this->counter);
703
  $this->token = \Smarty\Parser\ConfigfileParser::TPC_TRIPPLE_TEXT;
704
    }
705
706
707
}
708