Skip to content
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

Phpstan v2 #1017

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"ext-json": "*",
"ext-simplexml": "*",
"friendsofphp/php-cs-fixer": "^3.59.3",
"phpstan/phpstan": "^1.11.5",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan": "^2.0.2",
"phpstan/phpstan-phpunit": "^2.0.1",
"phpunit/phpunit": "^11.2.5",
"t3docs/fluid-documentation-generator": "^4.3",
"psr/container": "^2.0"
"psr/container": "^2.0",
"t3docs/fluid-documentation-generator": "^4.3"
},
"suggest": {
"ext-json": "PHP JSON is needed when using JSONVariableProvider: A relatively rare use case",
Expand Down
73 changes: 64 additions & 9 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,36 +1,91 @@
parameters:
ignoreErrors:
-
message: "#^Binary operation \"\\+\" between non\\-empty\\-string and 0 results in an error\\.$#"
message: '#^Instanceof between TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface and TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
count: 1
path: src/Core/Parser/SyntaxTree/RootNode.php

-
message: '#^Binary operation "\+" between non\-empty\-string and 0 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: "#^Property TYPO3Fluid\\\\Fluid\\\\Core\\\\Rendering\\\\RenderingContext\\:\\:\\$errorHandler \\(TYPO3Fluid\\\\Fluid\\\\Core\\\\ErrorHandler\\\\ErrorHandlerInterface\\) in isset\\(\\) is not nullable\\.$#"
message: '#^Call to an undefined method TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface\:\:getUninitializedViewHelper\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Core/Rendering/RenderingContext.php
path: src/Core/Parser/TemplateParser.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
message: '#^Method TYPO3Fluid\\Fluid\\Core\\Parser\\TemplateParser\:\:initializeViewHelperAndAddItToStack\(\) should return TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode\|null but returns TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface\.$#'
identifier: return.type
count: 1
path: src/Core/Parser/TemplateParser.php

-
message: '#^Strict comparison using \!\=\= between string and null will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: src/Core/Variables/JSONVariableProvider.php

-
message: '#^Instanceof between TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface and TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
count: 1
path: src/Core/ViewHelper/AbstractConditionViewHelper.php

-
message: '#^Instanceof between TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode and TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
count: 2
path: src/Core/ViewHelper/AbstractConditionViewHelper.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
message: '#^Call to TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper\:\:handleAdditionalArguments\(\) on a separate line has no effect\.$#'
identifier: staticMethod.resultUnused
count: 1
path: src/Core/ViewHelper/AbstractTagBasedViewHelper.php

-
message: '#^Call to TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper\:\:initialize\(\) on a separate line has no effect\.$#'
identifier: staticMethod.resultUnused
count: 1
path: src/Core/ViewHelper/AbstractTagBasedViewHelper.php

-
message: '#^Instanceof between TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface and TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
count: 1
path: src/Core/ViewHelper/AbstractViewHelper.php

-
message: "#^Strict comparison using \\=\\=\\= between class\\-string and false will always evaluate to false\\.$#"
message: '#^Method TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper\:\:handleAdditionalArguments\(\) has TYPO3Fluid\\Fluid\\Core\\ViewHelper\\Exception in PHPDoc @throws tag but it''s not thrown\.$#'
identifier: throws.unusedType
count: 1
path: src/Core/ViewHelper/ViewHelperResolver.php
path: src/Core/ViewHelper/AbstractViewHelper.php

-
message: '#^Parameter \#1 \$array of function array_unique expects an array of values castable to string, array\<array\<string\>\|string\> given\.$#'
identifier: argument.type
count: 2
path: src/View/TemplatePaths.php

-
message: "#^Variable \\$iterationData might not be defined\\.$#"
message: '#^Variable \$iterationData might not be defined\.$#'
identifier: variable.undefined
count: 1
path: src/ViewHelpers/ForViewHelper.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
message: '#^Unreachable statement \- code above always terminates\.$#'
identifier: deadCode.unreachable
count: 1
path: tests/Functional/ViewHelpers/StaticCacheable/NotSharedStaticCompilableViewHelperTest.php

-
message: '#^Call to TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper\:\:handleAdditionalArguments\(\) on a separate line has no effect\.$#'
identifier: staticMethod.resultUnused
count: 1
path: tests/Unit/Core/Fixtures/TestViewHelper.php
4 changes: 1 addition & 3 deletions src/Core/Cache/SimpleFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public function flush(?string $name = null): void
$this->flushByName($name);
} else {
$files = $this->getCachedFilenames();
if (is_array($files)) {
array_walk($files, [$this, 'flushByFilename']);
}
array_walk($files, [$this, 'flushByFilename']);
}
}

