Skip to content

Commit

Permalink
TASK: Migrate Neos.Fusion/Core to phpstan level 8 (Neos 8.3)
Browse files Browse the repository at this point in the history
Only files in `Neos.Fusion/Classes/Core` have been migrated, as they contain relatively new code like the parser.

Two kind of errors have been partially ignored from the level 8

For one: "no value type specified in iterable type array" as adding `array<int|string, mixed>` would just bloat this commit up. In these files we are mostly dealing with the fusion configuration which is highly dynamic:

- 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

And "has no return type specified" was noticed a lot in the ast visiting code. But i plan to refactor this instead to something better type able:

- Neos.Fusion/Classes/Core/ObjectTreeParser/MergedArrayTreeVisitor.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/AstNodeVisitorInterface.php
- Neos.Fusion/Classes/Core/ObjectTreeParser/Ast
  • Loading branch information
mhsdesign committed Jan 24, 2024
1 parent e62bd1e commit d0377b9
Show file tree
Hide file tree
Showing 51 changed files with 105 additions and 138 deletions.
5 changes: 3 additions & 2 deletions Neos.Fusion/Classes/Core/Cache/CacheSegmentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +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? */
$remainingContent = $this->extractContent($currentPosition, $nextEndPosition);
$segmentData['content'] .= $remainingContent;
$segmentData['cleanContent'] .= $remainingContent;
Expand Down Expand Up @@ -234,7 +235,7 @@ protected function reduceSegmentDataToCacheRelevantInformation(array $segmentDat

/**
* @param integer $fromPosition
* @param integer $toPosition
* @param integer|null $toPosition
* @return string
*/
protected function extractContent($fromPosition, $toPosition = null)
Expand Down Expand Up @@ -263,7 +264,7 @@ protected function calculateCurrentPosition($position)
*
* @param integer $currentPosition The position to start searching from
* @param string $token the token to search for (will internally be appeneded by the randomCacheMarker)
* @return integer|boolean Position of the token or false if the token was not found
* @return integer|false Position of the token or false if the token was not found
*/
protected function calculateNextTokenPosition($currentPosition, $token)
{
Expand Down
5 changes: 3 additions & 2 deletions Neos.Fusion/Classes/Core/Cache/ContentCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public function processCacheSegments($content, $storeCacheEntries = true)
* @param string $fusionPath Fusion path identifying the Fusion object to retrieve from the content cache
* @param array $cacheIdentifierValues Further values which play into the cache identifier hash, must be the same as the ones specified while the cache entry was written
* @param boolean $addCacheSegmentMarkersToPlaceholders If cache segment markers should be added – this makes sense if the cached segment is about to be included in a not-yet-cached segment
* @param string|bool $cacheDiscriminator The evaluated cache discriminator value, if any and false if the cache discriminator is disabled for the current context
* @return string|boolean The segment with replaced cache placeholders, or false if a segment was missing in the cache
* @param string|false $cacheDiscriminator The evaluated cache discriminator value, if any and false if the cache discriminator is disabled for the current context
* @return string|false The segment with replaced cache placeholders, or false if a segment was missing in the cache
* @throws Exception
*/
public function getCachedSegment($uncachedCommandCallback, $fusionPath, $cacheIdentifierValues, $addCacheSegmentMarkersToPlaceholders = false, $cacheDiscriminator = null)
Expand Down Expand Up @@ -361,6 +361,7 @@ protected function getTypeForContextValue($contextValue)
{
if (is_object($contextValue)) {
if ($contextValue instanceof Proxy) {
/** @var string $type */
$type = get_parent_class($contextValue);
} else {
$type = get_class($contextValue);
Expand Down
4 changes: 2 additions & 2 deletions Neos.Fusion/Classes/Core/Cache/FileMonitorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function __construct(CacheManager $flowCacheManager)
}

/**
* @param $fileMonitorIdentifier
* @param array $changedFiles
* @param string $fileMonitorIdentifier
* @param array<string, int> $changedFiles
* @return void
*/
public function flushContentCacheOnFileChanges($fileMonitorIdentifier, array $changedFiles)
Expand Down
3 changes: 3 additions & 0 deletions Neos.Fusion/Classes/Core/Cache/ParserCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Neos\Flow\Annotations as Flow;
use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Package\FlowPackageInterface;
use Neos\Flow\Package\PackageManager;
use Neos\Fusion\Core\ObjectTreeParser\Ast\FusionFile;
use Neos\Utility\Unicode\Functions as UnicodeFunctions;
Expand Down Expand Up @@ -44,6 +45,7 @@ class ParserCache

/**
* @Flow\InjectConfiguration(path="enableParsePartialsCache")
* @var boolean
*/
protected $enableCache;

Expand Down Expand Up @@ -105,6 +107,7 @@ private function getAbsolutePathForPackageRessourceUri(string $requestedPath): s
throw new \InvalidArgumentException("Unsupported stream wrapper: '$requestedPath'");
}

/** @var FlowPackageInterface $package */
$package = $this->packageManager->getPackage($resourceUriParts['host']);
return Files::concatenatePaths([$package->getResourcesPath(), $resourceUriParts['path']]);
}
Expand Down
4 changes: 2 additions & 2 deletions Neos.Fusion/Classes/Core/Cache/ParserCacheFlusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(CacheManager $flowCacheManager)
}

/**
* @param $fileMonitorIdentifier
* @param array $changedFiles
* @param string $fileMonitorIdentifier
* @param array<string, int> $changedFiles
* @return void
*/
public function flushPartialCacheOnFileChanges($fileMonitorIdentifier, array $changedFiles)
Expand Down
2 changes: 1 addition & 1 deletion Neos.Fusion/Classes/Core/Cache/RuntimeContentCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RuntimeContentCache
protected $enableContentCache = false;

/**
* @var boolean
* @var boolean|null
*/
protected $inCacheEntryPoint = null;

Expand Down
4 changes: 2 additions & 2 deletions Neos.Fusion/Classes/Core/DslFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DslFactory
{
/**
* @Flow\InjectConfiguration("dsl")
* @var
* @var array<string, class-string<DslInterface>>|null
*/
protected $dslSettings;

Expand All @@ -36,7 +36,7 @@ class DslFactory
*/
public function create(string $identifier): DslInterface
{
if (isset($this->dslSettings) && is_array($this->dslSettings) && isset($this->dslSettings[$identifier])) {
if (is_array($this->dslSettings) && isset($this->dslSettings[$identifier])) {
$dslObjectName = $this->dslSettings[$identifier];
if (!class_exists($dslObjectName)) {
throw new Fusion\Exception(sprintf('The fusion dsl-object %s was not found.', $dslObjectName), 1490776462);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AbsorbingHandler 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 @@ -64,6 +64,7 @@ public function handleRenderingException($fusionPath, \Exception $exception)
}
if ($exception instanceof Exceptions\RuntimeException) {
$fusionPath = $exception->getFusionPath();
/** @var \Exception $exception */
$exception = $exception->getPrevious();
}
if ($this->exceptionDisablesCache($fusionPath, $exception)) {
Expand All @@ -78,7 +79,7 @@ public function handleRenderingException($fusionPath, \Exception $exception)
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @param string|null $referenceCode
* @return string
*/
abstract protected function handle($fusionPath, \Exception $exception, $referenceCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BubblingHandler extends AbstractRenderingExceptionHandler
/**
* Handle an Exception thrown while rendering Fusion
*
* @param array $fusionPath
* @param string $fusionPath
* @param \Exception $exception
* @return string
* @throws StopActionException
Expand All @@ -44,11 +44,12 @@ public function handleRenderingException($fusionPath, \Exception $exception)
*
* @param string $fusionPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @return void
* @param string|null $referenceCode
* @return string
*/
protected function handle($fusionPath, \Exception $exception, $referenceCode)
{
// nothing to be done here, as this method is normally called in "handleRenderingException()", which was overridden above.
throw new \BadMethodCallException('Never called.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class ContextDependentHandler extends AbstractRenderingExceptionHandler
/**
* Handle an exception depending on the context with an HTML message or XML comment
*
* @param array $fusionPath path causing the exception
* @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 @@ -40,15 +40,15 @@ class HtmlMessageHandler extends AbstractRenderingExceptionHandler
/**
* @param LoggerInterface $logger
*/
public function injectLogger(LoggerInterface $logger)
public function injectLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}

/**
* @param ThrowableStorageInterface $throwableStorage
*/
public function injectThrowableStorage(ThrowableStorageInterface $throwableStorage)
public function injectThrowableStorage(ThrowableStorageInterface $throwableStorage): void
{
$this->throwableStorage = $throwableStorage;
}
Expand All @@ -66,7 +66,7 @@ public function __construct(bool $renderTechnicalDetails = true)
*
* @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 Expand Up @@ -96,7 +96,7 @@ protected function handle($fusionPath, \Exception $exception, $referenceCode)
* Renders a message depicting the user where to find further information
* for the given reference code.
*
* @param integer $referenceCode
* @param string $referenceCode
* @return string A rendered message with the reference code containing HTML
*/
protected function formatErrorCodeMessage($referenceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ThrowingHandler extends AbstractRenderingExceptionHandler
/**
* Handle an Exception thrown while rendering Fusion
*
* @param array $fusionPath
* @param string $fusionPath
* @param \Exception $exception
* @return string
* @throws StopActionException
Expand All @@ -39,7 +39,7 @@ public function handleRenderingException($fusionPath, \Exception $exception)
*
* @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 @@ -33,15 +33,15 @@ class XmlCommentHandler extends AbstractRenderingExceptionHandler
/**
* @param LoggerInterface $logger
*/
public function injectLogger(LoggerInterface $logger)
public function injectLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}

/**
* @param ThrowableStorageInterface $throwableStorage
*/
public function injectThrowableStorage(ThrowableStorageInterface $throwableStorage)
public function injectThrowableStorage(ThrowableStorageInterface $throwableStorage): void
{
$this->throwableStorage = $throwableStorage;
}
Expand Down
19 changes: 14 additions & 5 deletions Neos.Fusion/Classes/Core/FusionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@
*/
final class FusionConfiguration
{
/** @internal */
/**
* @internal
* @param array<int|string, mixed> $fusionConfiguration
*/
protected function __construct(
private array $fusionConfiguration
) {
}

/** @internal */
public static function fromArray(array $fusionConfiguration)
/**
* @internal
* @param array<int|string, mixed> $fusionConfiguration
*/
public static function fromArray(array $fusionConfiguration): self
{
return new static($fusionConfiguration);
}

/** @internal */
public function toArray()
/**
* @internal
* @return array<int|string, mixed>
*/
public function toArray(): array
{
return $this->fusionConfiguration;
}
Expand Down
9 changes: 6 additions & 3 deletions Neos.Fusion/Classes/Core/FusionSourceCodeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
* source code.
*/

/** @api */
/**
* @implements \IteratorAggregate<int, FusionSourceCode>
* @api
*/
final class FusionSourceCodeCollection implements \IteratorAggregate, \Countable
{
/** @var array<int, FusionSourceCode> */
Expand Down Expand Up @@ -49,7 +52,7 @@ public static function tryFromPackageRootFusion(string $packageKey): self
return static::tryFromFilePath($fusionPathAndFilename);
}

public static function empty()
public static function empty(): self
{
return new static();
}
Expand All @@ -71,7 +74,7 @@ public function count(): int
}

/**
* @param array<int, FusionSourceCode> $fusionSourceCode
* @param array<int|string, FusionSourceCode> $fusionSourceCode
* @return array<int, FusionSourceCode>
*/
private static function deduplicateItemsAndKeepLast(array $fusionSourceCode): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
#[Flow\Proxy(false)]
abstract class AbstractNode
{
abstract public function visit(AstNodeVisitorInterface $visitor, ...$args);
abstract public function visit(AstNodeVisitorInterface $visitor, mixed ...$args);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
) {
}

public function visit(AstNodeVisitorInterface $visitor, ...$args)
public function visit(AstNodeVisitorInterface $visitor, mixed ...$args)
{
return $visitor->visitAssignedObjectPath($this, ...$args);
}
Expand Down
2 changes: 1 addition & 1 deletion Neos.Fusion/Classes/Core/ObjectTreeParser/Ast/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
) {
}

public function visit(AstNodeVisitorInterface $visitor, ...$args)
public function visit(AstNodeVisitorInterface $visitor, mixed ...$args)
{
return $visitor->visitBlock($this, ...$args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
) {
}

public function visit(AstNodeVisitorInterface $visitor, ...$args)
public function visit(AstNodeVisitorInterface $visitor, mixed ...$args)
{
return $visitor->visitBoolValue($this, ...$args);
}
Expand Down
32 changes: 0 additions & 32 deletions Neos.Fusion/Classes/Core/ObjectTreeParser/Ast/CharValue.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
) {
}

public function visit(AstNodeVisitorInterface $visitor, ...$args)
public function visit(AstNodeVisitorInterface $visitor, mixed ...$args)
{
return $visitor->visitDslExpressionValue($this, ...$args);
}
Expand Down

0 comments on commit d0377b9

Please sign in to comment.