Skip to content

Commit

Permalink
TASK: Backport phpstan level 2 to Flow 8.3 and ignore to be fixed things
Browse files Browse the repository at this point in the history
Flow 9 Pr neos#3217
  • Loading branch information
mhsdesign committed Jan 17, 2024
1 parent 10c08ff commit 883ad0b
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 20 deletions.
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
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
5 changes: 3 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 boolean|int
*/
private $colorSupport;

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

Expand Down Expand Up @@ -118,6 +118,7 @@ public function getContent(): string
/**
* Sets color support / styled output to yes, no or auto detection
*
* @deprecated and will be removed https://github.com/neos/flow-development-collection/pull/3262
* @param boolean $colorSupport true, false or NULL (= autodetection)
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions Neos.Flow/Classes/Command/ResourceCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/I18n/Xliff/Service/XliffReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function readFiles($sourcePath, callable $iterator)
$reader->open($sourcePath);
$reader->read();

/** @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/8629 */
/** @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 @@ -67,7 +67,7 @@ public function readFiles($sourcePath, callable $iterator)
*/
protected function isFileNode(\XMLReader $reader)
{
/** @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/8629 */
/** @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/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function boot(Core\Bootstrap $bootstrap)
if (!$request instanceof Mvc\ActionRequest || SecurityHelper::hasSafeMethod($request->getHttpRequest()) !== true) {
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAll();
} elseif (SecurityHelper::hasSafeMethod($request->getHttpRequest())) {
/** @phpstan-ignore-next-line the persistence manager interface doesn't specify this method */
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAllowedObjects();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function generateValueHash(JoinPointInterface $joinPoint)
*/
public function cloneObject(JoinPointInterface $joinPoint)
{
/** @phpstan-ignore-next-line will be removed with https://github.com/neos/flow-development-collection/pull/3223 */
$joinPoint->getProxy()->Flow_Persistence_clone = true;
}
}
8 changes: 4 additions & 4 deletions Neos.Flow/Classes/Persistence/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ public function getConstraint()
* @return object
* @api
*/
public function logicalAnd(mixed $constraint1, mixed ...$constraints)
public function logicalAnd($constraint1)
{
if (is_array($constraint1)) {
$constraints = $constraint1;
} else {
$constraints = [$constraint1, ...$constraints];
$constraints = func_get_args();
}
return $this->queryBuilder->expr()->andX(...$constraints);
}
Expand All @@ -440,12 +440,12 @@ public function logicalAnd(mixed $constraint1, mixed ...$constraints)
* @return object
* @api
*/
public function logicalOr(mixed $constraint1, mixed ...$constraints)
public function logicalOr($constraint1)
{
if (is_array($constraint1)) {
$constraints = $constraint1;
} else {
$constraints = [$constraint1, ...$constraints];
$constraints = func_get_args();
}
return $this->queryBuilder->expr()->orX(...$constraints);
}
Expand Down
8 changes: 4 additions & 4 deletions Neos.Flow/Classes/Persistence/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,22 @@ public function getConstraint();
* takes one or more constraints and concatenates them with a boolean AND.
* It also accepts a single array of constraints to be concatenated.
*
* @param mixed $constraint1 The first of multiple constraints or an array of constraints.
* @param mixed ...$constraint1 The first of multiple constraints or an array of constraints.
* @return object
* @api
*/
public function logicalAnd(mixed $constraint1, mixed ...$constraints);
public function logicalAnd($constraint1);

/**
* Performs a logical disjunction of the two given constraints. The method
* takes one or more constraints and concatenates them with a boolean OR.
* It also accepts a single array of constraints to be concatenated.
*
* @param mixed $constraint1 The first of multiple constraints or an array of constraints.
* @param mixed ...$constraint1 The first of multiple constraints or an array of constraints.
* @return object
* @api
*/
public function logicalOr(mixed $constraint1, mixed ...$constraints);
public function logicalOr($constraint1);

/**
* Performs a logical negation of the given constraint
Expand Down
9 changes: 5 additions & 4 deletions Neos.Flow/Classes/Reflection/ReflectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public function setStatusCache(StringFrontend $cache)
$this->statusCache = $cache;
$backend = $this->statusCache->getBackend();
if (is_callable(['initializeObject', $backend])) {
/** @phpstan-ignore-next-line will be refactored with neos 9 */
$backend->initializeObject();
}
}
Expand Down Expand Up @@ -1282,12 +1283,10 @@ protected function reflectClass($className)
$this->classReflectionData[$className][self::DATA_CLASS_FINAL] = true;
}

