Skip to content

Commit

Permalink
TASK: Followup neos#4844 lint Neos.Fusion/Core in 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 2, 2024
1 parent 3c988b6 commit 336a658
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Neos.Fusion/Classes/Core/Cache/CacheSegmentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected function extractContentAndSubSegments($currentPosition, array $segment
$nextEndPosition = $this->calculateNextTokenPosition($currentPosition, ContentCache::CACHE_SEGMENT_END_TOKEN);
}

/** may have to be phpstan-ignore-next-line'd: $toPosition expects int|null but int|false given. Is this a real case? */
/** @phpstan-ignore-next-line: $toPosition expects int|null but int|false given. Is this a real case? */
$remainingContent = $this->extractContent($currentPosition, $nextEndPosition);
$segmentData['content'] .= $remainingContent;
$segmentData['cleanContent'] .= $remainingContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PlainTextHandler extends AbstractRenderingExceptionHandler
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param string|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public function handleRenderingException($fusionPath, \Exception $exception)
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
{
throw new \BadMethodCallException('Will never be thrown see handleRenderingException.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function injectThrowableStorage(ThrowableStorageInterface $throwableStora
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param string|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
Expand Down
6 changes: 6 additions & 0 deletions Neos.Fusion/Classes/Core/FusionGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
final readonly class FusionGlobals
{
/**
* @param array<string|mixed> $value
*/
private function __construct(
public array $value
) {
Expand All @@ -33,6 +36,9 @@ public static function empty(): self
return new self([]);
}

/**
* @param array<string|mixed> $variables
*/
public static function fromArray(array $variables): self
{
return new self($variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected static function resolveRelativePath(string $filePattern, ?string $file
*/
protected static function parseGlobPatternAndResolveFiles(string $filePattern, string $defaultFileNameEnd): array
{
$matches = [];
$fileIteratorCreator = match (1) {
// We use the flag SKIP_DOTS, as it might not be allowed to access `..` and we only are interested in files
// We use the flag UNIX_PATHS, so that stream wrapper paths are always valid on windows https://github.com/neos/neos-development-collection/issues/4358
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ObjectTreeParser

protected ?string $contextPathAndFilename;

protected function __construct(Lexer $lexer, ?string $contextPathAndFilename)
private function __construct(Lexer $lexer, ?string $contextPathAndFilename)
{
$this->lexer = $lexer;
$this->contextPathAndFilename = $contextPathAndFilename;
Expand All @@ -63,7 +63,7 @@ protected function __construct(Lexer $lexer, ?string $contextPathAndFilename)
public static function parse(FusionSourceCode $fusionCode): FusionFile
{
$lexer = new Lexer($fusionCode->getSourceCode());
$parser = new static($lexer, $fusionCode->getFilePath());
$parser = new self($lexer, $fusionCode->getFilePath());
return $parser->parseFusionFile();
}

Expand Down
8 changes: 4 additions & 4 deletions Neos.Fusion/Classes/Core/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ public function render($fusionPath)
*/
public function handleRenderingException(string $fusionPath, \Exception $exception, bool $useInnerExceptionHandler = false)
{
if ($this->overriddenExceptionHandler) {
$this->overriddenExceptionHandler->setRuntime($this);
return $this->overriddenExceptionHandler->handleRenderingException($fusionPath, $exception);
if ($exceptionHandler = $this->overriddenExceptionHandler) {
$exceptionHandler->setRuntime($this);
return $exceptionHandler->handleRenderingException($fusionPath, $exception);
}

$fusionConfiguration = $this->runtimeConfiguration->forPath($fusionPath);
Expand Down Expand Up @@ -755,7 +755,7 @@ protected function evaluateEelExpression($expression, AbstractFusionObject $cont
}
$contextVariables['this'] = $contextObject;

/** may have to be phpstan-ignore-next-line'd: the mind of the great phpstan can and will not comprehend this */
/** @phpstan-ignore-next-line the mind of the great phpstan can and will not comprehend this */
if ($this->eelEvaluator instanceof \Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy) {
$this->eelEvaluator->_activateDependency();
}
Expand Down
1 change: 1 addition & 0 deletions Neos.Fusion/Classes/Core/RuntimeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function forPath(string $fusionPath): array
$currentPrototypeDefinitions = $configuration['__prototypes'];
}
}
assert(isset($configuration));

// Build configuration for the remaining path parts
$remainingPath = substr($fusionPath, $pathUntilNow === '' ? 0 : strlen($pathUntilNow) + 1);
Expand Down
1 change: 1 addition & 0 deletions Neos.Fusion/Classes/Core/RuntimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RuntimeFactory

/**
* @Flow\InjectConfiguration(path="defaultContext", package="Neos.Fusion")
* @var array<string, string>
*/
protected ?array $defaultContextConfiguration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class NodeWrappingHandler extends AbstractRenderingExceptionHandler
*
* @param string $fusionPath - path causing the exception
* @param \Exception $exception - exception to handle
* @param integer $referenceCode - might be unset
* @param string|null $referenceCode - might be unset
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode): string
Expand Down
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/Fusion/ExceptionHandlers/PageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PageHandler extends AbstractRenderingExceptionHandler
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param string|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
Expand Down
9 changes: 0 additions & 9 deletions bootstrap-phpstan.php

This file was deleted.

25 changes: 25 additions & 0 deletions phpstan-neos-fusion-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# partial linting for Neos.Fusion was introduced with
# https://github.com/neos/neos-development-collection/pull/4844
# once the special ignores are not necessary anymore, this php-stan config should be deleted
parameters:
ignoreErrors:
# Adding array<int|string, mixed> would just bloat the code up.
# In these files we are mostly dealing with the fusion configuration which is highly dynamic:
-
message: '#no value type specified in iterable type array.$#'
paths:
- Neos.Fusion/Classes/Core/Runtime.php
- Neos.Fusion/Classes/Core/Cache/RuntimeContentCache.php
- Neos.Fusion/Classes/Core/Cache/ContentCache.php
- Neos.Fusion/Classes/Core/Cache/CacheSegmentParser.php
- Neos.Fusion/Classes/Core/RuntimeConfiguration.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/MergedArrayTreeVisitor.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/MergedArrayTree.php
# A return type was not explicitly specified in the ast visiting code.
# But it is planned refactor this instead to something better type- and readable in general:
-
message: '#has no return type specified.$#'
paths:
- Neos.Fusion/Classes/Core/ObjectTreeParser/MergedArrayTreeVisitor.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/AstNodeVisitorInterface.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/Ast
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
includes:
- phpstan-baseline.neon
- phpstan-neos-fusion-baseline.neon

parameters:
level: 8
Expand All @@ -16,8 +17,10 @@ parameters:
- Neos.ContentRepositoryRegistry/Classes
- Neos.Neos/Classes
- Neos.NodeTypes.Form/Classes
# todo lint whole fusion package
- Neos.Fusion/Classes/Core
bootstrapFiles:
- bootstrap-phpstan.php
- ../Framework/bootstrap-phpstan.php
rules:
- Neos\ContentRepository\BehavioralTests\PhpstanRules\ApiOrInternalAnnotationRule
- Neos\ContentRepository\BehavioralTests\PhpstanRules\InternalMethodsNotAllowedOutsideContentRepositoryRule

0 comments on commit 336a658

Please sign in to comment.