mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
Bump Phpstan to level 4
This commit is contained in:
committed by
Fabien Potencier
parent
b917be5db5
commit
29fce6de1e
+2
-1
@@ -2,8 +2,9 @@ includes:
|
||||
- phpstan-baseline.neon
|
||||
|
||||
parameters:
|
||||
level: 3
|
||||
level: 4
|
||||
paths:
|
||||
- src
|
||||
excludePaths:
|
||||
- src/Test
|
||||
treatPhpDocTypesAsCertain: false
|
||||
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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')]));
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@ final class CallableArgumentsExtractor
|
||||
*/
|
||||
public function extractArguments(Node $arguments): array
|
||||
{
|
||||
/** @var array<int|string, Node> $extractedArguments */
|
||||
$extractedArguments = [];
|
||||
$extractedArgumentNameMap = [];
|
||||
$named = false;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user