From e4daf09fcd8d433e0331f8a6b4ac59cf2d2ef8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= <stefan@buerk.tech> Date: Thu, 27 Jun 2024 23:18:49 +0200 Subject: [PATCH] [TASK] Avoid implicitly nullable class method parameter in `EXT:form` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With PHP 8.4 marking method parameter implicitly nullable is deprecated and will emit a `E_DEPRECATED` warning. One recommended way to resolve this, is making it explicitly nullable using the `?` nullable operator or adding a null tyype to an union type definition. [1] This prepares the way towards PHP 8.4 compatibility. [1] https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated Resolves: #104238 Releases: main, 12.4, 11.5 Change-Id: I340f35379b74d1ca05527a6950eab5ba66ffaae6 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84978 Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Stefan Bürk <stefan@buerk.tech> --- .../form/Classes/Controller/FormEditorController.php | 4 ++-- .../FormDefinition/Validators/ValidationDto.php | 12 ++++++------ .../form/Classes/Domain/Factory/ArrayFormFactory.php | 2 +- .../Classes/Domain/Factory/FormFactoryInterface.php | 2 +- .../form/Classes/Domain/Model/FormDefinition.php | 2 +- .../Domain/Runtime/FormRuntime/FormSession.php | 2 +- .../Mvc/Configuration/ConfigurationManager.php | 2 +- .../TypeConverter/FormDefinitionArrayConverter.php | 2 +- .../TypeConverter/UploadedFileReferenceConverter.php | 6 +++--- .../form/Classes/Service/TranslationService.php | 12 ++++++------ .../sysext/form/Classes/Slot/FilePersistenceSlot.php | 8 ++++---- .../ViewHelpers/Form/TimePickerViewHelper.php | 4 ++-- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/typo3/sysext/form/Classes/Controller/FormEditorController.php b/typo3/sysext/form/Classes/Controller/FormEditorController.php index c0b17e3200e6..c163b1d227c2 100644 --- a/typo3/sysext/form/Classes/Controller/FormEditorController.php +++ b/typo3/sysext/form/Classes/Controller/FormEditorController.php @@ -86,7 +86,7 @@ class FormEditorController extends AbstractBackendController * @throws PersistenceManagerException * @internal */ - public function indexAction(string $formPersistenceIdentifier, string $prototypeName = null): ResponseInterface + public function indexAction(string $formPersistenceIdentifier, ?string $prototypeName = null): ResponseInterface { if (!$this->formPersistenceManager->isAllowedPersistencePath($formPersistenceIdentifier)) { throw new PersistenceManagerException(sprintf('Read "%s" is not allowed', $formPersistenceIdentifier), 1614500662); @@ -256,7 +256,7 @@ class FormEditorController extends AbstractBackendController public function renderFormPageAction( FormDefinitionArray $formDefinition, int $pageIndex, - string $prototypeName = null + ?string $prototypeName = null ): ResponseInterface { $prototypeName = $prototypeName ?: $formDefinition['prototypeName'] ?? 'standard'; $formDefinition = $formDefinition->getArrayCopy(); diff --git a/typo3/sysext/form/Classes/Domain/Configuration/FormDefinition/Validators/ValidationDto.php b/typo3/sysext/form/Classes/Domain/Configuration/FormDefinition/Validators/ValidationDto.php index f2ddd520c5e3..899cd17456c1 100644 --- a/typo3/sysext/form/Classes/Domain/Configuration/FormDefinition/Validators/ValidationDto.php +++ b/typo3/sysext/form/Classes/Domain/Configuration/FormDefinition/Validators/ValidationDto.php @@ -60,12 +60,12 @@ class ValidationDto * @param string $propertyCollectionElementIdentifier */ public function __construct( - string $prototypeName = null, - string $formElementType = null, - string $formElementIdentifier = null, - string $propertyPath = null, - string $propertyCollectionName = null, - string $propertyCollectionElementIdentifier = null + ?string $prototypeName = null, + ?string $formElementType = null, + ?string $formElementIdentifier = null, + ?string $propertyPath = null, + ?string $propertyCollectionName = null, + ?string $propertyCollectionElementIdentifier = null ) { $this->prototypeName = $prototypeName; $this->formElementType = $formElementType; diff --git a/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php b/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php index ba62b7b657a9..d6700ac36545 100644 --- a/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php +++ b/typo3/sysext/form/Classes/Domain/Factory/ArrayFormFactory.php @@ -46,7 +46,7 @@ class ArrayFormFactory extends AbstractFormFactory * @throws RenderingException * @internal */ - public function build(array $configuration, string $prototypeName = null): FormDefinition + public function build(array $configuration, ?string $prototypeName = null): FormDefinition { if (empty($prototypeName)) { $prototypeName = $configuration['prototypeName'] ?? 'standard'; diff --git a/typo3/sysext/form/Classes/Domain/Factory/FormFactoryInterface.php b/typo3/sysext/form/Classes/Domain/Factory/FormFactoryInterface.php index 08aca7b329f6..dab0d5240fc8 100644 --- a/typo3/sysext/form/Classes/Domain/Factory/FormFactoryInterface.php +++ b/typo3/sysext/form/Classes/Domain/Factory/FormFactoryInterface.php @@ -45,5 +45,5 @@ interface FormFactoryInterface * @param string $prototypeName The name of the "PrototypeName" to use; it is factory-specific to implement this. * @return FormDefinition a newly built form definition */ - public function build(array $configuration, string $prototypeName = null): FormDefinition; + public function build(array $configuration, ?string $prototypeName = null): FormDefinition; } diff --git a/typo3/sysext/form/Classes/Domain/Model/FormDefinition.php b/typo3/sysext/form/Classes/Domain/Model/FormDefinition.php index 19916151654b..12475c8b816d 100644 --- a/typo3/sysext/form/Classes/Domain/Model/FormDefinition.php +++ b/typo3/sysext/form/Classes/Domain/Model/FormDefinition.php @@ -302,7 +302,7 @@ class FormDefinition extends AbstractCompositeRenderable implements VariableRend string $identifier, array $prototypeConfiguration = [], string $type = 'Form', - string $persistenceIdentifier = null + ?string $persistenceIdentifier = null ) { $this->typeDefinitions = $prototypeConfiguration['formElementsDefinition'] ?? []; $this->validatorsDefinition = $prototypeConfiguration['validatorsDefinition'] ?? []; diff --git a/typo3/sysext/form/Classes/Domain/Runtime/FormRuntime/FormSession.php b/typo3/sysext/form/Classes/Domain/Runtime/FormRuntime/FormSession.php index 73fe89bfbdc0..5c799687da79 100644 --- a/typo3/sysext/form/Classes/Domain/Runtime/FormRuntime/FormSession.php +++ b/typo3/sysext/form/Classes/Domain/Runtime/FormRuntime/FormSession.php @@ -37,7 +37,7 @@ class FormSession * @param string|null $authenticatedIdentifier * @throws BadRequestException */ - public function __construct(string $authenticatedIdentifier = null) + public function __construct(?string $authenticatedIdentifier = null) { if ($authenticatedIdentifier === null) { $this->identifier = $this->generateIdentifier(); diff --git a/typo3/sysext/form/Classes/Mvc/Configuration/ConfigurationManager.php b/typo3/sysext/form/Classes/Mvc/Configuration/ConfigurationManager.php index 4eab55ee23c2..0904af00ec40 100644 --- a/typo3/sysext/form/Classes/Mvc/Configuration/ConfigurationManager.php +++ b/typo3/sysext/form/Classes/Mvc/Configuration/ConfigurationManager.php @@ -60,7 +60,7 @@ class ConfigurationManager extends ExtbaseConfigurationManager implements Config * @return array The configuration * @internal */ - public function getConfiguration(string $configurationType, string $extensionName = null, string $pluginName = null): array + public function getConfiguration(string $configurationType, ?string $extensionName = null, ?string $pluginName = null): array { switch ($configurationType) { case self::CONFIGURATION_TYPE_YAML_SETTINGS: diff --git a/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/FormDefinitionArrayConverter.php b/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/FormDefinitionArrayConverter.php index 02c4f63f4b56..2b16739eef56 100644 --- a/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/FormDefinitionArrayConverter.php +++ b/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/FormDefinitionArrayConverter.php @@ -66,7 +66,7 @@ class FormDefinitionArrayConverter extends AbstractTypeConverter * @return FormDefinitionArray * @throws PropertyException */ - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) + public function convertFrom($source, $targetType, array $convertedChildProperties = [], ?PropertyMappingConfigurationInterface $configuration = null) { $rawFormDefinitionArray = json_decode($source, true); diff --git a/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php b/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php index 3f855af40355..1514169fc7a0 100644 --- a/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php +++ b/typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php @@ -153,7 +153,7 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter * @return AbstractFileFolder|Error|null * @internal */ - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) + public function convertFrom($source, $targetType, array $convertedChildProperties = [], ?PropertyMappingConfigurationInterface $configuration = null) { // slot/listener using `FileDumpController` instead of direct public URL in (later) rendering process $resourcePublicationSlot = GeneralUtility::makeInstance(ResourcePublicationSlot::class); @@ -263,7 +263,7 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter */ protected function createFileReferenceFromFalFileObject( File $file, - int $resourcePointer = null + ?int $resourcePointer = null ): PseudoFileReference { $fileReference = $this->resourceFactory->createFileReferenceObject( [ @@ -287,7 +287,7 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter */ protected function createFileReferenceFromFalFileReferenceObject( CoreFileReference $falFileReference, - int $resourcePointer = null + ?int $resourcePointer = null ): PseudoFileReference { if ($resourcePointer === null) { $fileReference = GeneralUtility::makeInstance(PseudoFileReference::class); diff --git a/typo3/sysext/form/Classes/Service/TranslationService.php b/typo3/sysext/form/Classes/Service/TranslationService.php index 3766da58d9b1..16a4dfc01378 100644 --- a/typo3/sysext/form/Classes/Service/TranslationService.php +++ b/typo3/sysext/form/Classes/Service/TranslationService.php @@ -107,9 +107,9 @@ class TranslationService implements SingletonInterface */ public function translate( $key, - array $arguments = null, - string $locallangPathAndFilename = null, - string $language = null, + ?array $arguments = null, + ?string $locallangPathAndFilename = null, + ?string $language = null, $defaultValue = '' ) { $value = null; @@ -219,7 +219,7 @@ class TranslationService implements SingletonInterface */ public function translateToAllBackendLanguages( string $key, - array $arguments = null, + ?array $arguments = null, array $translationFiles = [] ): array { $result = []; @@ -546,8 +546,8 @@ class TranslationService implements SingletonInterface */ protected function processTranslationChain( array $translationKeyChain, - string $language = null, - array $arguments = null + ?string $language = null, + ?array $arguments = null ) { $translatedValue = null; foreach ($translationKeyChain as $translationKey) { diff --git a/typo3/sysext/form/Classes/Slot/FilePersistenceSlot.php b/typo3/sysext/form/Classes/Slot/FilePersistenceSlot.php index a56cc3e0f3e1..9d46d0933002 100644 --- a/typo3/sysext/form/Classes/Slot/FilePersistenceSlot.php +++ b/typo3/sysext/form/Classes/Slot/FilePersistenceSlot.php @@ -71,7 +71,7 @@ final class FilePersistenceSlot implements SingletonInterface * @param string $command * @param bool|null $type */ - public function defineInvocation(string $command, bool $type = null) + public function defineInvocation(string $command, ?bool $type = null) { $this->definedInvocations[$command] = $type; if ($type === null) { @@ -93,7 +93,7 @@ final class FilePersistenceSlot implements SingletonInterface public function allowInvocation( string $command, string $combinedFileIdentifier, - string $contentSignature = null + ?string $contentSignature = null ): bool { $index = $this->searchAllowedInvocation( $command, @@ -218,7 +218,7 @@ final class FilePersistenceSlot implements SingletonInterface protected function assertFileName( string $command, string $combinedFileIdentifier, - string $content = null + ?string $content = null ): void { if (!$this->isFormDefinition($combinedFileIdentifier)) { return; @@ -271,7 +271,7 @@ final class FilePersistenceSlot implements SingletonInterface protected function searchAllowedInvocation( string $command, string $combinedFileIdentifier, - string $contentSignature = null + ?string $contentSignature = null ): ?int { foreach ($this->allowedInvocations as $index => $allowedInvocation) { if ( diff --git a/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php index fe418d9122e9..9df8ea523205 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php @@ -126,7 +126,7 @@ class TimePickerViewHelper extends AbstractFormFieldViewHelper * @param \DateTime $date * @return string */ - protected function buildHourSelector(\DateTime $date = null): string + protected function buildHourSelector(?\DateTime $date = null): string { $value = $date !== null ? $date->format('H') : null; $hourSelector = clone $this->tag; @@ -145,7 +145,7 @@ class TimePickerViewHelper extends AbstractFormFieldViewHelper * @param \DateTime $date * @return string */ - protected function buildMinuteSelector(\DateTime $date = null): string + protected function buildMinuteSelector(?\DateTime $date = null): string { $value = $date !== null ? $date->format('i') : null; $minuteSelector = clone $this->tag; -- GitLab