Smarty_Internal_Templatelexer::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
 * This file is part of Smarty.
4
 *
5
 * (c) 2015 Uwe Tews
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * Smarty_Internal_Templatelexer
13
 * This is the template file lexer.
14
 * It is generated from the smarty_internal_templatelexer.plex file
15
 *
16
 *
17
 * @author Uwe Tews <[email protected]>
18
 */
19
class Smarty_Internal_Templatelexer
20
{
21
    /**
22
     * Source
23
     *
24
     * @var string
25
     */
26
    public $data;
27
28
    /**
29
     * Source length
30
     *
31
     * @var int
32
     */
33
    public $dataLength = null;
34
35
    /**
36
     * byte counter
37
     *
38
     * @var int
39
     */
40
    public $counter;
41
42
    /**
43
     * token number
44
     *
45
     * @var int
46
     */
47
    public $token;
48
49
    /**
50
     * token value
51
     *
52
     * @var string
53
     */
54
    public $value;
55
56
    /**
57
     * current line
58
     *
59
     * @var int
60
     */
61
    public $line;
62
63
    /**
64
     * tag start line
65
     *
66
     * @var
67
     */
68
    public $taglineno;
69
70
    /**
71
     * php code type
72
     *
73
     * @var string
74
     */
75
    public $phpType = '';
76
77
   /**
78
     * state number
79
     *
80
     * @var int
81
     */
82
    public $state = 1;
83
84
    /**
85
     * Smarty object
86
     *
87
     * @var Smarty
88
     */
89
    public $smarty = null;
90
91
    /**
92
     * compiler object
93
     *
94
     * @var Smarty_Internal_TemplateCompilerBase
95
     */
96
    public $compiler = null;
97
98
    /**
99
     * trace file
100
     *
101
     * @var resource
102
     */
103
    public $yyTraceFILE;
104
105
    /**
106
     * trace prompt
107
     *
108
     * @var string
109
     */
110
    public $yyTracePrompt;
111
112
    /**
113
     * XML flag true while processing xml
114
     *
115
     * @var bool
116
     */
117
    public $is_xml = false;
118
119
    /**
120
     * state names
121
     *
122
     * @var array
123
     */
124
    public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',);
125
126
    /**
127
     * token names
128
     *
129
     * @var array
130
     */
131
    public $smarty_token_names = array(        // Text for parser error messages
132
                                               'NOT'         => '(!,not)',
133
                                               'OPENP'       => '(',
134
                                               'CLOSEP'      => ')',
135
                                               'OPENB'       => '[',
136
                                               'CLOSEB'      => ']',
137
                                               'PTR'         => '->',
138
                                               'APTR'        => '=>',
139
                                               'EQUAL'       => '=',
140
                                               'NUMBER'      => 'number',
141
                                               'UNIMATH'     => '+" , "-',
142
                                               'MATH'        => '*" , "/" , "%',
143
                                               'INCDEC'      => '++" , "--',
144
                                               'SPACE'       => ' ',
145
                                               'DOLLAR'      => '$',
146
                                               'SEMICOLON'   => ';',
147
                                               'COLON'       => ':',
148
                                               'DOUBLECOLON' => '::',
149
                                               'AT'          => '@',
150
                                               'HATCH'       => '#',
151
                                               'QUOTE'       => '"',
152
                                               'BACKTICK'    => '`',
153
                                               'VERT'        => '"|" modifier',
154
                                               'DOT'         => '.',
155
                                               'COMMA'       => '","',
156
                                               'QMARK'       => '"?"',
157
                                               'ID'          => 'id, name',
158
                                               'TEXT'        => 'text',
159
                                               'LDELSLASH'   => '{/..} closing tag',
160
                                               'LDEL'        => '{...} Smarty tag',
161
                                               'COMMENT'     => 'comment',
162
                                               'AS'          => 'as',
163
                                               'TO'          => 'to',
164
                                               'PHP'         => '"<?php", "<%", "{php}" tag',
165
                                               'LOGOP'       => '"<", "==" ... logical operator',
166
                                               'TLOGOP'      => '"lt", "eq" ... logical operator; "is div by" ... if condition',
167
                                               'SCOND'       => '"is even" ... if condition',
168
    );
169
170
    /**
171
     * literal tag nesting level
172
     *
173
     * @var int
174
     */
175
    private $literal_cnt = 0;
176
177
    /**
178
     * preg token pattern for state TEXT
179
     *
180
     * @var string
181
     */
182
    private $yy_global_pattern1 = null;
183
184
    /**
185
     * preg token pattern for state TAG
186
     *
187
     * @var string
188
     */
189
    private $yy_global_pattern2 = null;
190
191
    /**
192
     * preg token pattern for state TAGBODY
193
     *
194
     * @var string
195
     */
196
    private $yy_global_pattern3 = null;
197
198
    /**
199
     * preg token pattern for state LITERAL
200
     *
201
     * @var string
202
     */
203
    private $yy_global_pattern4 = null;
204
205
    /**
206
     * preg token pattern for state DOUBLEQUOTEDSTRING
207
     *
208
     * @var null
209
     */
210
    private $yy_global_pattern5 = null;
211
212
    /**
213
     * preg token pattern for text
214
     *
215
     * @var null
216
     */
217
    private $yy_global_text = null;
218
219
    /**
220
     * preg token pattern for literal
221
     *
222
     * @var null
223
     */
224
    private $yy_global_literal = null;
225
226
    /**
227
     * constructor
228
     *
229
     * @param   string                             $source template source
230
     * @param Smarty_Internal_TemplateCompilerBase $compiler
231
     */
232
    public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler)
