Browse code

fixed various small bugs

Fabien Potencier authored on 16/04/2019 15:25:44
Showing 6 changed files
... ...
@@ -470,6 +470,7 @@ class Environment
470 470
                 $this->cache->load($key);
471 471
             }
472 472
 
473
+            $source = null;
473 474
             if (!class_exists($cls, false)) {
474 475
                 $loader = $this->getLoader();
475 476
                 if (!$loader instanceof SourceContextLoaderInterface) {
... ...
@@ -1658,7 +1658,7 @@ function twig_constant_is_defined($constant, $object = null)
1658 1658
 function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
1659 1659
 {
1660 1660
     if (!twig_test_iterable($items)) {
1661
-        throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
1661
+        throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
1662 1662
     }
1663 1663
 
1664 1664
     $size = ceil($size);
... ...
@@ -35,7 +35,7 @@ class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader
35 35
 
36 36
 namespace {
37 37
 use Twig\Environment;
38
-use Twig\Template;
38
+use Twig\TemplateWrapper;
39 39
 
40 40
 /**
41 41
  * Loads a template from a string.
... ...
@@ -45,7 +45,7 @@ use Twig\Template;
45 45
  * @param string $template A template as a string or object implementing __toString()
46 46
  * @param string $name An optional name of the template to be used in error messages
47 47
  *
48
- * @return Template
48
+ * @return TemplateWrapper
49 49
  */
50 50
 function twig_template_from_string(Environment $env, $template, $name = null)
51 51
 {
... ...
@@ -277,11 +277,11 @@ class Lexer implements \Twig_LexerInterface
277 277
 
278 278
             case $this->options['tag_block'][0]:
279 279
                 // raw data?
280
-                if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
280
+                if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
281 281
                     $this->moveCursor($match[0]);
282 282
                     $this->lexRawData($match[1]);
283 283
                 // {% line \d+ %}
284
-                } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
284
+                } elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
285 285
                     $this->moveCursor($match[0]);
286 286
                     $this->lineno = (int) $match[1];
287 287
                 } else {
... ...
@@ -301,7 +301,7 @@ class Lexer implements \Twig_LexerInterface
301 301
 
302 302
     protected function lexBlock()
303 303
     {
304
-        if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) {
304
+        if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
305 305
             $this->pushToken(Token::BLOCK_END_TYPE);
306 306
             $this->moveCursor($match[0]);
307 307
             $this->popState();
... ...
@@ -312,7 +312,7 @@ class Lexer implements \Twig_LexerInterface
312 312
 
313 313
     protected function lexVar()
314 314
     {
315
-        if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) {
315
+        if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
316 316
             $this->pushToken(Token::VAR_END_TYPE);
317 317
             $this->moveCursor($match[0]);
318 318
             $this->popState();
... ...
@@ -324,7 +324,7 @@ class Lexer implements \Twig_LexerInterface
324 324
     protected function lexExpression()
325 325
     {
326 326
         // whitespace
327
-        if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
327
+        if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) {
328 328
             $this->moveCursor($match[0]);
329 329
 
330 330
             if ($this->cursor >= $this->end) {
... ...
@@ -333,17 +333,17 @@ class Lexer implements \Twig_LexerInterface
333 333
         }
334 334
 
335 335
         // operators
336
-        if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
336
+        if (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
337 337
             $this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
338 338
             $this->moveCursor($match[0]);
339 339
         }
340 340
         // names
341
-        elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) {
341
+        elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
342 342
             $this->pushToken(Token::NAME_TYPE, $match[0]);
343 343
             $this->moveCursor($match[0]);
344 344
         }
345 345
         // numbers
346
-        elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
346
+        elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
347 347
             $number = (float) $match[0];  // floats
348 348
             if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
349 349
                 $number = (int) $match[0]; // integers lower than the maximum
... ...
@@ -373,12 +373,12 @@ class Lexer implements \Twig_LexerInterface
373 373
             ++$this->cursor;
374 374
         }
375 375
         // strings
376
-        elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) {
376
+        elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
377 377
             $this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
378 378
             $this->moveCursor($match[0]);
379 379
         }
380 380
         // opening double quoted string
381
-        elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
381
+        elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
382 382
             $this->brackets[] = ['"', $this->lineno];
383 383
             $this->pushState(self::STATE_STRING);
384 384
             $this->moveCursor($match[0]);
... ...
@@ -428,15 +428,15 @@ class Lexer implements \Twig_LexerInterface
428 428
 
429 429
     protected function lexString()
430 430
     {
431
-        if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
431
+        if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
432 432
             $this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
433 433
             $this->pushToken(Token::INTERPOLATION_START_TYPE);
434 434
             $this->moveCursor($match[0]);
435 435
             $this->pushState(self::STATE_INTERPOLATION);
436
-        } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && \strlen($match[0]) > 0) {
436
+        } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
437 437
             $this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
438 438
             $this->moveCursor($match[0]);
439
-        } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
439
+        } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
440 440
             list($expect, $lineno) = array_pop($this->brackets);
441 441
             if ('"' != $this->code[$this->cursor]) {
442 442
                 throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
... ...
@@ -453,7 +453,7 @@ class Lexer implements \Twig_LexerInterface
453 453
     protected function lexInterpolation()
454 454
     {
455 455
         $bracket = end($this->brackets);
456
-        if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) {
456
+        if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
457 457
             array_pop($this->brackets);
458 458
             $this->pushToken(Token::INTERPOLATION_END_TYPE);
459 459
             $this->moveCursor($match[0]);
... ...
@@ -194,7 +194,7 @@ abstract class IntegrationTestCase extends TestCase
194 194
                     $message = $e->getMessage();
195 195
                     $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message)));
196 196
                     $last = substr($message, \strlen($message) - 1);
197
-                    $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.');
197
+                    $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
198 198
 
199 199
                     return;
200 200
                 }
... ...
@@ -56,7 +56,7 @@ abstract class NodeTestCase extends TestCase
56 56
         $line = $line > 0 ? "// line {$line}\n" : '';
57 57
 
58 58
         if (\PHP_VERSION_ID >= 70000) {
59
-            return sprintf('%s($context["%s"] ?? null)', $line, $name, $name);
59
+            return sprintf('%s($context["%s"] ?? null)', $line, $name);
60 60
         }
61 61
 
62 62
         if (\PHP_VERSION_ID >= 50400) {