[CLEANUP] Fix TYPO3.ControlStructures.DisallowEachInLoopCondition-Sniff 70/32070/5
authorAndy Grunwald <andygrunwald@gmail.com>
Sun, 10 Aug 2014 17:19:37 +0000 (19:19 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 1 Feb 2015 12:29:56 +0000 (13:29 +0100)
Resolves: #60876
Releases: master
Change-Id: Ifc630f26bd5670ce2f3c6f62522face4514fdbd6
Reviewed-on: http://review.typo3.org/32070
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Mateusz Wojtuła <matw88@gmail.com>
Reviewed-by: Zbigniew Jacko <z.jacko@macopedia.pl>
Reviewed-by: Göran Bodenschatz <coding@46halbe.de>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Database/QueryGenerator.php
typo3/sysext/core/Classes/Database/QueryView.php
typo3/sysext/core/Classes/Html/HtmlParser.php
typo3/sysext/core/Classes/Utility/MathUtility.php
typo3/sysext/core/Resources/PHP/TYPO3.Flow/Classes/TYPO3/Flow/Package/PackageManager.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/rtehtmlarea/Classes/Controller/SpellCheckingController.php

index 6bb9534..2d41017 100644 (file)
@@ -836,7 +836,7 @@ class QueryGenerator {
                        }
                        $counter = 0;
                        $webMountPageTree = '';
-                       while (list(, $from_table) = each($from_table_Arr)) {
+                       foreach ($from_table_Arr as $from_table) {
                                if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) {
                                        $tablePrefix = $from_table . '_';
                                }
index 2843c40..1145e50 100644 (file)
@@ -745,7 +745,7 @@ class QueryView {
                        }
                        $d->close();
                        natcasesort($fileArray);
-                       while (list(, $fileName) = each($fileArray)) {
+                       foreach ($fileArray as $fileName) {
                                if (GeneralUtility::inList($fieldValue, $fileName) || $fieldValue == $fileName) {
                                        if (!$out) {
                                                $out = htmlspecialchars($fileName);
index 6f6ab62..615ccbf 100644 (file)
@@ -331,8 +331,9 @@ class HtmlParser {
                $buffer = $parts[0];
                $nested = 0;
                reset($parts);
-               next($parts);
-               while (list($k, $v) = each($parts)) {
+               // We skip the first element in foreach loop
+               $partsSliced = array_slice($parts, 1, null, true);
+               foreach ($partsSliced as $v) {
                        $isEndTag = substr($content, $pointer, 2) == '</' ? 1 : 0;
                        $tagLen = strcspn(substr($content, $pointer), '>') + 1;
                        // We meet a start-tag:
@@ -434,8 +435,9 @@ class HtmlParser {
                $newParts = array();
                $newParts[] = $parts[0];
                reset($parts);
-               next($parts);
-               while (list($k, $v) = each($parts)) {
+               // We skip the first element in foreach loop
+               $partsSliced = array_slice($parts, 1, null, true);
+               foreach ($partsSliced as $v) {
                        $tagLen = strcspn(substr($content, $pointer), '>') + 1;
                        // Set tag:
                        // New buffer set and pointer increased
@@ -698,14 +700,15 @@ class HtmlParser {
                $newContent = array();
                $tokArr = explode('<', $content);
                $newContent[] = $this->processContent(current($tokArr), $hSC, $addConfig);
-               next($tokArr);
+               // We skip the first element in foreach loop
+               $tokArrSliced = array_slice($tokArr, 1, null, true);
                $c = 1;
                $tagRegister = array();
                $tagStack = array();
                $inComment = FALSE;
                $inCdata = FALSE;
                $skipTag = FALSE;
-               while (list(, $tok) = each($tokArr)) {
+               foreach ($tokArrSliced as $tok) {
                        if ($inComment) {
                                if (($eocPos = strpos($tok, '-->')) === FALSE) {
                                        // End of comment is not found in the token. Go further until end of comment is found in other tokens.
@@ -1181,9 +1184,9 @@ class HtmlParser {
        public function unprotectTags($content, $tagList = '') {
                $tagsArray = GeneralUtility::trimExplode(',', $tagList, TRUE);
                $contentParts = explode('&lt;', $content);
-               next($contentParts);
                // bypass the first
-               while (list($k, $tok) = each($contentParts)) {
+               $contentPartsSliced = array_slice($contentParts, 1, null, true);
+               foreach ($contentPartsSliced as $k => $tok) {
                        $firstChar = $tok[0];
                        if (trim($firstChar) !== '') {
                                $subparts = explode('&gt;', $tok, 2);
index 17f691d..302c804 100644 (file)
@@ -122,8 +122,8 @@ class MathUtility {
                $err = '';
                $buffer = doubleval(current($reg[2]));
                // Advance pointer
-               next($reg[2]);
-               while (list($k, $v) = each($reg[2])) {
+               $regSliced = array_slice($reg[2], 1, null, true);
+               foreach ($regSliced as $k => $v) {
                        $v = doubleval($v);
                        $sign = $reg[1][$k];
                        if ($sign == '+' || $sign == '-') {
index 5c230ac..8a686b2 100644 (file)
@@ -793,7 +793,7 @@ class PackageManager implements \TYPO3\Flow\Package\PackageManagerInterface {
                } else {
                        $jsonPathsAndFilenames = Files::readDirectoryRecursively($packagePath, '.json');
                        asort($jsonPathsAndFilenames);
-                       while (list($unusedKey, $jsonPathAndFilename) = each($jsonPathsAndFilenames)) {
+                       foreach ($jsonPathsAndFilenames as $jsonPathAndFilename) {
                                if (basename($jsonPathAndFilename) === 'composer.json') {
                                        $manifestPath = dirname($jsonPathAndFilename) . '/';
                                        $manifestPaths[] = $manifestPath;
index 39ddd7e..2683781 100644 (file)
@@ -5505,7 +5505,10 @@ class ContentObjectRenderer {
                }
                $retVal = '';
                $sections = explode('//', $string);
-               while (!$retVal and list($secKey, $secVal) = each($sections)) {
+               foreach ($sections as $secKey => $secVal) {
+                       if ($retVal) {
+                               break;
+                       }
                        $parts = explode(':', $secVal, 2);
                        $type = strtolower(trim($parts[0]));
                        $typesWithOutParameters = array('level', 'date', 'current');
index 0172f0f..c557805 100644 (file)
@@ -554,7 +554,7 @@ var selectedDictionary = "' . $this->dictionary . '";
                $incurrent = array();
                $stringText = $string;
                $words = preg_split($this->parserCharset == 'utf-8' ? '/\\P{L}+/u' : '/\\W+/', $stringText);
-               while (list(, $word) = each($words)) {
+               foreach ($words as $word) {
                        $word = preg_replace('/ /' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '', $word);
                        if ($word && !is_numeric($word)) {
                                if ($this->pspell_is_available && !$this->forceCommandMode) {