[CLEANUP] Replace create_function() with closure 57/40457/3
authorMarkus Klein <markus.klein@typo3.org>
Thu, 18 Jun 2015 21:53:24 +0000 (23:53 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 19 Jun 2015 07:03:49 +0000 (09:03 +0200)
The create_function() function is discouraged due to internal usage
of eval(). Replace all calls with a real closure, which is supported
since PHP 5.3.

Resolves: #67616
Releases: master
Change-Id: I7943bf69df94d0948b1b2dd0f4821bc48ec67896
Reviewed-on: http://review.typo3.org/40457
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Utility/ArrayUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/AbstractConfigurationManagerTest.php

index f2835a8..1ac0399 100644 (file)
@@ -591,7 +591,7 @@ class ArrayUtility {
         * array('cc' => array('fifth', 'sixth'),
         * );
         * $keepItems = array('third');
-        * $getValueFunc = create_function('$value', 'return $value[0];');
+        * $getValueFunc = function($value) { return $value[0]; }
         *
         * Returns:
         * array(
index 6de0cb7..fdd742b 100755 (executable)
@@ -1514,7 +1514,7 @@ class GeneralUtility {
         * array('cc' => array('fifth', 'sixth'),
         * );
         * $keepItems = array('third');
-        * $getValueFunc = create_function('$value', 'return $value[0];');
+        * $getValueFunc = function($value) { return $value[0]; }
         *
         * Returns:
         * array(
index 12604a7..375435f 100644 (file)
@@ -1862,31 +1862,12 @@ class ArrayUtilityTest extends UnitTestCase {
        }
 
        /**
-        * Shows the exmaple from the doc comment where
+        * Shows the example from the doc comment where
         * a function is used to reduce the sub arrays to one item which
         * is then used for the matching.
         *
         * @test
         */
-       public function keepItemsInArrayCanUseCallbackOnSearchArray() {
-               $array = array(
-                       'aa' => array('first', 'second'),
-                       'bb' => array('third', 'fourth'),
-                       'cc' => array('fifth', 'sixth')
-               );
-               $expected = array('bb' => array('third', 'fourth'));
-               $keepItems = 'third';
-               $getValueFunc = create_function('$value', 'return $value[0];');
-               $match = ArrayUtility::keepItemsInArray($array, $keepItems, $getValueFunc);
-               $this->assertEquals($expected, $match);
-       }
-
-       /**
-        * Similar to keepItemsInArrayCanUseCallbackOnSearchArray(),
-        * but uses a closure instead of create_function()
-        *
-        * @test
-        */
        public function keepItemsInArrayCanUseClosure() {
                $array = array(
                        'aa' => array('first', 'second'),
index a1722c2..be79de4 100644 (file)
@@ -4206,9 +4206,8 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function callUserFunctionCanCallFunction() {
-               $functionName = create_function('', 'return "Worked fine";');
                $inputData = array('foo' => 'bar');
-               $result = Utility\GeneralUtility::callUserFunction($functionName, $inputData, $this, '');
+               $result = Utility\GeneralUtility::callUserFunction(function() { return "Worked fine"; }, $inputData, $this, '');
                $this->assertEquals('Worked fine', $result);
        }
 
@@ -4217,7 +4216,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function callUserFunctionCanCallMethod() {
                $inputData = array('foo' => 'bar');
-               $result = Utility\GeneralUtility::callUserFunction(\TYPO3\CMS\Core\Tests\Unit\Utility\GeneralUtilityTest::class . '->user_calledUserFunction', $inputData, $this);
+               $result = Utility\GeneralUtility::callUserFunction(GeneralUtilityTest::class . '->user_calledUserFunction', $inputData, $this);
                $this->assertEquals('Worked fine', $result);
        }
 
index 3856b2f..2e438d3 100644 (file)
@@ -390,7 +390,7 @@ class AbstractConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                $this->abstractConfigurationManager->setConfiguration($configuration);
                $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
                $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
-               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
+               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function($a) { return $a; }));
                $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
                $expectedResult = array(
                        'Controller1' => array(
@@ -416,7 +416,7 @@ class AbstractConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                $this->abstractConfigurationManager->setConfiguration($configuration);
                $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
                $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
-               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
+               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function($a) { return $a; }));
                $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
                $expectedResult = array(
                        'Controller1' => array(
@@ -442,7 +442,7 @@ class AbstractConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                $this->abstractConfigurationManager->setConfiguration($configuration);
                $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
                $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
-               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
+               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function($a) { return $a; }));
                $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
                $expectedResult = array();
                $actualResult = $mergedConfiguration['controllerConfiguration'];
@@ -465,7 +465,7 @@ class AbstractConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                $this->abstractConfigurationManager->setConfiguration($configuration);
                $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testPluginConfiguration));
                $this->abstractConfigurationManager->expects($this->once())->method('getSwitchableControllerActions')->with('CurrentExtensionName', 'CurrentPluginName')->will($this->returnValue($this->testSwitchableControllerActions));
-               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(create_function('$a', 'return $a;')));
+               $this->abstractConfigurationManager->expects($this->once())->method('getContextSpecificFrameworkConfiguration')->will($this->returnCallBack(function($a) { return $a; }));
                $mergedConfiguration = $this->abstractConfigurationManager->getConfiguration();
                $expectedResult = array(
                        'Controller1' => array(