Bump Phpstan to level 4

This commit is contained in:
Vincent Langlet
2024-12-02 16:54:35 +01:00
committed by Fabien Potencier
parent b917be5db5
commit 29fce6de1e
13 changed files with 23 additions and 15 deletions
+2 -1
View File
@@ -2,8 +2,9 @@ includes:
- phpstan-baseline.neon
parameters:
level: 3
level: 4
paths:
- src
excludePaths:
- src/Test
treatPhpDocTypesAsCertain: false
+2
View File
@@ -371,6 +371,7 @@ class Environment
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
$this->cache->load($key);
/** @var class-string $cls -- to reset `class_exists($cls, false)` result for PHPStan */
}
if (!class_exists($cls, false)) {
@@ -379,6 +380,7 @@ class Environment
if (!isset($this->hotCache[$name])) {
$this->cache->write($key, $content);
$this->cache->load($key);
/** @var class-string $cls -- to reset `class_exists($cls, false)` result for PHPStan */
}
if (!class_exists($mainCls, false)) {
+1 -6
View File
@@ -142,12 +142,7 @@ class Error extends \Exception
}
if ($this->name) {
if (\is_string($this->name) || $this->name instanceof \Stringable) {
$name = \sprintf('"%s"', $this->name);
} else {
$name = json_encode($this->name);
}
$this->message .= \sprintf(' in %s', $name);
$this->message .= \sprintf(' in "%s"', $this->name);
}
if ($this->lineno && $this->lineno >= 0) {
+1 -1
View File
@@ -1199,7 +1199,7 @@ final class CoreExtension extends AbstractExtension
return mb_strlen($thing, $charset);
}
if (is_countable($thing) || $thing instanceof \SimpleXMLElement) {
if (is_countable($thing)) {
return \count($thing);
}
+1 -1
View File
@@ -71,7 +71,7 @@ final class EscaperNodeVisitor implements NodeVisitorInterface
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): Node
{
if ($node instanceof ModuleNode) {
$this->defaultStrategy = false;
+1 -1
View File
@@ -72,7 +72,7 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): Node
{
if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
$this->leaveOptimizeFor($node);
+1 -1
View File
@@ -84,7 +84,7 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): Node
{
if ($node instanceof ConstantExpression) {
// constants are marked safe for all
+1 -1
View File
@@ -103,7 +103,7 @@ final class SandboxNodeVisitor implements NodeVisitorInterface
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): Node
{
if ($node instanceof ModuleNode) {
$this->inAModule = false;
+4 -1
View File
@@ -152,6 +152,9 @@ class Parser
}
}
/**
* @phpstan-impure
*/
public function subparse($test, bool $dropNeedle = false): Node
{
$lineno = $this->getCurrentToken()->getLine();
@@ -362,7 +365,7 @@ class Parser
// we need to discard the wrapping "Node" for the "body" node
$nested = $nested || !$node instanceof Nodes;
foreach ($node as $k => $n) {
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) {
if (null === $this->filterBodyNodes($n, $nested)) {
$node->removeNode($k);
}
}
@@ -41,7 +41,7 @@ final class ProfilerNodeVisitor implements NodeVisitorInterface
return $node;
}
public function leaveNode(Node $node, Environment $env): ?Node
public function leaveNode(Node $node, Environment $env): Node
{
if ($node instanceof ModuleNode) {
$node->setNode('display_start', new Nodes([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $this->varName), $node->getNode('display_start')]));
+6
View File
@@ -44,6 +44,8 @@ final class TokenStream
/**
* Sets the pointer to the next token and returns the old one.
*
* @phpstan-impure
*/
public function next(): Token
{
@@ -58,6 +60,8 @@ final class TokenStream
* Tests a token, sets the pointer to the next one and returns it or throws a syntax error.
*
* @return Token|null The next token if the condition is true, null otherwise
*
* @phpstan-impure
*/
public function nextIf($primary, $secondary = null)
{
@@ -66,6 +70,8 @@ final class TokenStream
/**
* Tests a token and returns it or throws a syntax error.
*
* @phpstan-impure
*/
public function expect($type, $value = null, ?string $message = null): Token
{
+1
View File
@@ -39,6 +39,7 @@ final class CallableArgumentsExtractor
*/
public function extractArguments(Node $arguments): array
{
/** @var array<int|string, Node> $extractedArguments */
$extractedArguments = [];
$extractedArgumentNameMap = [];
$named = false;
+1 -1
View File
@@ -77,7 +77,7 @@ final class ReflectionCallable
return $this->reflector;
}
public function getCallable(): \Closure|string|array|null
public function getCallable(): \Closure|string|array
{
return $this->callable;
}