diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 8b5749775..539390404 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -189,12 +189,13 @@ class Twig_ExpressionParser break; } + // no break default: if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) { $node = $this->parseArrayExpression(); } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) { $node = $this->parseHashExpression(); - } elseif ($token->test(Twig_Token::OPERATOR_TYPE, '=') && ($this->parser->getStream()->look(-1)->getValue() === '==' || $this->parser->getStream()->look(-1)->getValue() === '!=')) { + } elseif ($token->test(Twig_Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { throw new Twig_Error_Syntax(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } else { throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); @@ -305,7 +306,7 @@ class Twig_ExpressionParser { while (true) { $token = $this->parser->getCurrentToken(); - if ($token->getType() == Twig_Token::PUNCTUATION_TYPE) { + if (Twig_Token::PUNCTUATION_TYPE == $token->getType()) { if ('.' == $token->getValue() || '[' == $token->getValue()) { $node = $this->parseSubscriptExpression($node); } elseif ('|' == $token->getValue()) { @@ -376,14 +377,14 @@ class Twig_ExpressionParser $lineno = $token->getLine(); $arguments = new Twig_Node_Expression_Array(array(), $lineno); $type = Twig_Template::ANY_CALL; - if ($token->getValue() == '.') { + if ('.' == $token->getValue()) { $token = $stream->next(); if ( - $token->getType() == Twig_Token::NAME_TYPE + Twig_Token::NAME_TYPE == $token->getType() || - $token->getType() == Twig_Token::NUMBER_TYPE + Twig_Token::NUMBER_TYPE == $token->getType() || - ($token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) + (Twig_Token::OPERATOR_TYPE == $token->getType() && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) ) { $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index c37a9fe3b..cdfa669c9 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -579,7 +579,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese if ($start >= 0 && $length >= 0 && $item instanceof Iterator) { try { - return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys); + return iterator_to_array(new LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys); } catch (OutOfBoundsException $exception) { return array(); } diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index bac1cc82a..599c73bc6 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -210,7 +210,7 @@ class Twig_Lexer $this->moveCursor($match[0]); if ($this->cursor >= $this->end) { - throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); } } @@ -308,7 +308,7 @@ class Twig_Lexer $this->moveCursor($match[0]); } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { list($expect, $lineno) = array_pop($this->brackets); - if ($this->code[$this->cursor] != '"') { + if ('"' != $this->code[$this->cursor]) { throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 323e942f0..d54572924 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -131,7 +131,7 @@ class Twig_Parser $this->stream->next(); $token = $this->getCurrentToken(); - if ($token->getType() !== Twig_Token::NAME_TYPE) { + if (Twig_Token::NAME_TYPE !== $token->getType()) { throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); } diff --git a/lib/Twig/Profiler/Profile.php b/lib/Twig/Profiler/Profile.php index 2177f6092..f81e52b95 100644 --- a/lib/Twig/Profiler/Profile.php +++ b/lib/Twig/Profiler/Profile.php @@ -80,7 +80,7 @@ class Twig_Profiler_Profile implements IteratorAggregate, Serializable return $this->profiles; } - public function addProfile(Twig_Profiler_Profile $profile) + public function addProfile(self $profile) { $this->profiles[] = $profile; } diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 551d50086..41963a07e 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -38,7 +38,7 @@ final class Twig_TokenParser_For extends Twig_TokenParser $stream->expect(Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideForFork')); - if ($stream->next()->getValue() == 'else') { + if ('else' == $stream->next()->getValue()) { $stream->expect(Twig_Token::BLOCK_END_TYPE); $else = $this->parser->subparse(array($this, 'decideForEnd'), true); } else { diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index c32180ca9..539d0d5a2 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -123,7 +123,7 @@ final class Twig_TokenStream */ public function isEOF() { - return $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE; + return Twig_Token::EOF_TYPE === $this->tokens[$this->current]->getType(); } /** diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php index 122afc4ff..10f83bd63 100644 --- a/test/Twig/Tests/Extension/SandboxTest.php +++ b/test/Twig/Tests/Extension/SandboxTest.php @@ -251,7 +251,7 @@ EOF $twig->loadTemplate('1_include')->render(self::$params); } catch (Throwable $e) { } - if ($e === null) { + if (null === $e) { $this->fail('An exception should be thrown for this test to be valid.'); } diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index f512b1070..027180f12 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -311,7 +311,7 @@ class CountableStub implements \Countable } /** - * This class is used in tests for the length filter + * This class is used in tests for the length filter. */ class IteratorAggregateStub implements \IteratorAggregate {