[TASK] Use native array_replace_recursive implementation 72/55672/2
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Mon, 29 Jan 2018 13:56:45 +0000 (14:56 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Mon, 12 Feb 2018 13:55:12 +0000 (14:55 +0100)
The custom implementation of array_replace_recursive in YamlSource
has been replaced with the native PHP version of the same method.

Resolves: #83860
Releases: master, 8.7
Change-Id: Ibc0c9ea55e7a510b84c39689890f51bfa01ebafa
Reviewed-on: https://review.typo3.org/55672
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/form/Classes/Mvc/Configuration/YamlSource.php
typo3/sysext/form/Tests/Unit/Mvc/Configuration/YamlSourceTest.php

index 944f9fd..fcd84c2 100644 (file)
@@ -105,7 +105,7 @@ class YamlSource
                 }
 
                 if (is_array($loadedConfiguration)) {
-                    $this->mergeRecursiveWithOverrule($configuration, $loadedConfiguration);
+                    $configuration = array_replace_recursive($configuration, $loadedConfiguration);
                 }
             } catch (ParseException $exception) {
                 throw new ParseErrorException(
@@ -182,28 +182,4 @@ class YamlSource
         }
         return $header;
     }
-
-    /**
-     * The differences to the existing PHP function array_merge_recursive() are:
-     *  * If the original value is an array and the overrule value is something else
-     *    (like null) the overrule value is used.
-     *    (TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule does not do this)
-     *
-     * @param array $original Original array. It will be *modified* by this method and contains the result afterwards!
-     * @param array $overrule Overrule array, overruling the original array
-     */
-    protected function mergeRecursiveWithOverrule(array &$original, array $overrule)
-    {
-        foreach ($overrule as $key => $_) {
-            if (isset($original[$key]) && is_array($original[$key])) {
-                if (is_array($overrule[$key])) {
-                    $this->mergeRecursiveWithOverrule($original[$key], $overrule[$key]);
-                } else {
-                    $original[$key] = $overrule[$key];
-                }
-            } else {
-                $original[$key] = $overrule[$key];
-            }
-        }
-    }
 }
index ec830f5..695c3b6 100644 (file)
@@ -126,113 +126,4 @@ class YamlSourceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
 
         $this->assertSame($expected, $mockYamlSource->_call('load', $input));
     }
-
-    /**
-     * @return array
-     */
-    public function mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider()
-    {
-        return [
-            'Override array can reset string to array' => [
-                [
-                    'first' => [
-                        'second' => 'foo',
-                    ],
-                ],
-                [
-                    'first' => [
-                        'second' => ['third' => 'bar'],
-                    ],
-                ],
-                [
-                    'first' => [
-                        'second' => ['third' => 'bar'],
-                    ],
-                ],
-            ],
-            'Override array does reset array to string' => [
-                [
-                    'first' => [],
-                ],
-                [
-                    'first' => 'foo',
-                ],
-                [
-                    'first' => 'foo', // Note that ArrayUtility::mergeRecursiveWithOverrule returns [] here
-                ],
-            ],
-            'Override array does override null with string' => [
-                [
-                    'first' => null,
-                ],
-                [
-                    'first' => 'foo',
-                ],
-                [
-                    'first' => 'foo',
-                ],
-            ],
-            'Override array does override null with empty string' => [
-                [
-                    'first' => null,
-                ],
-                [
-                    'first' => '',
-                ],
-                [
-                    'first' => '',
-                ],
-            ],
-            'Override array does override string with null' => [
-                [
-                    'first' => 'foo',
-                ],
-                [
-                    'first' => null,
-                ],
-                [
-                    'first' => null, // Note that ArrayUtility::mergeRecursiveWithOverrule returns 'foo' here
-                ],
-            ],
-            'Override array does override null with null' => [
-                [
-                    'first' => null,
-                ],
-                [
-                    'first' => null,
-                ],
-                [
-                    'first' => null, // Note that ArrayUtility::mergeRecursiveWithOverrule returns '' here
-                ],
-            ],
-            'Override can add keys' => [
-                [
-                    'first' => 'foo',
-                ],
-                [
-                    'second' => 'bar',
-                ],
-                [
-                    'first' => 'foo',
-                    'second' => 'bar',
-                ],
-            ],
-        ];
-    }
-
-    /**
-     * Note the data provider is similar to the data provider for ArrayUtility::mergeRecursiveWithOverrule()
-     *
-     * @test
-     * @dataProvider mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider
-     * @param array $input1 Input 1
-     * @param array $input2 Input 2
-     * @param array $expected expected array
-     */
-    public function mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $expected)
-    {
-        $mockYamlSource = $this->getAccessibleMock(YamlSource::class, ['dummy'], [], '', false);
-        $mockYamlSource->_callRef('mergeRecursiveWithOverrule', $input1, $input2);
-        $this->assertSame($expected, $input1);
-    }
 }