Skip to content

Commit

Permalink
[TASK] Avoid useless is_array check
Browse files Browse the repository at this point in the history
phpstan is correct here, the is_array() check
is obsolete since the variable is initialized
as array and preg_match_all() won't change
its type when hand over as reference.
  • Loading branch information
lolli42 committed Nov 20, 2024
1 parent f7b0a3a commit 218c0f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ parameters:
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: '#^Call to function is_array\(\) with list\<array\<string\>\> will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: '#^Method TYPO3Fluid\\Fluid\\Core\\Parser\\TemplateParser\:\:initializeViewHelperAndAddItToStack\(\) should return TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode\|null but returns TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface\.$#'
identifier: return.type
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: '#^Strict comparison using \=\=\= between true and true will always evaluate to true\.$#'
identifier: identical.alwaysTrue
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: '#^Instanceof between TYPO3Fluid\\Fluid\\Core\\Cache\\FluidCacheInterface and TYPO3Fluid\\Fluid\\Core\\Cache\\FluidCacheInterface will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
Expand Down
44 changes: 21 additions & 23 deletions src/Core/Parser/TemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,30 +626,28 @@ protected function textAndShorthandSyntaxHandler(ParsingState $state, string $te
$detectionExpression = $expressionNodeTypeClassName::$detectionExpression;
$matchedVariables = [];
preg_match_all($detectionExpression, $section, $matchedVariables, PREG_SET_ORDER);
if (is_array($matchedVariables) === true) {
foreach ($matchedVariables as $matchedVariableSet) {
$expressionStartPosition = strpos($section, $matchedVariableSet[0]);
/** @var ExpressionNodeInterface $expressionNode */
$expressionNode = new $expressionNodeTypeClassName($matchedVariableSet[0], $matchedVariableSet, $state);
try {
if ($expressionStartPosition > 0) {
$state->getNodeFromStack()->addChildNode(new TextNode(substr($section, 0, $expressionStartPosition)));
}

$this->callInterceptor($expressionNode, InterceptorInterface::INTERCEPT_EXPRESSION, $state);
$state->getNodeFromStack()->addChildNode($expressionNode);

$expressionEndPosition = $expressionStartPosition + strlen($matchedVariableSet[0]);
if ($expressionEndPosition < strlen($section)) {
$this->textAndShorthandSyntaxHandler($state, substr($section, $expressionEndPosition), $context);
break;
}
} catch (ExpressionException $error) {
$this->textHandler(
$state,
$this->renderingContext->getErrorHandler()->handleExpressionError($error),
);
foreach ($matchedVariables as $matchedVariableSet) {
$expressionStartPosition = strpos($section, $matchedVariableSet[0]);
/** @var ExpressionNodeInterface $expressionNode */
$expressionNode = new $expressionNodeTypeClassName($matchedVariableSet[0], $matchedVariableSet, $state);
try {
if ($expressionStartPosition > 0) {
$state->getNodeFromStack()->addChildNode(new TextNode(substr($section, 0, $expressionStartPosition)));
}

$this->callInterceptor($expressionNode, InterceptorInterface::INTERCEPT_EXPRESSION, $state);
$state->getNodeFromStack()->addChildNode($expressionNode);

$expressionEndPosition = $expressionStartPosition + strlen($matchedVariableSet[0]);
if ($expressionEndPosition < strlen($section)) {
$this->textAndShorthandSyntaxHandler($state, substr($section, $expressionEndPosition), $context);
break;
}
} catch (ExpressionException $error) {
$this->textHandler(
$state,
$this->renderingContext->getErrorHandler()->handleExpressionError($error),
);
}
}
}
Expand Down

0 comments on commit 218c0f9

Please sign in to comment.