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

TASK: Phpstan level 2 for Flow 8.3 and ignore to be fixed things #3264

Merged
merged 4 commits into from
Jan 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
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ jobs:
git -C ../${{ env.FLOW_FOLDER }} checkout -b build
composer config repositories.flow '{ "type": "path", "url": "../${{ env.FLOW_FOLDER }}", "options": { "symlink": false } }'
composer require --no-update neos/flow-development-collection:"dev-build as ${{ env.FLOW_BRANCH_ALIAS }}"
# todo remove temporary hack ;) (sorry - if i forget)
composer require --no-update --dev "phpstan/phpstan:^1.10.0"

- name: Cache Composer packages
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Psr/Cache/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function expiresAt(?\DateTimeInterface $expiration): static

/**
* @param \DateInterval|int|null $time
* @return CacheItem|static
* @return static
*/
public function expiresAfter(int|\DateInterval|null $time): static
{
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Psr/SimpleCache/SimpleCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(string $identifier, BackendInterface $backend)
*
* @param string $key An identifier used for this cache entry
* @param mixed $value The variable to cache
* @param null|int|\DateInterval $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @param null|int|\DateInterval $ttl Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @return bool
*
* @throws Exception
Expand Down
4 changes: 3 additions & 1 deletion Neos.Eel/Classes/CompilingEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ protected function evaluateAndUnwrap(\closure $expressionFunction, Context $cont
*/
protected function generateEvaluatorCode($expression)
{
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line `CompilingEelParser` has been explicitly excluded from analysis, because it contains generated code that is impossible to fix */
$parser = new CompilingEelParser($expression);
$result = $parser->match_Expression();

if ($result === false) {
throw new ParserException(sprintf('Expression "%s" could not be parsed.', $expression), 1344513194);
/** @phpstan-ignore-next-line $parser->pos appears to be undeclared, because instantiation of $parser is hidden as well */
} elseif ($parser->pos !== strlen($expression)) {
/** @phpstan-ignore-next-line $parser->pos appears to be undeclared, because instantiation of $parser is hidden as well */
throw new ParserException(sprintf('Expression "%s" could not be parsed. Error starting at character %d: "%s".', $expression, $parser->pos, substr($expression, $parser->pos)), 1327682383);
} elseif (!array_key_exists('code', $result)) {
throw new ParserException(sprintf('Parser error, no code in result %s ', json_encode($result)), 1334491498);
Expand Down
2 changes: 1 addition & 1 deletion Neos.Eel/Classes/FlowQuery/OperationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function isFinal();
* can work with the $context objects. It can be implemented
* to implement runtime conditions.
*
* @param array (or array-like object) $context onto which this operation should be applied
* @param array $context (or array-like object) $context onto which this operation should be applied
* @return boolean true if the operation can be applied onto the $context, false otherwise
* @api
*/
Expand Down
2 changes: 1 addition & 1 deletion Neos.Eel/Classes/FlowQuery/OperationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function buildOperationsAndFinalOperationNames($objectManager)

$reflectionService = $objectManager->get(ReflectionService::class);
$operationClassNames = $reflectionService->getAllImplementationClassNamesForInterface(OperationInterface::class);
/** @var $operationClassName OperationInterface */
/** @var OperationInterface $operationClassName */
foreach ($operationClassNames as $operationClassName) {
$shortOperationName = $operationClassName::getShortName();
$operationPriority = $operationClassName::getPriority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function getShortName()
/**
* {@inheritdoc}
*
* @param array (or array-like object) $context onto which this operation should be applied
* @param array $context (or array-like object) $context onto which this operation should be applied
* @return boolean true if the operation can be applied onto the $context, false otherwise
* @api
*/
Expand Down
2 changes: 1 addition & 1 deletion Neos.Eel/Classes/Helper/MathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getSQRT2()
* @param float $x A number
* @return float The absolute value of the given value
*/
public function abs($x = 'NAN')
public function abs($x = NAN)
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
{
if (!is_numeric($x) && $x !== null) {
return NAN;
Expand Down
5 changes: 5 additions & 0 deletions Neos.Eel/Classes/InterpretedEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public function evaluate($expression, Context $context)

if ($res === false) {
throw new ParserException(sprintf('Expression "%s" could not be parsed.', $expression), 1344514198);
/**
* @phpstan-ignore-next-line $parser->pos appears to be undeclared, because it is declared up in the parent class chain of `InterpretedEelParser`,
* wherein multiple classes (e.g. `EelParser` and `AbstractEelParser`) are explicitly excluded from analysis, because they contain generated code that is impossible to fix
*/
} elseif ($parser->pos !== strlen($expression)) {
/** @phpstan-ignore-next-line $parser->pos appears to be undeclared see comment above. */
throw new ParserException(sprintf('Expression "%s" could not be parsed. Error starting at character %d: "%s".', $expression, $parser->pos, substr($expression, $parser->pos)), 1344514188);
} elseif (!array_key_exists('val', $res)) {
throw new ParserException(sprintf('Parser error, no val in result %s ', json_encode($res)), 1344514204);
Expand Down
2 changes: 2 additions & 0 deletions Neos.Eel/Classes/Validation/ExpressionSyntaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ protected function isValid($value)

if ($result === false) {
$this->addError('Expression "%s" could not be parsed.', 1421940748, [$value]);
/** @phpstan-ignore-next-line */
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
} elseif ($parser->pos !== strlen($value)) {
/** @phpstan-ignore-next-line */
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
$this->addError('Expression "%s" could not be parsed. Error starting at character %d: "%s".', 1421940760, [$value, $parser->pos, substr($value, $parser->pos)]);
}
}
Expand Down
1 change: 0 additions & 1 deletion Neos.Error.Messages/Classes/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ public function merge(Result $otherResult)
$this->mergeProperty($otherResult, 'getNotices', 'addNotice');
}

/** @var $subResult Result */
foreach ($otherResult->getSubResults() as $subPropertyName => $subResult) {
if (array_key_exists($subPropertyName, $this->propertyResults) && $this->propertyResults[$subPropertyName]->hasMessages()) {
$this->forProperty($subPropertyName)->merge($subResult);
Expand Down
3 changes: 0 additions & 3 deletions Neos.Flow/Classes/Annotations/Inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ final class Inject
*/
public $name;

/**
* @param array $values
*/
public function __construct(?string $name = null, bool $lazy = true)
{
$this->lazy = $lazy;
Expand Down
5 changes: 4 additions & 1 deletion Neos.Flow/Classes/Aop/Advice/AdviceChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Aop\ProxyInterface as InternalAopProxyInterface;

/**
* The advice chain holds a number of subsequent advices that
Expand Down Expand Up @@ -56,7 +57,9 @@ public function proceed(JoinPointInterface &$joinPoint)
if ($this->adviceIndex < count($this->advices)) {
$result = $this->advices[$this->adviceIndex]->invoke($joinPoint);
} else {
$result = $joinPoint->getProxy()->Flow_Aop_Proxy_invokeJoinpoint($joinPoint);
/** @var InternalAopProxyInterface $proxy */
$proxy = $joinPoint->getProxy();
$result = $proxy->Flow_Aop_Proxy_invokeJoinpoint($joinPoint);
}
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow/Classes/Aop/Builder/ProxyClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function buildProxyClass(string $targetClassName, array &$aspectContainer
$proxyClass->addInterfaces($introducedInterfaces);
$proxyClass->addTraits($introducedTraits);

/** @var $propertyIntroduction PropertyIntroduction */
/** @var PropertyIntroduction $propertyIntroduction */
foreach ($propertyIntroductions as $propertyIntroduction) {
$propertyName = $propertyIntroduction->getPropertyName();
$declaringAspectClassName = $propertyIntroduction->getDeclaringAspectClassName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ protected function parseDesignatorMethod(string $operator, string $signaturePatt
$classNameFilter = new PointcutClassNameFilter($classPattern);
$classNameFilter->injectReflectionService($this->reflectionService);
$methodNameFilter = new PointcutMethodNameFilter($methodNamePattern, $methodVisibility, $methodArgumentConstraints);
/** @var LoggerInterface $logger */
$logger = $this->objectManager->get(PsrLoggerFactoryInterface::class)->get('systemLogger');
$methodNameFilter->injectLogger($logger);
$methodNameFilter->injectReflectionService($this->reflectionService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Neos\Cache\Frontend\StringFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Cache\CacheManager;
Expand Down
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Cli/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class Response
private $content = '';

/**
* @var
* @var bool|int
*/
private $colorSupport;

/**
* @var
* @var int
*/
private $outputFormat = self::OUTPUTFORMAT_STYLED;

Expand Down
4 changes: 0 additions & 4 deletions Neos.Flow/Classes/Command/ConfigurationCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\ConfigurationSchemaValidator;
use Neos\Flow\Configuration\Exception\SchemaValidationException;
use Neos\Error\Messages\Error;
use Neos\Error\Messages\Notice;
use Neos\Utility\Arrays;
use Neos\Utility\SchemaGenerator;

Expand Down Expand Up @@ -155,7 +153,6 @@ public function validateCommand(string $type = null, string $path = null, bool $
if ($result->hasNotices()) {
$notices = $result->getFlattenedNotices();
$this->outputLine('<b>%d notices:</b>', [count($notices)]);
/** @var Notice $notice */
foreach ($notices as $path => $pathNotices) {
foreach ($pathNotices as $notice) {
$this->outputLine(' - %s -> %s', [$path, $notice->render()]);
Expand All @@ -168,7 +165,6 @@ public function validateCommand(string $type = null, string $path = null, bool $
if ($result->hasErrors()) {
$errors = $result->getFlattenedErrors();
$this->outputLine('<b>%d errors were found:</b>', [count($errors)]);
/** @var Error $error */
foreach ($errors as $path => $pathErrors) {
foreach ($pathErrors as $error) {
$this->outputLine(' - %s -> %s', [$path, $error->render()]);
Expand Down
2 changes: 0 additions & 2 deletions Neos.Flow/Classes/Command/MiddlewareCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Mvc\Routing\Route;
use Neos\Utility\PositionalArraySorter;

/**
Expand All @@ -36,7 +35,6 @@ public function listCommand(): void
$this->outputLine('<b>Currently configured middlewares:</b>');
$rows = [];
$index = 0;
/** @var Route $route */
foreach ($orderedChainConfiguration->toArray() as $middlewareName => $middlewareConfiguration) {
$rows[] = [
'#' => ++ $index,
Expand Down
8 changes: 4 additions & 4 deletions Neos.Flow/Classes/Command/ResourceCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\ResourceManagement\ResourceRepository;
use Neos\Media\Domain\Repository\AssetRepository;

use Neos\Media\Domain\Repository\ThumbnailRepository;

/**
Expand Down Expand Up @@ -98,6 +97,7 @@ public function publishCommand(string $collection = null)
/** @var CollectionInterface $collection */
$this->outputLine('Publishing resources of collection "%s"', [$collection->getName()]);
$target = $collection->getTarget();
/** @phpstan-ignore-next-line will be fixed via https://github.com/neos/flow-development-collection/pull/3229 */
$target->publishCollection($collection, function ($iteration) {
$this->clearState($iteration);
});
Expand Down Expand Up @@ -232,13 +232,13 @@ public function cleanCommand()
$assetRepository = class_exists(AssetRepository::class) ? $this->objectManager->get(AssetRepository::class) : null;
/* @var ThumbnailRepository|null $thumbnailRepository */
$thumbnailRepository = class_exists(ThumbnailRepository::class) ? $this->objectManager->get(ThumbnailRepository::class) : null;
$mediaPackagePresent = $assetRepository && $thumbnailRepository && $this->packageManager->isPackageAvailable('Neos.Media');
$mediaPackagePresent = $this->packageManager->isPackageAvailable('Neos.Media');

if (count($brokenResources) > 0) {
foreach ($brokenResources as $key => $resourceIdentifier) {
$resource = $this->resourceRepository->findByIdentifier($resourceIdentifier);
$brokenResources[$key] = $resource;
if ($mediaPackagePresent) {
if ($mediaPackagePresent && $assetRepository !== null && $thumbnailRepository !== null) {
$assets = $assetRepository->findByResource($resource);
if ($assets !== null) {
$relatedAssets[$resource] = $assets;
Expand Down Expand Up @@ -280,7 +280,7 @@ public function cleanCommand()
]);
$resource->disableLifecycleEvents();
$this->resourceRepository->remove($resource);
if ($mediaPackagePresent) {
if ($mediaPackagePresent && $assetRepository !== null && $thumbnailRepository !== null) {
if (isset($relatedAssets[$resource])) {
foreach ($relatedAssets[$resource] as $asset) {
$assetRepository->removeWithoutUsageChecks($asset);
Expand Down
4 changes: 0 additions & 4 deletions Neos.Flow/Classes/Command/SchemaCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Cli\CommandController;
use Neos\Error\Messages\Error;
use Neos\Error\Messages\Notice;
use Neos\Utility\SchemaValidator;
use Symfony\Component\Yaml\Yaml;
use Neos\Utility\Files;
Expand Down Expand Up @@ -80,7 +78,6 @@ public function validateCommand(string $configurationFile = null, string $schema
if ($result->hasNotices()) {
$notices = $result->getFlattenedNotices();
$this->outputLine('<b>%d notices:</b>', [count($notices)]);
/** @var Notice $notice */
foreach ($notices as $path => $pathNotices) {
foreach ($pathNotices as $notice) {
$this->outputLine(' - %s -> %s', [$path, $notice->render()]);
Expand All @@ -93,7 +90,6 @@ public function validateCommand(string $configurationFile = null, string $schema
if ($result->hasErrors()) {
$errors = $result->getFlattenedErrors();
$this->outputLine('<b>%d errors were found:</b>', [count($errors)]);
/** @var Error $error */
foreach ($errors as $path => $pathErrors) {
foreach ($pathErrors as $error) {
$this->outputLine(' - %s -> %s', [$path, $error->render()]);
Expand Down
13 changes: 9 additions & 4 deletions Neos.Flow/Classes/Core/Booting/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Neos\Flow\ObjectManagement\ObjectManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\Package\FlowPackageInterface;
use Neos\Flow\Package\GenericPackage;
use Neos\Flow\Package\PackageManager;
use Neos\Flow\Reflection\ReflectionService;
use Neos\Flow\Reflection\ReflectionServiceFactory;
Expand Down Expand Up @@ -577,8 +578,10 @@ public static function initializeSystemFileMonitor(Bootstrap $bootstrap)
if (!in_array($packageKey, $packagesWithConfiguredObjects)) {
continue;
}
foreach ($package->getAutoloadPaths() as $autoloadPath) {
self::monitorDirectoryIfItExists($fileMonitors['Flow_ClassFiles'], $autoloadPath, '\.php$');
if ($package instanceof GenericPackage) {
foreach ($package->getAutoloadPaths() as $autoloadPath) {
self::monitorDirectoryIfItExists($fileMonitors['Flow_ClassFiles'], $autoloadPath, '\.php$');
}
}

// Note that getFunctionalTestsPath is currently not part of any interface... We might want to add it or find a better way.
Expand All @@ -602,8 +605,10 @@ public static function initializeSystemFileMonitor(Bootstrap $bootstrap)
*/
protected static function getListOfPackagesWithConfiguredObjects(Bootstrap $bootstrap): array
{
$objectManager = $bootstrap->getEarlyInstance(ObjectManagerInterface::class);
$packagesWithConfiguredObjects = array_reduce($objectManager->getAllObjectConfigurations(), function ($foundPackages, $item) {
$objectManager = $bootstrap->getObjectManager();
/** @phpstan-ignore-next-line the object manager interface doesn't specify this method */
$allObjectConfigurations = $objectManager->getAllObjectConfigurations();
$packagesWithConfiguredObjects = array_reduce($allObjectConfigurations, function ($foundPackages, $item) {
if (isset($item['p']) && !in_array($item['p'], $foundPackages)) {
$foundPackages[] = $item['p'];
}
Expand Down
4 changes: 3 additions & 1 deletion Neos.Flow/Classes/Http/Client/InternalRequestEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ public function sendRequest(RequestInterface $httpRequest): ResponseInterface
}

$requestHandler = $this->bootstrap->getActiveRequestHandler();
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line composer doesnt autoload this class */
if (!$requestHandler instanceof FunctionalTestRequestHandler) {
throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
}

/** @phpstan-ignore-next-line composer doesnt autoload this class */
$requestHandler->setHttpRequest($httpRequest);
$this->securityContext->clearContext();
$this->validatorResolver->reset();
Expand All @@ -142,6 +143,7 @@ public function sendRequest(RequestInterface $httpRequest): ResponseInterface
*/
$middlewaresChain = $objectManager->get(Http\Middleware\MiddlewaresChain::class);
$middlewaresChain->onStep(function (ServerRequestInterface $request) use ($requestHandler) {
/** @phpstan-ignore-next-line composer doesnt autoload this class */
$requestHandler->setHttpRequest($request);
});

Expand Down
2 changes: 2 additions & 0 deletions Neos.Flow/Classes/I18n/Xliff/Service/XliffReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function readFiles($sourcePath, callable $iterator)
$reader->open($sourcePath);
$reader->read();

/** @var object|\XMLReader $reader the stubs for XMLReader are wrong https://github.com/phpstan/phpstan/issues/8629 */
if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name === 'xliff') {
$version = $reader->getAttribute('version');
$result = true;
Expand Down Expand Up @@ -66,6 +67,7 @@ public function readFiles($sourcePath, callable $iterator)
*/
protected function isFileNode(\XMLReader $reader)
{
/** @var object|\XMLReader $reader the stubs for XMLReader are wrong https://github.com/phpstan/phpstan/issues/8629 */
return $reader->nodeType === \XMLReader::ELEMENT && $reader->name === 'file';
}
}
1 change: 0 additions & 1 deletion Neos.Flow/Classes/Log/ThrowableStorage/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ protected function cleanupThrowableDumps(): void
if ($this->maximumThrowableDumpAge > 0) {
$cutoffTime = time() - $this->maximumThrowableDumpAge;

/** @var \SplFileInfo $directoryEntry */
$iterator = new \DirectoryIterator($this->storagePath);
foreach ($iterator as $directoryEntry) {
if ($directoryEntry->isFile() && $directoryEntry->getCTime() < $cutoffTime) {
Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow/Classes/Mvc/Controller/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* A composite of controller arguments
*
* @api
* @extends \ArrayObject<Argument>
* @extends \ArrayObject<string, Argument>
*/
class Arguments extends \ArrayObject
{
Expand Down
Loading
Loading