233
    {
234
        $this->data = $source;
235
        $this->dataLength = strlen($this->data);
236
        $this->counter = 0;
237
        if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) {
238
            $this->counter += strlen($match[0]);
239
        }
240
        $this->line = 1;
241
        $this->smarty = $compiler->template->smarty;
242
        $this->compiler = $compiler;
243
        $this->compiler->initDelimiterPreg();
244
        $this->smarty_token_names['LDEL'] = $this->smarty->getLeftDelimiter();
245
        $this->smarty_token_names['RDEL'] = $this->smarty->getRightDelimiter();
246
    }
247
248
    /**
249
     * open lexer/parser trace file
250
     *
251
     */
252
    public function PrintTrace()
253
    {
254
        $this->yyTraceFILE = fopen('php://output', 'w');
255
        $this->yyTracePrompt = '<br>';
256
    }
257
258
   /**
259
     * replace placeholders with runtime preg  code
260
     *
261
     * @param string $preg
262
     *
263
     * @return string
264
     */
265
   public function replace($preg)
266
   {
267
        return $this->compiler->replaceDelimiter($preg);
268
   }
269
270
    /**
271
     * check if current value is an autoliteral left delimiter
272
     *
273
     * @return bool
274
     */
275
    public function isAutoLiteral()
276
    {
277
        return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ?
278
            strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false;
279
    }
280
281
     
282
    private $_yy_state = 1;
283
    private $_yy_stack = array();
284
285
    public function yylex()
286
    {
287
        return $this->{'yylex' . $this->_yy_state}();
288
    }
289
290
    public function yypushstate($state)
291
    {
292
        if ($this->yyTraceFILE) {
293
             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);
294
        }
295
        array_push($this->_yy_stack, $this->_yy_state);
296
        $this->_yy_state = $state;
297
        if ($this->yyTraceFILE) {
298
             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);
299
        }
300
    }
301
302
    public function yypopstate()
303
    {
304
       if ($this->yyTraceFILE) {
305
             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);
306
        }
307
       $this->_yy_state = array_pop($this->_yy_stack);
308
        if ($this->yyTraceFILE) {
309
             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);
310
        }
311
312
    }
313
314
    public function yybegin($state)
315
    {
316
       $this->_yy_state = $state;
317
        if ($this->yyTraceFILE) {
318
             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);
319
        }
320
    }
321
322
323
     
324
    public function yylex1()
