-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use phpstan level 4 #4464
Use phpstan level 4 #4464
Conversation
@@ -139,10 +155,7 @@ public function __construct(LoaderInterface $loader, array $options = []) | |||
$escaperExt = new EscaperExtension($options['autoescape']); | |||
$escaperExt->setEnvironment($this, false); | |||
$this->addExtension($escaperExt); | |||
if (\PHP_VERSION_ID >= 80000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused code since "php": ">=8.0.2", in composer.json
@@ -873,7 +888,7 @@ public function getUnaryOperators(): array | |||
/** | |||
* @internal | |||
* | |||
* @return array<string, array{precedence: int, class: class-string<AbstractBinary>, associativity: ExpressionParser::OPERATOR_*}> | |||
* @return array<string, array{precedence: int, class: class-string<AbstractExpression>, associativity: ExpressionParser::OPERATOR_*}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not always an AbstractBinary since CoreExtension::getOperators returns NullCoalesceExpression
which is not extending AbstractBinary.
I did the same for Unary just in case.
@@ -753,7 +751,6 @@ private function parseTestExpression(Node $node): TestExpression | |||
$node = new MacroReferenceExpression($alias['node']->getNode('var'), $alias['name'], new ArrayExpression([], $node->getTemplateLine()), $node->getTemplateLine()); | |||
} | |||
|
|||
$ready = $test instanceof TwigTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused code
@@ -1223,7 +1223,7 @@ public static function length(string $charset, $thing): int | |||
return mb_strlen($thing, $charset); | |||
} | |||
|
|||
if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SimpleXMLElement is countable
@@ -15,23 +15,6 @@ | |||
|
|||
class EqualBinary extends AbstractBinary | |||
{ | |||
public function compile(Compiler $compiler): void | |||
{ | |||
if (\PHP_VERSION_ID >= 80000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always true since "php": ">=8.0.2", in composer.json ; same for others
@@ -327,7 +327,10 @@ private function getTwigCallable(): TwigCallableInterface | |||
{ | |||
$current = $this->getAttribute('twig_callable'); | |||
|
|||
$this->setAttribute('twig_callable', match ($this->getAttribute('type')) { | |||
/** @var 'test'|'function'|'filter' $type */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid phpstan reporting that we don't support all match cases.
@@ -41,20 +41,12 @@ public function compile(Compiler $compiler): void | |||
if ($this->getAttribute('is_defined_test')) { | |||
if (isset($this->specialVars[$name])) { | |||
$compiler->repr(true); | |||
} elseif (\PHP_VERSION_ID >= 70400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always true
@@ -67,7 +67,7 @@ public function enterNode(Node $node, Environment $env): Node | |||
return $node; | |||
} | |||
|
|||
public function leaveNode(Node $node, Environment $env): ?Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHPStan report the null type as useless.
Since the class is final we can remove it.
@@ -408,7 +408,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node | |||
// Node::class !== \get_class($node) should be removed in Twig 4.0 | |||
$nested = $nested || (Node::class !== \get_class($node) && !$node instanceof Nodes); | |||
foreach ($node as $k => $n) { | |||
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$n is never null ; when doing foreach on node, it's \IteratorAggregate<int|string, Node>
@@ -63,7 +63,7 @@ public function __construct( | |||
$this->name = $class->name.'::'.$r->name; | |||
} elseif (\PHP_VERSION_ID < 80111 && $class = $r->getClosureScopeClass()) { | |||
$callable = [\is_array($callable) ? $callable[0] : $class->name, $r->name]; | |||
$this->name = (\is_array($callable) ? $callable[0] : $class->name).'::'.$r->name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always an array.
I think we should focus on Twig 4 instead for the higher level. |
Ok, I'll do others PR on Twig 4 then. I'll wait for the 3.x merge into 4.x first. |
I reopened the PR on 4.x. #4494 |
No description provided.