Skip to content

Commit

Permalink
Simplify hasEvenNumberOfParentheses()
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo authored Jan 18, 2025
1 parent ad20dd5 commit d0346d3
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,7 @@ protected function replaceFirstStatement($search, $replace, $subject, $offset)
*/
protected function hasEvenNumberOfParentheses(string $expression)
{
$tokens = token_get_all('<?php '.$expression);

if (Arr::last($tokens) !== ')') {
return false;
}

$opening = 0;
$closing = 0;

foreach ($tokens as $token) {
if ($token == ')') {
$closing++;
} elseif ($token == '(') {
$opening++;
}
}

return $opening === $closing;
return substr_count($expression, '(') === substr_count($expression, ')');
}

/**
Expand Down

0 comments on commit d0346d3

Please sign in to comment.