From 848152106858d56cc383d9ec439bcefd9c403e0a Mon Sep 17 00:00:00 2001 From: Ralf Zimmermann Date: Fri, 9 Mar 2018 18:28:25 +0100 Subject: [PATCH] [TASK] Apply code cleanup * Reapply usage of null coalescing operator from review:54810 that have been lost by the revert review:55422 * Prevent E_NOTICES within InheritancesResolverService * Fix typos in unit tests Releases: master Resolves: #84189 Change-Id: If77ff3eddf51fa821314800cebaaf76d482b22e7 Reviewed-on: https://review.typo3.org/56080 Tested-by: TYPO3com Reviewed-by: Oliver Klee Reviewed-by: Joerg Boesche Reviewed-by: Susanne Moog Tested-by: Susanne Moog Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../Controller/FormEditorController.php | 14 ++++---- .../InheritancesResolverService.php | 3 +- .../Controller/FormEditorControllerTest.php | 12 +++---- .../Controller/FormManagerControllerTest.php | 6 ++-- .../Domain/Finishers/AbstractFinisherTest.php | 36 +++++++++---------- .../Hooks/DataStructureIdentifierHookTest.php | 6 ++-- .../Tests/Unit/Mvc/ProcessingRuleTest.php | 12 +++---- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/typo3/sysext/form/Classes/Controller/FormEditorController.php b/typo3/sysext/form/Classes/Controller/FormEditorController.php index cf60953b6415..0fa2b387e320 100644 --- a/typo3/sysext/form/Classes/Controller/FormEditorController.php +++ b/typo3/sysext/form/Classes/Controller/FormEditorController.php @@ -72,11 +72,10 @@ public function indexAction(string $formPersistenceIdentifier, string $prototype throw new PersistenceManagerException('Edit a extension formDefinition is not allowed.', 1478265661); } + $prototypeName = $prototypeName ?: $formDefinition['prototypeName'] ?? 'standard'; $formDefinition = $this->formPersistenceManager->load($formPersistenceIdentifier); $formDefinition = ArrayUtility::stripTagsFromValuesRecursive($formDefinition); - if (empty($prototypeName)) { - $prototypeName = $formDefinition['prototypeName'] ?? 'standard'; - } + $formDefinition['prototypeName'] = $prototypeName; $configurationService = $this->objectManager->get(ConfigurationService::class); @@ -152,6 +151,7 @@ public function initializeSaveFormAction() public function saveFormAction(string $formPersistenceIdentifier, FormDefinitionArray $formDefinition) { $formDefinition = $formDefinition->getArrayCopy(); + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeFormSave'] ?? [] as $className) { $hookObj = GeneralUtility::makeInstance($className); if (method_exists($hookObj, 'beforeFormSave')) { @@ -196,15 +196,14 @@ public function saveFormAction(string $formPersistenceIdentifier, FormDefinition */ public function renderFormPageAction(FormDefinitionArray $formDefinition, int $pageIndex, string $prototypeName = null): string { - if (empty($prototypeName)) { - $prototypeName = $formDefinition['prototypeName'] ?? 'standard'; - } + $prototypeName = $prototypeName ?: $formDefinition['prototypeName'] ?? 'standard'; $formFactory = $this->objectManager->get(ArrayFormFactory::class); $formDefinition = $formFactory->build($formDefinition->getArrayCopy(), $prototypeName); $formDefinition->setRenderingOption('previewMode', true); $form = $formDefinition->bind($this->request, $this->response); $form->overrideCurrentPage($pageIndex); + return $form->render(); } @@ -217,7 +216,6 @@ public function renderFormPageAction(FormDefinitionArray $formDefinition, int $p */ protected function getInsertRenderablesPanelConfiguration(array $formElementsDefinition): array { - $formElementGroups = $this->prototypeConfiguration['formEditor']['formElementGroups'] ?? []; $formElementsByGroup = []; foreach ($formElementsDefinition as $formElementName => $formElementConfiguration) { @@ -243,7 +241,7 @@ protected function getInsertRenderablesPanelConfiguration(array $formElementsDef } $formGroups = []; - foreach ($formElementGroups as $groupName => $groupConfiguration) { + foreach ($this->prototypeConfiguration['formEditor']['formElementGroups'] ?? [] as $groupName => $groupConfiguration) { if (!isset($formElementsByGroup[$groupName])) { continue; } diff --git a/typo3/sysext/form/Classes/Mvc/Configuration/InheritancesResolverService.php b/typo3/sysext/form/Classes/Mvc/Configuration/InheritancesResolverService.php index 10edf3d67f0d..7a9118f95903 100644 --- a/typo3/sysext/form/Classes/Mvc/Configuration/InheritancesResolverService.php +++ b/typo3/sysext/form/Classes/Mvc/Configuration/InheritancesResolverService.php @@ -302,7 +302,8 @@ protected function throwExceptionIfCycleInheritances(string $path, string $pathT } if ( - is_array($this->inheritanceStack[$pathToCheck]) + isset($this->inheritanceStack[$pathToCheck]) + && is_array($this->inheritanceStack[$pathToCheck]) && in_array($inheritancePath, $this->inheritanceStack[$pathToCheck]) ) { $this->inheritanceStack[$pathToCheck][] = $inheritancePath; diff --git a/typo3/sysext/form/Tests/Unit/Controller/FormEditorControllerTest.php b/typo3/sysext/form/Tests/Unit/Controller/FormEditorControllerTest.php index 36b04820d41a..5a5f9515fc56 100644 --- a/typo3/sysext/form/Tests/Unit/Controller/FormEditorControllerTest.php +++ b/typo3/sysext/form/Tests/Unit/Controller/FormEditorControllerTest.php @@ -61,8 +61,8 @@ public function getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedCon 'dummy' ], [], '', false); - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translate' @@ -73,7 +73,7 @@ public function getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedCon ->method('translate') ->willReturnArgument(4); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -159,8 +159,8 @@ public function getFormEditorDefinitionsReturnReducedConfiguration() 'dummy' ], [], '', false); - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateValuesRecursive' @@ -171,7 +171,7 @@ public function getFormEditorDefinitionsReturnReducedConfiguration() ->method('translateValuesRecursive') ->willReturnArgument(0); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); diff --git a/typo3/sysext/form/Tests/Unit/Controller/FormManagerControllerTest.php b/typo3/sysext/form/Tests/Unit/Controller/FormManagerControllerTest.php index e77bea73c987..b8fb4eb7d8c6 100644 --- a/typo3/sysext/form/Tests/Unit/Controller/FormManagerControllerTest.php +++ b/typo3/sysext/form/Tests/Unit/Controller/FormManagerControllerTest.php @@ -122,8 +122,8 @@ public function getAccessibleFormStorageFoldersReturnsProcessedArray() */ public function getFormManagerAppInitialDataReturnsProcessedArray() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateValuesRecursive' @@ -134,7 +134,7 @@ public function getFormManagerAppInitialDataReturnsProcessedArray() ->method('translateValuesRecursive') ->willReturnArgument(0); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); diff --git a/typo3/sysext/form/Tests/Unit/Domain/Finishers/AbstractFinisherTest.php b/typo3/sysext/form/Tests/Unit/Domain/Finishers/AbstractFinisherTest.php index 714416431652..63e20d47a1d2 100644 --- a/typo3/sysext/form/Tests/Unit/Domain/Finishers/AbstractFinisherTest.php +++ b/typo3/sysext/form/Tests/Unit/Domain/Finishers/AbstractFinisherTest.php @@ -150,8 +150,8 @@ public function parseOptionReturnsBoolOptionValuesAsBool() */ public function parseOptionReturnsValueFromFormRuntimeIfOptionNameReferenceAFormElementIdentifierWhoseValueIsAString() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -162,7 +162,7 @@ public function parseOptionReturnsValueFromFormRuntimeIfOptionNameReferenceAForm ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -199,8 +199,8 @@ public function parseOptionReturnsValueFromFormRuntimeIfOptionNameReferenceAForm */ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameReferenceAFormElementIdentifierWhoseValueIsNotAString() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -211,7 +211,7 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -249,8 +249,8 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe */ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameReferenceANonExistingFormElement() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -261,7 +261,7 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -298,8 +298,8 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe */ public function parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinOptionsButWithinDefaultOptions() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -310,7 +310,7 @@ public function parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinO ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -347,8 +347,8 @@ public function parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinO */ public function parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementReferenceAndTheFormElementValueIsEmpty() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -359,7 +359,7 @@ public function parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementR ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); @@ -399,8 +399,8 @@ public function parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementR */ public function parseOptionReturnsTimestampIfOptionValueIsATimestampRequestTrigger() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $mockTranslationService = $this->getAccessibleMock(TranslationService::class, [ 'translateFinisherOption' @@ -411,7 +411,7 @@ public function parseOptionReturnsTimestampIfOptionValueIsATimestampRequestTrigg ->method('translateFinisherOption') ->willReturnArgument(3); - $objectMangerProphecy + $objectManagerProphecy ->get(TranslationService::class) ->willReturn($mockTranslationService); diff --git a/typo3/sysext/form/Tests/Unit/Hooks/DataStructureIdentifierHookTest.php b/typo3/sysext/form/Tests/Unit/Hooks/DataStructureIdentifierHookTest.php index 005463d29370..738a61a081de 100644 --- a/typo3/sysext/form/Tests/Unit/Hooks/DataStructureIdentifierHookTest.php +++ b/typo3/sysext/form/Tests/Unit/Hooks/DataStructureIdentifierHookTest.php @@ -183,10 +183,10 @@ public function parseDataStructureByIdentifierPostProcessReturnsDataStructureUnc */ public function parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem) { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManager::class); - $objectMangerProphecy->get(FormPersistenceManagerInterface::class) + $objectManagerProphecy->get(FormPersistenceManagerInterface::class) ->willReturn($formPersistenceManagerProphecy->reveal()); $formPersistenceManagerProphecy->listForms()->shouldBeCalled()->willReturn([$formDefinition]); diff --git a/typo3/sysext/form/Tests/Unit/Mvc/ProcessingRuleTest.php b/typo3/sysext/form/Tests/Unit/Mvc/ProcessingRuleTest.php index ac8217fe64e4..aae41df16109 100644 --- a/typo3/sysext/form/Tests/Unit/Mvc/ProcessingRuleTest.php +++ b/typo3/sysext/form/Tests/Unit/Mvc/ProcessingRuleTest.php @@ -71,11 +71,11 @@ public function addValidatorAddValidator() */ public function processNoPropertyMappingReturnsNotModifiedValue() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); $resultProphecy = $this->prophesize(Result::class); - $objectMangerProphecy + $objectManagerProphecy ->get(Result::class) ->willReturn($resultProphecy->reveal()); @@ -96,10 +96,10 @@ public function processNoPropertyMappingReturnsNotModifiedValue() */ public function processNoPropertyMappingAndHasErrorsIfValidatorContainsErrors() { - $objectMangerProphecy = $this->prophesize(ObjectManager::class); - GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal()); + $objectManagerProphecy = $this->prophesize(ObjectManager::class); + GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal()); - $objectMangerProphecy + $objectManagerProphecy ->get(Result::class) ->willReturn(new Result);