Skip to content

Commit

Permalink
[TASK] Apply code cleanup
Browse files Browse the repository at this point in the history
* 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 <no-reply@typo3.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
waldhacker1 authored and lolli42 committed Mar 12, 2018
1 parent ba35a50 commit 8481521
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 45 deletions.
14 changes: 6 additions & 8 deletions typo3/sysext/form/Classes/Controller/FormEditorController.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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();
}

Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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'
Expand All @@ -73,7 +73,7 @@ public function getInsertRenderablesPanelConfigurationReturnsGroupedAndSortedCon
->method('translate')
->willReturnArgument(4);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -171,7 +171,7 @@ public function getFormEditorDefinitionsReturnReducedConfiguration()
->method('translateValuesRecursive')
->willReturnArgument(0);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down
Expand Up @@ -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'
Expand All @@ -134,7 +134,7 @@ public function getFormManagerAppInitialDataReturnsProcessedArray()
->method('translateValuesRecursive')
->willReturnArgument(0);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down
Expand Up @@ -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'
Expand All @@ -162,7 +162,7 @@ public function parseOptionReturnsValueFromFormRuntimeIfOptionNameReferenceAForm
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -211,7 +211,7 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -261,7 +261,7 @@ public function parseOptionReturnsNoReplacedValueFromFormRuntimeIfOptionNameRefe
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -310,7 +310,7 @@ public function parseOptionReturnsDefaultOptionValueIfOptionNameNotExistsWithinO
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -359,7 +359,7 @@ public function parseOptionReturnsDefaultOptionValueIfOptionValueIsAFormElementR
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down Expand Up @@ -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'
Expand All @@ -411,7 +411,7 @@ public function parseOptionReturnsTimestampIfOptionValueIsATimestampRequestTrigg
->method('translateFinisherOption')
->willReturnArgument(3);

$objectMangerProphecy
$objectManagerProphecy
->get(TranslationService::class)
->willReturn($mockTranslationService);

Expand Down
Expand Up @@ -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]);
Expand Down
12 changes: 6 additions & 6 deletions typo3/sysext/form/Tests/Unit/Mvc/ProcessingRuleTest.php
Expand Up @@ -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());

Expand All @@ -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);

Expand Down

0 comments on commit 8481521

Please sign in to comment.