325
    {
326
        if (!isset($this->yy_global_pattern1)) {
327
            $this->yy_global_pattern1 = $this->replace("/\G([{][}])|\G((SMARTYldel)SMARTYal[*])|\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\S\s])/isS");
328
        }
329
        if (!isset($this->dataLength)) {
330
            $this->dataLength = strlen($this->data);
331
        }
332
        if ($this->counter >=  $this->dataLength) {
333
            return false; // end of input
334
        }
335
        
336
        do {
337
            if (preg_match($this->yy_global_pattern1,$this->data, $yymatches, 0, $this->counter)) {
338
                if (!isset($yymatches[ 0 ][1])) {
339
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
340
                } else {
341
                    $yymatches = array_filter($yymatches);
342
                }
343
                if (empty($yymatches)) {
344
                    throw new Exception('Error: lexing failed because a rule matched' .
345
                        ' an empty string.  Input "' . substr($this->data,
346
                        $this->counter, 5) . '... state TEXT');
347
                }
348
                next($yymatches); // skip global match
349
                $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...
350
                $this->value = current($yymatches); // token value
351
                $r = $this->{'yy_r1_' . $this->token}();
352
                if ($r === null) {
353
                    $this->counter += strlen($this->value);
354
                    $this->line += substr_count($this->value, "\n");
355
                    // accept this token
356
                    return true;
357
                } elseif ($r === true) {
358
                    // we have changed state
359
                    // process this token in the new state
360
                    return $this->yylex();
361
                } elseif ($r === false) {
362
                    $this->counter += strlen($this->value);
363
                    $this->line += substr_count($this->value, "\n");
364
                    if ($this->counter >=  $this->dataLength) {
365
                        return false; // end of input
366
                    }
367
                    // skip this token
368
                    continue;
369
                }            } else {
370
                throw new Exception('Unexpected input at line' . $this->line .
371
                    ': ' . $this->data[$this->counter]);
372
            }
373
            break;
374
        } while (true);
375
376
    } // end function
377
378
379
    const TEXT = 1;
380
    public function yy_r1_1()
381
    {
382
383
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
384
         }
385
    public function yy_r1_2()
386
    {
387
388
       $to = $this->dataLength;
389
       preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
390
        if (isset($match[0][1])) {
391
            $to = $match[0][1] + strlen($match[0][0]);
392
        } else {
393
            $this->compiler->trigger_template_error ("missing or misspelled comment closing tag '{$this->smarty->getRightDelimiter()}'");
394
        }
395
        $this->value = substr($this->data,$this->counter,$to-$this->counter);
396
        return false;
397
         }
398
    public function yy_r1_4()
399
    {
400
401
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
402
         }
403
    public function yy_r1_6()
404
    {
405
406
        $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
407
        $this->yypushstate(self::LITERAL);
408
         }
409
    public function yy_r1_8()
410
    {
411
412
        $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
413
        $this->yypushstate(self::LITERAL);
414
         }
415
    public function yy_r1_10()
416
    {
417
418
        $this->yypushstate(self::TAG);
419
        return true;
420
         }
421
    public function yy_r1_12()
422
    {
423
424
       if (!isset($this->yy_global_text)) {
425
           $this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal/isS');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->replace('/(SMARTYldel)SMARTYal/isS') of type string is incompatible with the declared type null of property $yy_global_text.

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...
426
       }
427
       $to = $this->dataLength;
428
       preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
429
       if (isset($match[0][1])) {
430
         $to = $match[0][1];
431
       }
432
       $this->value = substr($this->data,$this->counter,$to-$this->counter);
433
       $this->token = Smarty_Internal_Templateparser::TP_TEXT;
434
         }
435
436
     
437
    public function yylex2()
438
    {
439
        if (!isset($this->yy_global_pattern2)) {
440
            $this->yy_global_pattern2 = $this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYalmake_nocache\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$]smarty\\.block\\.(child|parent)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/][0-9]*[a-zA-Z_]\\w*\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS");
441
        }
442
        if (!isset($this->dataLength)) {
443
            $this->dataLength = strlen($this->data);
444
        }
