Skip to content

Commit

Permalink
minor #4494 Bump Phpstan to level 4 (VincentLanglet)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Bump Phpstan to level 4

Commits
-------

29fce6d Bump Phpstan to level 4
  • Loading branch information
fabpot committed Dec 2, 2024
2 parents f087bd6 + 29fce6d commit 6e88a90
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ includes:
- phpstan-baseline.neon

parameters:
level: 3
level: 4
paths:
- src
excludePaths:
- src/Test
treatPhpDocTypesAsCertain: false
2 changes: 2 additions & 0 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public function loadTemplate(string $cls, string $name, ?int $index = null): Tem

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)) {
Expand All @@ -379,6 +380,7 @@ public function loadTemplate(string $cls, string $name, ?int $index = null): Tem
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)) {
Expand Down
7 changes: 1 addition & 6 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ private function updateRepr(): void
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public static function length(string $charset, $thing): int
return mb_strlen($thing, $charset);
}

if (is_countable($thing) || $thing instanceof \SimpleXMLElement) {
if (is_countable($thing)) {
return \count($thing);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/EscaperNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function enterNode(Node $node, Environment $env): Node
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;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/OptimizerNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function enterNode(Node $node, Environment $env): Node
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);
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/SafeAnalysisNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function enterNode(Node $node, Environment $env): Node
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
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/SandboxNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function enterNode(Node $node, Environment $env): Node
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;
Expand Down
5 changes: 4 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public function subparseIgnoreUnknownTwigCallables($test, bool $dropNeedle = fal
}
}

/**
* @phpstan-impure
*/
public function subparse($test, bool $dropNeedle = false): Node
{
$lineno = $this->getCurrentToken()->getLine();
Expand Down Expand Up @@ -362,7 +365,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node
// 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Profiler/NodeVisitor/ProfilerNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function enterNode(Node $node, Environment $env): Node
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')]));
Expand Down
6 changes: 6 additions & 0 deletions src/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function injectTokens(array $tokens)

/**
* Sets the pointer to the next token and returns the old one.
*
* @phpstan-impure
*/
public function next(): Token
{
Expand All @@ -58,6 +60,8 @@ public function next(): Token
* 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)
{
Expand All @@ -66,6 +70,8 @@ public function nextIf($primary, $secondary = null)

/**
* Tests a token and returns it or throws a syntax error.
*
* @phpstan-impure
*/
public function expect($type, $value = null, ?string $message = null): Token
{
Expand Down
1 change: 1 addition & 0 deletions src/Util/CallableArgumentsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
*/
public function extractArguments(Node $arguments): array
{
/** @var array<int|string, Node> $extractedArguments */
$extractedArguments = [];
$extractedArgumentNameMap = [];
$named = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Util/ReflectionCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getReflector(): \ReflectionFunctionAbstract
return $this->reflector;
}

public function getCallable(): \Closure|string|array|null
public function getCallable(): \Closure|string|array
{
return $this->callable;
}
Expand Down

0 comments on commit 6e88a90

Please sign in to comment.