From 6bbc133504ca71772d0f079bdbdf7b58348a23bc Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Fri, 6 Sep 2024 16:33:17 +0200 Subject: [PATCH] TASK: Add and enforce `strict_type` declarations Adds a ``` declare(strict_types=1); ``` declaration to all PHP files of the core that were missing one and implements & defines a new PHPStan rule to enforce them from now on Related: #5239 --- .../src/ContentGraphFactory.php | 2 + .../src/ContentGraphTableNames.php | 2 + .../DoctrineDbalContentGraphSchemaBuilder.php | 2 + ...tegrityViolationDetectionRunnerFactory.php | 2 + .../src/NodeQueryBuilder.php | 2 + .../src/ContentHyperGraphFactory.php | 2 + .../SchemaBuilder/HypergraphSchemaBuilder.php | 2 + .../Projection/SchemaBuilder/JsonbType.php | 2 + .../SchemaBuilder/UuidArrayType.php | 2 + .../Projection/SchemaBuilder/UuidType.php | 2 + .../SchemaBuilder/VarcharArrayType.php | 2 + .../PhpstanRules/DeclareStrictTypesRule.php | 47 +++++++++++++++++++ ...ntentRepositoryServiceFactoryInterface.php | 2 + .../ContentRepositoryServiceInterface.php | 2 + .../ProjectionsAndCatchUpHooksFactory.php | 2 + .../Dto/NodeAggregateIdMapping.php | 2 + .../Classes/NodeType/ConstraintCheck.php | 2 + .../Projection/CatchUpHookInterface.php | 3 +- .../Projection/CheckpointStorageStatus.php | 2 + .../Projection/DelegatingCatchUpHook.php | 2 + .../Classes/Projection/ProjectionStatus.php | 2 + .../Projection/ProjectionStatusType.php | 2 + .../Classes/Projection/ProjectionStatuses.php | 2 + .../Projection/Workspace/WorkspaceStatus.php | 2 + .../NodeAggregateCurrentlyDoesNotExist.php | 2 + .../NodeAggregateCurrentlyExists.php | 2 + .../Exception/NodeAggregateIsAmbiguous.php | 2 + .../Exception/NodeAggregateIsDescendant.php | 2 + .../Exception/NodeAggregateIsNotRoot.php | 2 + .../Exception/NodeAggregateIsRoot.php | 2 + .../Exception/NodeAggregateIsTethered.php | 2 + .../Exception/NodeNameIsAlreadyCovered.php | 2 + .../Exception/NodeTypeIsAbstract.php | 2 + .../Exception/NodeTypeIsNotOfTypeRoot.php | 2 + .../Exception/NodeTypeIsOfTypeRoot.php | 2 + ...eWorkspaceContentStreamExistsException.php | 2 + .../BackReferenceNodesOperation.php | 3 ++ .../BackReferencesOperation.php | 3 ++ .../FlowQueryOperations/ChildrenOperation.php | 3 ++ .../FlowQueryOperations/ClosestOperation.php | 3 ++ .../FlowQueryOperations/FilterOperation.php | 3 ++ .../FlowQueryOperations/FindOperation.php | 3 ++ .../FlowQueryOperations/HasOperation.php | 3 ++ .../FlowQueryOperations/IdOperation.php | 3 ++ .../FlowQueryOperations/LabelOperation.php | 3 ++ .../FlowQueryOperations/NextAllOperation.php | 3 ++ .../FlowQueryOperations/NextOperation.php | 3 ++ .../NextUntilOperation.php | 3 ++ .../NodeTypeNameOperation.php | 3 ++ .../FlowQueryOperations/ParentOperation.php | 3 ++ .../FlowQueryOperations/ParentsOperation.php | 3 ++ .../ParentsUntilOperation.php | 3 ++ .../FlowQueryOperations/PrevAllOperation.php | 3 ++ .../FlowQueryOperations/PrevOperation.php | 3 ++ .../PrevUntilOperation.php | 2 + .../FlowQueryOperations/PropertyOperation.php | 3 ++ .../ReferenceNodesOperation.php | 3 ++ .../ReferencePropertyOperation.php | 3 ++ .../ReferencesOperation.php | 3 ++ .../FlowQueryOperations/RemoveOperation.php | 3 ++ .../FlowQueryOperations/SiblingsOperation.php | 3 ++ .../FlowQueryOperations/UniqueOperation.php | 3 ++ .../ContentStreamCommandController.php | 3 ++ .../NodeMigrationCommandController.php | 2 + .../Command/NodeTypesCommandController.php | 2 + .../ContentRepositoryNotFoundException.php | 3 ++ .../InvalidConfigurationException.php | 3 ++ .../Migration/Configuration/Configuration.php | 3 ++ .../Configuration/ConfigurationInterface.php | 3 ++ .../Configuration/YamlConfiguration.php | 3 ++ .../Migration/Factory/MigrationFactory.php | 2 + .../Classes/Package.php | 2 + .../Service/NodeMigrationGeneratorService.php | 2 + .../Classes/Core/Cache/CacheSegmentParser.php | 3 ++ .../Classes/Core/Cache/ContentCache.php | 3 ++ .../Core/Cache/FileMonitorListener.php | 3 ++ .../Core/Cache/RuntimeContentCache.php | 3 ++ Neos.Fusion/Classes/Core/DslInterface.php | 3 ++ .../ExceptionHandlers/AbsorbingHandler.php | 3 ++ .../AbstractRenderingExceptionHandler.php | 3 ++ .../ExceptionHandlers/BubblingHandler.php | 3 ++ .../ContextDependentHandler.php | 3 ++ .../ExceptionHandlers/HtmlMessageHandler.php | 3 ++ .../ExceptionHandlers/PlainTextHandler.php | 3 ++ .../ExceptionHandlers/ThrowingHandler.php | 3 ++ .../ExceptionHandlers/XmlCommentHandler.php | 3 ++ Neos.Fusion/Classes/Core/Runtime.php | 3 ++ Neos.Fusion/Classes/Core/RuntimeFactory.php | 3 ++ .../Domain/Service/AssetSourceService.php | 2 +- .../Classes/Controller/Backend/MenuHelper.php | 2 + .../Module/User/UserSettingsController.php | 4 +- .../ExpressionBasedNodeLabelGenerator.php | 2 + .../Service/FusionConfigurationCache.php | 2 + .../CatchUpHook/RouterCacheHook.php | 2 + .../CatchUpHook/RouterCacheHookFactory.php | 2 + .../DocumentUriPathSchemaBuilder.php | 2 + ...ctorCatchUpHookForCacheFlushingFactory.php | 2 + .../Classes/Fusion/Helper/BackendHelper.php | 2 + Neos.Neos/Classes/Service/XliffService.php | 4 +- Neos.Neos/Classes/Utility/User.php | 2 + .../ViewHelpers/Node/LabelViewHelper.php | 2 + .../DataSource/FormDefinitionDataSource.php | 3 ++ ...imeableNodeVisibilityCommandController.php | 2 + .../Classes/Domain/ChangedVisibilities.php | 2 + .../Classes/Domain/ChangedVisibility.php | 2 + .../Service/TimeableNodeVisibilityService.php | 2 + phpstan.neon.dist | 1 + 107 files changed, 306 insertions(+), 4 deletions(-) create mode 100644 Neos.ContentRepository.BehavioralTests/Classes/PhpstanRules/DeclareStrictTypesRule.php diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php index 2599353780a..5f1b45b09a5 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphFactory.php @@ -1,5 +1,7 @@ + */ +class DeclareStrictTypesRule implements Rule +{ + public function getNodeType(): string + { + return FileNode::class; + } + + public function processNode(Node $node, Scope $scope): array + { + assert($node instanceof FileNode); + $nodes = $node->getNodes(); + if (0 === \count($nodes)) { + return []; + } + $firstNode = \array_shift($nodes); + + if ($firstNode instanceof Node\Stmt\Declare_) { + foreach ($firstNode->declares as $declare) { + if ( + $declare->value instanceof Node\Scalar\LNumber + && $declare->key->toLowerString() === 'strict_types' + && $declare->value->value === 1 + ) { + return []; + } + } + } + + return [ + 'File is missing a "declare(strict_types=1)" declaration.', + ]; + } +} diff --git a/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryServiceFactoryInterface.php b/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryServiceFactoryInterface.php index 3d6923659e0..fdcb1bf7d39 100644 --- a/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryServiceFactoryInterface.php +++ b/Neos.ContentRepository.Core/Classes/Factory/ContentRepositoryServiceFactoryInterface.php @@ -1,5 +1,7 @@ userService->updateUser($user); $this->addFlashMessage( - $this->translator->translateById('userSettings.electronicAddressRemoved.body', [htmlspecialchars($electronicAddress->getIdentifier()), htmlspecialchars($electronicAddress->getType()), htmlspecialchars($user->getName())], null, null, 'Modules', 'Neos.Neos'), + $this->translator->translateById('userSettings.electronicAddressRemoved.body', [htmlspecialchars($electronicAddress->getIdentifier()), htmlspecialchars($electronicAddress->getType()), htmlspecialchars((string)$user->getName())], null, null, 'Modules', 'Neos.Neos'), $this->translator->translateById('userSettings.electronicAddressRemoved.title', [], null, null, 'Modules', 'Neos.Neos'), Message::SEVERITY_NOTICE, [], diff --git a/Neos.Neos/Classes/Domain/NodeLabel/ExpressionBasedNodeLabelGenerator.php b/Neos.Neos/Classes/Domain/NodeLabel/ExpressionBasedNodeLabelGenerator.php index ae6c9a291bc..95ff8df9655 100644 --- a/Neos.Neos/Classes/Domain/NodeLabel/ExpressionBasedNodeLabelGenerator.php +++ b/Neos.Neos/Classes/Domain/NodeLabel/ExpressionBasedNodeLabelGenerator.php @@ -1,5 +1,7 @@ xliffToJsonTranslationsCache->has($cacheIdentifier)) { $json = $this->xliffToJsonTranslationsCache->get($cacheIdentifier); diff --git a/Neos.Neos/Classes/Utility/User.php b/Neos.Neos/Classes/Utility/User.php index 9ecaaf1d110..5275452f696 100644 --- a/Neos.Neos/Classes/Utility/User.php +++ b/Neos.Neos/Classes/Utility/User.php @@ -1,5 +1,7 @@