445
        if ($this->counter >=  $this->dataLength) {
446
            return false; // end of input
447
        }
448
        
449
        do {
450
            if (preg_match($this->yy_global_pattern2,$this->data, $yymatches, 0, $this->counter)) {
451
                if (!isset($yymatches[ 0 ][1])) {
452
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
453
                } else {
454
                    $yymatches = array_filter($yymatches);
455
                }
456
                if (empty($yymatches)) {
457
                    throw new Exception('Error: lexing failed because a rule matched' .
458
                        ' an empty string.  Input "' . substr($this->data,
459
                        $this->counter, 5) . '... state TAG');
460
                }
461
                next($yymatches); // skip global match
462
                $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...
463
                $this->value = current($yymatches); // token value
464
                $r = $this->{'yy_r2_' . $this->token}();
465
                if ($r === null) {
466
                    $this->counter += strlen($this->value);
467
                    $this->line += substr_count($this->value, "\n");
468
                    // accept this token
469
                    return true;
470
                } elseif ($r === true) {
471
                    // we have changed state
472
                    // process this token in the new state
473
                    return $this->yylex();
474
                } elseif ($r === false) {
475
                    $this->counter += strlen($this->value);
476
                    $this->line += substr_count($this->value, "\n");
477
                    if ($this->counter >=  $this->dataLength) {
478
                        return false; // end of input
479
                    }
480
                    // skip this token
481
                    continue;
482
                }            } else {
483
                throw new Exception('Unexpected input at line' . $this->line .
484
                    ': ' . $this->data[$this->counter]);
485
            }
486
            break;
487
        } while (true);
488
489
    } // end function
490
491
492
    const TAG = 2;
493
    public function yy_r2_1()
494
    {
495
496
        $this->token = Smarty_Internal_Templateparser::TP_LDELIF;
497
        $this->yybegin(self::TAGBODY);
498
        $this->taglineno = $this->line;
499
         }
500
    public function yy_r2_4()
501
    {
502
503
        $this->token = Smarty_Internal_Templateparser::TP_LDELFOR;
504
        $this->yybegin(self::TAGBODY);
505
        $this->taglineno = $this->line;
506
         }
507
    public function yy_r2_6()
508
    {
509
510
        $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH;
511
        $this->yybegin(self::TAGBODY);
512
        $this->taglineno = $this->line;
513
         }
514
    public function yy_r2_8()
515
    {
516
517
        $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER;
518
        $this->yybegin(self::TAGBODY);
519
        $this->taglineno = $this->line;
520
         }
521
    public function yy_r2_10()
522
    {
523
524
        $this->token = Smarty_Internal_Templateparser::TP_LDELMAKENOCACHE;
525
        $this->yybegin(self::TAGBODY);
526
        $this->taglineno = $this->line;
527
         }
528
    public function yy_r2_12()
529
    {
530
531
        $this->yypopstate();
532
        $this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG;
533
        $this->taglineno = $this->line;
534
         }
535
    public function yy_r2_15()
536
    {
537
538
         $this->yypopstate();
539
         $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT;
540
         $this->taglineno = $this->line;
541
         }
542
    public function yy_r2_18()
543
    {
544
545
        $this->yypopstate();
546
        $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG;
547
        $this->taglineno = $this->line;
548
         }
549
    public function yy_r2_20()
550
    {
551
552
        if ($this->_yy_stack[count($this->_yy_stack)-1] === self::TEXT) {
553
            $this->yypopstate();
554
            $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT;
555
            $this->taglineno = $this->line;
556
        } else {
557
            $this->value = $this->smarty->getLeftDelimiter();
558
            $this->token = Smarty_Internal_Templateparser::TP_LDEL;
559
            $this->yybegin(self::TAGBODY);
560
            $this->taglineno = $this->line;
561
        }
562
         }
563
    public function yy_r2_23()
564
    {
565
566
        $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
567
        $this->yybegin(self::TAGBODY);
568
        $this->taglineno = $this->line;
569
         }
570
    public function yy_r2_25()