Expand Down
44 changes: 21 additions & 23 deletions src/Core/Parser/TemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,30 +626,28 @@ protected function textAndShorthandSyntaxHandler(ParsingState $state, string $te
$detectionExpression = $expressionNodeTypeClassName::$detectionExpression;
$matchedVariables = [];
preg_match_all($detectionExpression, $section, $matchedVariables, PREG_SET_ORDER);
if (is_array($matchedVariables) === true) {
foreach ($matchedVariables as $matchedVariableSet) {
$expressionStartPosition = strpos($section, $matchedVariableSet[0]);
/** @var ExpressionNodeInterface $expressionNode */
$expressionNode = new $expressionNodeTypeClassName($matchedVariableSet[0], $matchedVariableSet, $state);
try {
if ($expressionStartPosition > 0) {
$state->getNodeFromStack()->addChildNode(new TextNode(substr($section, 0, $expressionStartPosition)));
}

$this->callInterceptor($expressionNode, InterceptorInterface::INTERCEPT_EXPRESSION, $state);
$state->getNodeFromStack()->addChildNode($expressionNode);

$expressionEndPosition = $expressionStartPosition + strlen($matchedVariableSet[0]);
if ($expressionEndPosition < strlen($section)) {
$this->textAndShorthandSyntaxHandler($state, substr($section, $expressionEndPosition), $context);
break;
}
} catch (ExpressionException $error) {
$this->textHandler(
$state,
$this->renderingContext->getErrorHandler()->handleExpressionError($error),
);
foreach ($matchedVariables as $matchedVariableSet) {
$expressionStartPosition = strpos($section, $matchedVariableSet[0]);
/** @var ExpressionNodeInterface $expressionNode */
$expressionNode = new $expressionNodeTypeClassName($matchedVariableSet[0], $matchedVariableSet, $state);
try {
if ($expressionStartPosition > 0) {
$state->getNodeFromStack()->addChildNode(new TextNode(substr($section, 0, $expressionStartPosition)));
}

$this->callInterceptor($expressionNode, InterceptorInterface::INTERCEPT_EXPRESSION, $state);
$state->getNodeFromStack()->addChildNode($expressionNode);

$expressionEndPosition = $expressionStartPosition + strlen($matchedVariableSet[0]);
if ($expressionEndPosition < strlen($section)) {
$this->textAndShorthandSyntaxHandler($state, substr($section, $expressionEndPosition), $context);
break;
}
} catch (ExpressionException $error) {
$this->textHandler(
$state,
$this->renderingContext->getErrorHandler()->handleExpressionError($error),
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Rendering/RenderingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class RenderingContext implements RenderingContextInterface
{
/**
* @var ErrorHandlerInterface
* @var ErrorHandlerInterface|null
*/
protected $errorHandler;

Expand Down Expand Up @@ -90,7 +90,7 @@ class RenderingContext implements RenderingContextInterface
protected $templateCompiler;

/**
* @var FluidCacheInterface
* @var FluidCacheInterface|null
*/
protected $cache;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/ViewHelper/ViewHelperResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function resolveViewHelperClassName(string $namespaceIdentifier, string $
if (!isset($this->resolvedViewHelperClassNames[$namespaceIdentifier][$methodIdentifier])) {
$resolvedViewHelperClassName = $this->resolveViewHelperName($namespaceIdentifier, $methodIdentifier);
$actualViewHelperClassName = implode('\\', array_map('ucfirst', explode('.', $resolvedViewHelperClassName)));
if (false === class_exists($actualViewHelperClassName) || $actualViewHelperClassName === false) {
if (!class_exists($actualViewHelperClassName)) {
throw new ParserException(sprintf(
'The ViewHelper "<%s:%s>" could not be resolved.' . chr(10) .
'Based on your spelling, the system would load the class "%s", however this class does not exist.',
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/AliasViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class AliasViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('map', 'array', 'Array that specifies which variables should be mapped to which alias', true);
}

Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/CaseViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class CaseViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'mixed', 'Value to match in this case', true);
}

Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/ConstantViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ConstantViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('name', 'string', 'String representation of a PHP constant or enum');
}

Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/CountViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class CountViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('subject', 'array', 'Countable subject, array or \Countable');
}

Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/CycleViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class CycleViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('values', 'array', 'The array or object implementing \ArrayAccess (for example \SplObjectStorage) to iterated over');
$this->registerArgument('as', 'string', 'The name of the iteration variable', true);
}
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/DebugViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class DebugViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('typeOnly', 'boolean', 'If true, debugs only the type of variables', false, false);
$this->registerArgument('levels', 'integer', 'Levels to render when rendering nested objects/arrays', false, 5);
$this->registerArgument('html', 'boolean', 'Render HTML. If false, output is indented plaintext', false, false);
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/ForViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class ForViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('each', 'array', 'The array or \SplObjectStorage to iterated over', true);
$this->registerArgument('as', 'string', 'The name of the iteration variable', true);
$this->registerArgument('key', 'string', 'Variable to assign array key to');
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/Format/HtmlspecialcharsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class HtmlspecialcharsViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'string', 'Value to format');
$this->registerArgument('keepQuotes', 'boolean', 'If true quotes will not be replaced (ENT_NOQUOTES)', false, false);
$this->registerArgument('encoding', 'string', 'Encoding', false, 'UTF-8');
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/Format/PrintfViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class PrintfViewHelper extends AbstractViewHelper
{
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'string', 'String to format');
$this->registerArgument('arguments', 'array', 'The arguments for vsprintf', false, []);
}
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/GroupedForViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class GroupedForViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('each', 'array', 'The array or \SplObjectStorage to iterated over', true);
$this->registerArgument('as', 'string', 'The name of the iteration variable', true);
$this->registerArgument('groupBy', 'string', 'Group by this property', true);
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class RenderViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('section', 'string', 'Section to render - combine with partial to render section in partial');
$this->registerArgument('partial', 'string', 'Partial to render, with or without section');
$this->registerArgument('delegate', 'string', 'Optional PHP class name of a permanent, included-in-app ParsedTemplateInterface implementation to override partial/section');
Expand Down
1 change: 0 additions & 1 deletion src/ViewHelpers/SwitchViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class SwitchViewHelper extends AbstractViewHelper

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('expression', 'mixed', 'Expression to switch', true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct()

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('firstOptionalArgument', 'string', 'First optional argument which is used as render children.');
$this->registerArgument('secondOptionalArgument', 'string', 'Second optional argument which is used as render children.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function __construct() {}

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('firstOptionalArgument', 'string', 'First optional argument which is used as render children.');
$this->registerArgument('secondOptionalArgument', 'string', 'Second optional argument which is used as render children.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class CompileWithContentArgumentAndRenderStaticFirstRegisteredOptionalArgu

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('requiredArgument', 'string', 'demo required argument before optional argument', true);
$this->registerArgument('firstOptionalArgument', 'string', 'First optional argument which is used as render children.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class CompileWithContentArgumentAndRenderStaticUseFirstRegisteredOptionalA

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('firstOptionalArgument', 'string', 'First optional argument which is used as render children.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class ContentArgumentNameViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('value', 'string', '');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final class ContentArgumentNameWithoutEscapeChildrenViewHelper extends AbstractV

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('value', 'string', '');
}

Expand Down
9 changes: 0 additions & 9 deletions tests/Functional/ViewHelpers/Cache/DisableViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@
namespace TYPO3Fluid\Fluid\Tests\Functional\ViewHelpers\Cache;

use PHPUnit\Framework\Attributes\Test;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;
use TYPO3Fluid\Fluid\ViewHelpers\Cache\DisableViewHelper;

final class DisableViewHelperTest extends AbstractFunctionalTestCase
{
#[Test]
public function viewHelperCanBeInstantiated(): void
{
$subject = new DisableViewHelper();
self::assertInstanceOf(AbstractViewHelper::class, $subject);
}

#[Test]
public function templateUsingViewHelperCanBeRendered(): void
{
Expand Down
9 changes: 0 additions & 9 deletions tests/Functional/ViewHelpers/Cache/StaticViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@
namespace TYPO3Fluid\Fluid\Tests\Functional\ViewHelpers\Cache;

use PHPUnit\Framework\Attributes\Test;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;
use TYPO3Fluid\Fluid\ViewHelpers\Cache\StaticViewHelper;

final class StaticViewHelperTest extends AbstractFunctionalTestCase
{
#[Test]
public function viewHelperCanBeInstantiated(): void
{
$subject = new StaticViewHelper();
self::assertInstanceOf(AbstractViewHelper::class, $subject);
}

#[Test]
public function templateUsingViewHelperCanBeRendered(): void
{
Expand Down
Loading