Merge "[TASK] Improve performance of Utility/Arrays::integerExplode"
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Mon, 30 Apr 2012 23:35:31 +0000 (01:35 +0200)
committerGerrit Code Review <gerrit@review.typo3.org>
Mon, 30 Apr 2012 23:35:31 +0000 (01:35 +0200)
typo3/sysext/extbase/Classes/Utility/Arrays.php
typo3/sysext/extbase/Tests/Unit/Utility/ArraysTest.php

index c55414b..478f31e 100644 (file)
@@ -44,11 +44,8 @@ class Tx_Extbase_Utility_Arrays {
         * @api
         */
        static public function integerExplode($delimiter, $string) {
-               $chunksArr = explode($delimiter, $string);
-               foreach ($chunksArr as $key => $value) {
-                       $chunks[$key] = intval($value);
-               }
-               return $chunks;
+               $explodedValues = self::trimExplode($delimiter, $string);
+               return array_map('intval', $explodedValues);
        }
 
        /**
index 969ab63..f0d55b2 100644 (file)
@@ -405,5 +405,30 @@ class Tx_Extbase_Tests_Unit_Utility_ArraysTest extends Tx_Extbase_Tests_Unit_Bas
                        )
                );
        }
+
+       /**
+        * @test
+        */
+       public function integerExplodeReturnsArrayOfIntegers() {
+               $inputString = '1,2,3,4,5,6';
+               $expected = array(1,2,3,4,5,6);
+               $this->assertSame(
+                       $expected,
+                       Tx_Extbase_Utility_Arrays::integerExplode(',', $inputString)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function integerExplodeReturnsZeroForStringValues() {
+               $inputString = '1,abc,3,,5';
+               $expected = array(1,0,3,0,5);
+               $this->assertSame(
+                       $expected,
+                       Tx_Extbase_Utility_Arrays::integerExplode(',', $inputString)
+               );
+       }
+
 }
 ?>
\ No newline at end of file