571
    {
572
573
        $this->token = Smarty_Internal_Templateparser::TP_LDEL;
574
        $this->yybegin(self::TAGBODY);
575
        $this->taglineno = $this->line;
576
         }
577
578
     
579
    public function yylex3()
580
    {
581
        if (!isset($this->yy_global_pattern3)) {
582
            $this->yy_global_pattern3 = $this->replace("/\G(\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even|div)\\s+by\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G([!]\\s*|not\\s+)|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G(array\\s*[(]\\s*)|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|][@]?)|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS");
583
        }
584
        if (!isset($this->dataLength)) {
585
            $this->dataLength = strlen($this->data);
586
        }
587
        if ($this->counter >=  $this->dataLength) {
588
            return false; // end of input
589
        }
590
        
591
        do {
592
            if (preg_match($this->yy_global_pattern3,$this->data, $yymatches, 0, $this->counter)) {
593
                if (!isset($yymatches[ 0 ][1])) {
594
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
595
                } else {
596
                    $yymatches = array_filter($yymatches);
597
                }
598
                if (empty($yymatches)) {
599
                    throw new Exception('Error: lexing failed because a rule matched' .
600
                        ' an empty string.  Input "' . substr($this->data,
601
                        $this->counter, 5) . '... state TAGBODY');
602
                }
603
                next($yymatches); // skip global match
604
                $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...
605
                $this->value = current($yymatches); // token value
606
                $r = $this->{'yy_r3_' . $this->token}();
607
                if ($r === null) {
608
                    $this->counter += strlen($this->value);
609
                    $this->line += substr_count($this->value, "\n");
610
                    // accept this token
611
                    return true;
612
                } elseif ($r === true) {
613
                    // we have changed state
614
                    // process this token in the new state
615
                    return $this->yylex();
616
                } elseif ($r === false) {
617
                    $this->counter += strlen($this->value);
618
                    $this->line += substr_count($this->value, "\n");
619
                    if ($this->counter >=  $this->dataLength) {
620
                        return false; // end of input
621
                    }
622
                    // skip this token
623
                    continue;
624
                }            } else {
625
                throw new Exception('Unexpected input at line' . $this->line .
626
                    ': ' . $this->data[$this->counter]);
627
            }
628
            break;
629
        } while (true);
630
631
    } // end function
632
633
634
    const TAGBODY = 3;
635
    public function yy_r3_1()
636
    {
637
638
        $this->token = Smarty_Internal_Templateparser::TP_RDEL;
639
        $this->yypopstate();
640
         }
641
    public function yy_r3_2()
642
    {
643
644
        $this->yypushstate(self::TAG);
645
        return true;
646
         }
647
    public function yy_r3_4()
648
    {
649
650
        $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
651
        $this->yypushstate(self::DOUBLEQUOTEDSTRING);
652
        $this->compiler->enterDoubleQuote();
653
         }
654
    public function yy_r3_5()
655
    {
656
657
        $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING;
658
         }
659
    public function yy_r3_6()
660
    {
661
662
        $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
663
         }
664
    public function yy_r3_7()
665
    {
666
667
        $this->token = Smarty_Internal_Templateparser::TP_DOLLAR;
668
         }
669
    public function yy_r3_8()
670
    {
671
672
        $this->token = Smarty_Internal_Templateparser::TP_ISIN;
673
         }
674
    public function yy_r3_9()
675
    {
676
677
        $this->token = Smarty_Internal_Templateparser::TP_AS;
678
         }
679
    public function yy_r3_10()
680
    {
681
682
        $this->token = Smarty_Internal_Templateparser::TP_TO;
683
         }
684
    public function yy_r3_11()
685
    {
686
687
        $this->token = Smarty_Internal_Templateparser::TP_STEP;
688
         }
689
    public function yy_r3_12()
690
    {
691
692
        $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF;
693
         }
694
    public function yy_r3_13()
695
    {
696
697
        $this->token = Smarty_Internal_Templateparser::TP_LOGOP;
698
         }
699
    public function yy_r3_15()