/** @var $parentClass ClassReflection */
foreach ($this->getParentClasses($class) as $parentClass) {
$this->addParentClass($className, $parentClass);
}

/** @var $interface ClassReflection */
foreach ($class->getInterfaces() as $interface) {
$this->addImplementedInterface($className, $interface);
}
Expand All @@ -1308,7 +1307,6 @@ protected function reflectClass($className)
}
}

/** @var $property PropertyReflection */
foreach ($class->getProperties() as $property) {
$this->reflectClassProperty($className, $property);
}
Expand Down Expand Up @@ -1877,6 +1875,7 @@ protected function convertParameterReflectionToArray(ParameterReflection $parame
$parameterInformation[self::DATA_PARAMETER_ALLOWS_NULL] = true;
}

/** @var \ReflectionNamedType|\ReflectionUnionType|\ReflectionIntersectionType|null $parameterType */
$parameterType = $parameter->getType();
if ($parameterType !== null) {
if ($parameterType instanceof \ReflectionUnionType) {
Expand Down Expand Up @@ -1940,7 +1939,6 @@ static function (\ReflectionNamedType $type) {
protected function forgetChangedClasses()
{
$frozenNamespaces = [];
/** @var $package Package */
foreach ($this->packageManager->getAvailablePackages() as $packageKey => $package) {
if ($this->packageManager->isPackageFrozen($packageKey)) {
$frozenNamespaces = array_merge($frozenNamespaces, $package->getNamespaces());
Expand Down Expand Up @@ -2259,7 +2257,9 @@ protected function saveProductionData()
$this->reflectionDataRuntimeCache->set('__classNames', $classNames);
$this->reflectionDataRuntimeCache->set('__annotatedClasses', $this->annotatedClasses);

/** @phpstan-ignore-next-line will be refactored with neos 9 */
$this->reflectionDataRuntimeCache->getBackend()->freeze();
/** @phpstan-ignore-next-line will be refactored with neos 9 */
$this->classSchemataRuntimeCache->getBackend()->freeze();

$this->log(sprintf('Built and froze reflection runtime caches (%s classes).', count($this->classReflectionData)), LogLevel::INFO);
Expand Down Expand Up @@ -2343,6 +2343,7 @@ protected function getPrecompiledReflectionStoragePath()
*/
protected function hasFrozenCacheInProduction()
{
/** @phpstan-ignore-next-line will be refactored with neos 9 */
return $this->environment->getContext()->isProduction() && $this->reflectionDataRuntimeCache->getBackend()->isFrozen();
}
}
1 change: 1 addition & 0 deletions Neos.Flow/Classes/ResourceManagement/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function getObjects(callable $callback = null)
}
}
} else {
/** @phpstan-ignore-next-line will be fixed via https://github.com/neos/flow-development-collection/pull/3229 */
yield from $this->storage->getObjectsByCollection($this, $callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public function publishCollection(CollectionInterface $collection, callable $cal
{
$storage = $collection->getStorage();
$this->checkAndRemovePackageSymlinks($storage);
/** @phpstan-ignore-next-line will be fixed via https://github.com/neos/flow-development-collection/pull/3229 */
foreach ($collection->getObjects($callback) as $object) {
/** @var StorageObject $object */
$sourceStream = $object->getStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function setDefaultPackageKey($defaultPackageKey)
*/
public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState)
{
/** @var $node TextNode */
/** @var TextNode $node */
if (strpos($node->getText(), 'Public/') === false) {
return $node;
}
Expand Down
1 change: 1 addition & 0 deletions Neos.FluidAdaptor/Classes/View/TemplatePaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ protected function getPackagePrivateResourcesPath($packageKey)
if (!$this->packageManager->isPackageAvailable($packageKey)) {
return null;
}
/** @phpstan-ignore-next-line this code will be dropped totally as its unused */
$packageResourcesPath = $this->packageManager->getPackage($packageKey)->getResourcesPath();

return Files::concatenatePaths([$packageResourcesPath, 'Private']);
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
parameters:
level: 2
ignoreErrors:
# https://github.com/phpstan/phpstan/issues/9467 will be fixed with flow 9
- '#^Method Neos\\Flow\\Persistence\\QueryInterface\:\:logicalOr\(\) invoked with \d parameters, 1 required\.$#'
- '#^Method Neos\\Flow\\Persistence\\QueryInterface\:\:logicalAnd\(\) invoked with \d parameters, 1 required\.$#'
paths:
- Neos.Cache/Classes
- Neos.Eel/Classes
Expand Down

0 comments on commit 883ad0b

Please sign in to comment.