mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-25 01:56:27 +00:00
Replace most empty() calls
This commit is contained in:
@@ -621,7 +621,7 @@ class ExpressionParser
|
||||
|
||||
$stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
|
||||
while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) {
|
||||
if (!empty($args)) {
|
||||
if ($args) {
|
||||
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
|
||||
|
||||
// if the comma above was a trailing comma, early exit the argument parse loop
|
||||
|
||||
@@ -545,7 +545,7 @@ final class CoreExtension extends AbstractExtension
|
||||
}
|
||||
|
||||
$asString = (string) $date;
|
||||
if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
|
||||
if (ctype_digit($asString) || (isset($asString[0]) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
|
||||
$date = new \DateTime('@'.$date);
|
||||
} else {
|
||||
$date = new \DateTime($date, $this->getTimezone());
|
||||
@@ -1616,7 +1616,7 @@ final class CoreExtension extends AbstractExtension
|
||||
} elseif (\is_object($object)) {
|
||||
$message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
|
||||
} elseif (\is_array($object)) {
|
||||
if (empty($object)) {
|
||||
if (!$object) {
|
||||
$message = \sprintf('Key "%s" does not exist as the sequence/mapping is empty.', $arrayItem);
|
||||
} else {
|
||||
$message = \sprintf('Key "%s" for sequence/mapping with keys "%s" does not exist.', $arrayItem, implode(', ', array_keys($object)));
|
||||
|
||||
+4
-4
@@ -217,7 +217,7 @@ class Lexer
|
||||
|
||||
$this->pushToken(Token::EOF_TYPE);
|
||||
|
||||
if (!empty($this->brackets)) {
|
||||
if ($this->brackets) {
|
||||
[$expect, $lineno] = array_pop($this->brackets);
|
||||
throw new SyntaxError(\sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ class Lexer
|
||||
|
||||
private function lexBlock(): void
|
||||
{
|
||||
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
|
||||
if (!$this->brackets && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
|
||||
$this->pushToken(Token::BLOCK_END_TYPE);
|
||||
$this->moveCursor($match[0]);
|
||||
$this->popState();
|
||||
@@ -303,7 +303,7 @@ class Lexer
|
||||
|
||||
private function lexVar(): void
|
||||
{
|
||||
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
|
||||
if (!$this->brackets && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
|
||||
$this->pushToken(Token::VAR_END_TYPE);
|
||||
$this->moveCursor($match[0]);
|
||||
$this->popState();
|
||||
@@ -360,7 +360,7 @@ class Lexer
|
||||
}
|
||||
// closing bracket
|
||||
elseif (str_contains(')]}', $this->code[$this->cursor])) {
|
||||
if (empty($this->brackets)) {
|
||||
if (!$this->brackets) {
|
||||
throw new SyntaxError(\sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
} elseif ($callableParameter->isDefaultValueAvailable()) {
|
||||
$optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1);
|
||||
} elseif ($callableParameter->isOptional()) {
|
||||
if (empty($parameters)) {
|
||||
if (!$parameters) {
|
||||
break;
|
||||
} else {
|
||||
$missingArguments[] = $name;
|
||||
@@ -235,7 +235,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($parameters)) {
|
||||
if ($parameters) {
|
||||
$unknownParameter = null;
|
||||
foreach ($parameters as $parameter) {
|
||||
if ($parameter instanceof Node) {
|
||||
|
||||
@@ -149,7 +149,7 @@ abstract class IntegrationTestCase extends TestCase
|
||||
$tests[] = [str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs, $deprecation];
|
||||
}
|
||||
|
||||
if ($legacyTests && empty($tests)) {
|
||||
if ($legacyTests && !$tests) {
|
||||
// add a dummy test to avoid a PHPUnit message
|
||||
return [['not', '-', '', [], '', []]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user