700
    {
701
702
        $this->token = Smarty_Internal_Templateparser::TP_SLOGOP;
703
         }
704
    public function yy_r3_17()
705
    {
706
707
        $this->token = Smarty_Internal_Templateparser::TP_TLOGOP;
708
         }
709
    public function yy_r3_20()
710
    {
711
712
        $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND;
713
         }
714
    public function yy_r3_23()
715
    {
716
717
        $this->token = Smarty_Internal_Templateparser::TP_NOT;
718
         }
719
    public function yy_r3_24()
720
    {
721
722
        $this->token = Smarty_Internal_Templateparser::TP_TYPECAST;
723
         }
724
    public function yy_r3_28()
725
    {
726
727
        $this->token = Smarty_Internal_Templateparser::TP_OPENP;
728
         }
729
    public function yy_r3_29()
730
    {
731
732
        $this->token = Smarty_Internal_Templateparser::TP_CLOSEP;
733
         }
734
    public function yy_r3_30()
735
    {
736
737
        $this->token = Smarty_Internal_Templateparser::TP_OPENB;
738
         }
739
    public function yy_r3_31()
740
    {
741
742
        $this->token = Smarty_Internal_Templateparser::TP_CLOSEB;
743
         }
744
    public function yy_r3_32()
745
    {
746
747
        $this->token = Smarty_Internal_Templateparser::TP_PTR;
748
         }
749
    public function yy_r3_33()
750
    {
751
752
        $this->token = Smarty_Internal_Templateparser::TP_APTR;
753
         }
754
    public function yy_r3_34()
755
    {
756
757
        $this->token = Smarty_Internal_Templateparser::TP_EQUAL;
758
         }
759
    public function yy_r3_35()
760
    {
761
762
        $this->token = Smarty_Internal_Templateparser::TP_INCDEC;
763
         }
764
    public function yy_r3_37()
765
    {
766
767
        $this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
768
         }
769
    public function yy_r3_39()
770
    {
771
772
        $this->token = Smarty_Internal_Templateparser::TP_MATH;
773
         }
774
    public function yy_r3_41()
775
    {
776
777
        $this->token = Smarty_Internal_Templateparser::TP_AT;
778
         }
779
    public function yy_r3_42()
780
    {
781
782
        $this->token = Smarty_Internal_Templateparser::TP_ARRAYOPEN;
783
         }
784
    public function yy_r3_43()
785
    {
786
787
        $this->token = Smarty_Internal_Templateparser::TP_HATCH;
788
         }
789
    public function yy_r3_44()
790
    {
791
792
        // resolve conflicts with shorttag and right_delimiter starting with '='
793
        if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter()) {
794
            preg_match('/\s+/',$this->value,$match);
795
            $this->value = $match[0];
796
            $this->token = Smarty_Internal_Templateparser::TP_SPACE;
797
        } else {
798
            $this->token = Smarty_Internal_Templateparser::TP_ATTR;
799
        }
800
         }
801
    public function yy_r3_45()
802
    {
803
804
        $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE;
805
         }
806
    public function yy_r3_48()
807
    {
808
809
        $this->token = Smarty_Internal_Templateparser::TP_ID;
810
         }
811
    public function yy_r3_49()
812
    {
813
814
        $this->token = Smarty_Internal_Templateparser::TP_INTEGER;
815
         }
816
    public function yy_r3_50()
817
    {
818
819
        $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
820
        $this->yypopstate();
821
         }
822
    public function yy_r3_51()
823
    {
824
825
        $this->token = Smarty_Internal_Templateparser::TP_VERT;
826
         }
827
    public function yy_r3_52()
828
    {
829
830
        $this->token = Smarty_Internal_Templateparser::TP_DOT;
831
         }
832
    public function yy_r3_53()
833
    {
834
835
        $this->token = Smarty_Internal_Templateparser::TP_COMMA;
836
         }
837
    public function yy_r3_54()
838
    {
839
840
        $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
841
         }
842
    public function yy_r3_55()
843
    {
844
845
        $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
846
         }
847
    public function yy_r3_56()
848
    {
849
850
        $this->token = Smarty_Internal_Templateparser::TP_COLON;
851
         }
852
    public function yy_r3_57()
853
    {
854
855
        $this->token = Smarty_Internal_Templateparser::TP_QMARK;
856
         }
857
    public function yy_r3_58()
858
    {
859
860
        $this->token = Smarty_Internal_Templateparser::TP_HEX;
861
         }
862
    public function yy_r3_59()
863
    {
864
865
        $this->token = Smarty_Internal_Templateparser::TP_SPACE;
866
         }
867
    public function yy_r3_60()
868
    {
869
870
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
871
         }
872
873
874
     
875
    public function yylex4()
876
    {
877
        if (!isset($this->yy_global_pattern4)) {
878
            $this->yy_global_pattern4 = $this->replace("/\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G([\S\s])/isS");
879
        }
880
        if (!isset($this->dataLength)) {
881
            $this->dataLength = strlen($this->data);
882
        }
883
        if ($this->counter >=  $this->dataLength) {
884
            return false; // end of input
885
        }
886
        
887
        do {
888
            if (preg_match($this->yy_global_pattern4,$this->data, $yymatches, 0, $this->counter)) {
889
                if (!isset($yymatches[ 0 ][1])) {
890
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
891
                } else {
892
                    $yymatches = array_filter($yymatches);
893
                }
894
                if (empty($yymatches)) {
895
                    throw new Exception('Error: lexing failed because a rule matched' .
896
                        ' an empty string.  Input "' . substr($this->data,
897
                        $this->counter, 5) . '... state LITERAL');
898
                }
899
                next($yymatches); // skip global match
900
                $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...
901
                $this->value = current($yymatches); // token value
902
                $r = $this->{'yy_r4_' . $this->token}();
903
                if ($r === null) {
904
                    $this->counter += strlen($this->value);
905
                    $this->line += substr_count($this->value, "\n");
906
                    // accept this token
907
                    return true;
908
                } elseif ($r === true) {
909
                    // we have changed state
910
                    // process this token in the new state
911
                    return $this->yylex();
912
                } elseif ($r === false) {
913
                    $this->counter += strlen($this->value);
914
                    $this->line += substr_count($this->value, "\n");
915
                    if ($this->counter >=  $this->dataLength) {
916
                        return false; // end of input
917
                    }
918
                    // skip this token
919
                    continue;
920
                }            } else {
921
                throw new Exception('Unexpected input at line' . $this->line .
922
                    ': ' . $this->data[$this->counter]);
923
            }
924
            break;
925
        } while (true);
926
927
    } // end function
928
929
930
    const LITERAL = 4;
931
    public function yy_r4_1()
932
    {
933
934
        $this->literal_cnt++;
935
        $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
936
         }
937
    public function yy_r4_3()
938
    {
939
940
        if ($this->literal_cnt) {
941
             $this->literal_cnt--;
942
            $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
943
        } else {
944
            $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
945
            $this->yypopstate();
946
        }
947
         }
948
    public function yy_r4_5()
949
    {
950
951
       if (!isset($this->yy_global_literal)) {
952
           $this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->replace('/(SMARTY...literalSMARTYrdel/isS') of type string is incompatible with the declared type null of property $yy_global_literal.

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...
953
       }
954
       $to = $this->dataLength;
955
       preg_match($this->yy_global_literal, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
956
       if (isset($match[0][1])) {
957
         $to = $match[0][1];
958
       } else {
959
          $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
960
       }
961
       $this->value = substr($this->data,$this->counter,$to-$this->counter);
962
       $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
963
         }
964
965
     
966
    public function yylex5()
967
    {
968
        if (!isset($this->yy_global_pattern5)) {
969
            $this->yy_global_pattern5 = $this->replace("/\G((SMARTYldel)SMARTYautoliteral\\s+SMARTYliteral)|\G((SMARTYldel)SMARTYalliteral\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/]literal\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*)|\G((SMARTYldel)SMARTYal)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=((SMARTYldel)SMARTYal|\\$|`\\$|\"SMARTYliteral)))|\G([\S\s])/isS");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->replace('/\G((SMA...ral)))|\G([\S\s])/isS') of type string is incompatible with the declared type null of property $yy_global_pattern5.

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...
970
        }
971
        if (!isset($this->dataLength)) {
972
            $this->dataLength = strlen($this->data);
973
        }
974
        if ($this->counter >=  $this->dataLength) {
975
            return false; // end of input
976
        }
977
        
978
        do {
979
            if (preg_match($this->yy_global_pattern5,$this->data, $yymatches, 0, $this->counter)) {
980
                if (!isset($yymatches[ 0 ][1])) {
981
                   $yymatches = preg_grep("/(.|\s)+/", $yymatches);
982
                } else {
983
                    $yymatches = array_filter($yymatches);
984
                }
985
                if (empty($yymatches)) {
986
                    throw new Exception('Error: lexing failed because a rule matched' .
987
                        ' an empty string.  Input "' . substr($this->data,
988
                        $this->counter, 5) . '... state DOUBLEQUOTEDSTRING');
989
                }
990
                next($yymatches); // skip global match
991
                $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...
992
                $this->value = current($yymatches); // token value
993
                $r = $this->{'yy_r5_' . $this->token}();
994
                if ($r === null) {
995
                    $this->counter += strlen($this->value);
996
                    $this->line += substr_count($this->value, "\n");
997
                    // accept this token
998
                    return true;
999
                } elseif ($r === true) {
1000
                    // we have changed state
1001
                    // process this token in the new state
1002
                    return $this->yylex();
1003
                } elseif ($r === false) {
1004
                    $this->counter += strlen($this->value);
1005
                    $this->line += substr_count($this->value, "\n");
1006
                    if ($this->counter >=  $this->dataLength) {
1007
                        return false; // end of input
1008
                    }
1009
                    // skip this token
1010
                    continue;
1011
                }            } else {
1012
                throw new Exception('Unexpected input at line' . $this->line .
1013
                    ': ' . $this->data[$this->counter]);
1014
            }
1015
            break;
1016
        } while (true);
1017
1018
    } // end function
1019
1020
1021
    const DOUBLEQUOTEDSTRING = 5;
1022
    public function yy_r5_1()
1023
    {
1024
1025
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1026
         }
1027
    public function yy_r5_3()
1028
    {
1029
1030
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1031
         }
1032
    public function yy_r5_5()
1033
    {
1034
1035
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1036
         }
1037
    public function yy_r5_7()
1038
    {
1039
1040
        $this->yypushstate(self::TAG);
1041
        return true;
1042
         }
1043
    public function yy_r5_9()
1044
    {
1045
1046
        $this->yypushstate(self::TAG);
1047
        return true;
1048
         }
1049
    public function yy_r5_11()
1050
    {
1051
1052
        $this->token = Smarty_Internal_Templateparser::TP_LDEL;
1053
        $this->taglineno = $this->line;
1054
        $this->yypushstate(self::TAGBODY);
1055
         }
1056
    public function yy_r5_13()
1057
    {
1058
1059
        $this->token = Smarty_Internal_Templateparser::TP_QUOTE;
1060
        $this->yypopstate();
1061
         }
1062
    public function yy_r5_14()
1063
    {
1064
1065
        $this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
1066
        $this->value = substr($this->value,0,-1);
1067
        $this->yypushstate(self::TAGBODY);
1068
        $this->taglineno = $this->line;
1069
         }
1070
    public function yy_r5_15()
1071
    {
1072
1073
        $this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
1074
         }
1075
    public function yy_r5_16()
1076
    {
1077
1078
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1079
         }
1080
    public function yy_r5_17()
1081
    {
1082
1083
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1084
         }
1085
    public function yy_r5_22()
1086
    {
1087
1088
        $to = $this->dataLength;
1089
        $this->value = substr($this->data,$this->counter,$to-$this->counter);
1090
        $this->token = Smarty_Internal_Templateparser::TP_TEXT;
1091
         }
1092
1093
  }
1094
1095