[CLEANUP] Replace count with empty in EXT:indexed_search 53/40953/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 7 Jul 2015 13:28:09 +0000 (15:28 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 7 Jul 2015 14:29:39 +0000 (16:29 +0200)
Replace occurences of count() with matching empty() pendants.

Resolves: #67951
Releases: master
Change-Id: I134a141abf1d0f60a8b67139e53a4e5f6b885503
Reviewed-on: http://review.typo3.org/40953
Reviewed-by: Stephan GroƟberndt <stephan@grossberndt.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/form/Classes/Domain/Factory/TypoScriptFactory.php
typo3/sysext/form/Classes/PostProcess/MailPostProcessor.php
typo3/sysext/indexed_search/Classes/Controller/SearchController.php
typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php
typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php
typo3/sysext/indexed_search/Classes/Hook/CrawlerHook.php
typo3/sysext/indexed_search/Classes/Indexer.php

index 083d04a..baf431c 100644 (file)
@@ -132,7 +132,7 @@ class TypoScriptFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                $typoscriptParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
                                $oldArguments = $arguments;
                                list($class, $arguments) = $typoscriptParser->getVal($key, $this->frontendController->tmpl->setup);
-                               if (is_array($oldArguments) && count($oldArguments)) {
+                               if (is_array($oldArguments) && !empty($oldArguments)) {
                                        $arguments = array_replace_recursive($arguments, $oldArguments);
                                }
                                $this->timeTracker->incStackPointer();
index dafe752..1cf54a5 100644 (file)
@@ -176,7 +176,7 @@ class MailPostProcessor implements \TYPO3\CMS\Form\PostProcess\PostProcessorInte
         */
        protected function setTo() {
                $validEmails = $this->filterValidEmails($this->typoScript['recipientEmail']);
-               if (count($validEmails)) {
+               if (!empty($validEmails)) {
                        $this->mailMessage->setTo($validEmails);
                }
        }
@@ -190,7 +190,7 @@ class MailPostProcessor implements \TYPO3\CMS\Form\PostProcess\PostProcessorInte
         */
        protected function setCc() {
                $validEmails = $this->filterValidEmails($this->typoScript['ccEmail']);
-               if (count($validEmails)) {
+               if (!empty($validEmails)) {
                        $this->mailMessage->setCc($validEmails);
                }
        }
index 6d0f023..cf23af8 100644 (file)
@@ -272,7 +272,8 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                        if ($resultData['count']) {
                                // could we get this in the view?
                                if ($this->searchData['group'] == 'sections' && $freeIndexUid <= 0) {
-                                       $result['sectionText'] = sprintf(LocalizationUtility::translate('result.' . (count($this->resultSections) > 1 ? 'inNsections' : 'inNsection'), 'indexed_search'), count($this->resultSections));
+                                       $resultSectionsCount = count($this->resultSections);
+                                       $result['sectionText'] = sprintf(LocalizationUtility::translate('result.' . ($resultSectionsCount > 1 ? 'inNsections' : 'inNsection'), 'indexed_search'), $resultSectionsCount);
                                }
                        }
                }
@@ -345,11 +346,12 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                                        $onclick = 'document.forms[\'tx_indexedsearch\'][\'tx_indexedsearch_pi2[search][_sections]\'].value=' . GeneralUtility::quoteJSvalue($theRLid) . ';document.forms[\'tx_indexedsearch\'].submit();return false;';
                                        $sectionTitleLinked = '<a href="#" onclick="' . htmlspecialchars($onclick) . '">' . htmlspecialchars($sectionName) . ':</a>';
                                }
-                               $this->resultSections[$id] = array($sectionName, count($resultRows));
+                               $resultRowsCount = count($resultRows);
+                               $this->resultSections[$id] = array($sectionName, $resultRowsCount);
                                // Add section header
                                $finalResultRows[] = array(
                                        'isSectionHeader' => TRUE,
-                                       'numResultRows' => count($resultRows),
+                                       'numResultRows' => $resultRowsCount,
                                        'sectionId' => $id,
                                        'sectionTitle' => $sectionTitleLinked
                                );
@@ -443,7 +445,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                                'sys_language_uid' => $row['sys_language_uid']
                        ));
                        // check if the access is restricted
-                       if (is_array($this->requiredFrontendUsergroups[$pathId]) && count($this->requiredFrontendUsergroups[$pathId])) {
+                       if (is_array($this->requiredFrontendUsergroups[$pathId]) && !empty($this->requiredFrontendUsergroups[$pathId])) {
                                $resultData['access'] = '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('indexed_search')
                                        . 'pi/res/locked.gif" width="12" height="15" vspace="5" title="'
                                        . sprintf(LocalizationUtility::translate('result.memberGroups', 'indexed_search'), implode(',', array_unique($this->requiredFrontendUsergroups[$pathId])))
@@ -857,14 +859,14 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                        $this->view->assign('allSearchTypes', $allSearchTypes);
                        $allDefaultOperands = $this->getAllAvailableOperandsOptions();
                        $this->view->assign('allDefaultOperands', $allDefaultOperands);
-                       $showTypeSearch = count($allSearchTypes) || count($allDefaultOperands);
+                       $showTypeSearch = !empty($allSearchTypes) || !empty($allDefaultOperands);
                        $this->view->assign('showTypeSearch', $showTypeSearch);
                        // "Search in"
                        $allMediaTypes = $this->getAllAvailableMediaTypesOptions();
                        $this->view->assign('allMediaTypes', $allMediaTypes);
                        $allLanguageUids = $this->getAllAvailableLanguageOptions();
                        $this->view->assign('allLanguageUids', $allLanguageUids);
-                       $showMediaAndLanguageSearch = count($allMediaTypes) || count($allLanguageUids);
+                       $showMediaAndLanguageSearch = !empty($allMediaTypes) || !empty($allLanguageUids);
                        $this->view->assign('showMediaAndLanguageSearch', $showMediaAndLanguageSearch);
                        // Sections
                        $allSections = $this->getAllAvailableSectionsOptions();
@@ -877,7 +879,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                        $this->view->assign('allSortOrders', $allSortOrders);
                        $allSortDescendings = $this->getAllAvailableSortDescendingOptions();
                        $this->view->assign('allSortDescendings', $allSortDescendings);
-                       $showSortOrders = count($allSortOrders) || count($allSortDescendings);
+                       $showSortOrders = !empty($allSortOrders) || !empty($allSortDescendings);
                        $this->view->assign('showSortOrders', $showSortOrders);
                        // Limits
                        $allNumberOfResults = $this->getAllAvailableNumberOfResultsOptions();
@@ -955,7 +957,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                        }
                        foreach ($this->externalParsers as $extension => $obj) {
                                // Skip unwanted extensions
-                               if (count($additionalMedia) && !in_array($extension, $additionalMedia)) {
+                               if (!empty($additionalMedia) && !in_array($extension, $additionalMedia)) {
                                        continue;
                                }
                                if ($name = $obj->searchTypeMediaTitle($extension)) {
@@ -1205,14 +1207,12 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                }
                $target = '';
                // If external domain, then link to that:
-               if (count($this->domainRecords[$pageUid])) {
+               if (!empty($this->domainRecords[$pageUid])) {
                        $scheme = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://';
                        $firstDomain = reset($this->domainRecords[$pageUid]);
                        $additionalParams = '';
-                       if (is_array($urlParameters)) {
-                               if (count($urlParameters)) {
-                                       $additionalParams = GeneralUtility::implodeArrayForUrl('', $urlParameters);
-                               }
+                       if (is_array($urlParameters) && !empty($urlParameters)) {
+                               $additionalParams = GeneralUtility::implodeArrayForUrl('', $urlParameters);
                        }
                        $uri = $scheme . $firstDomain . '/index.php?id=' . $pageUid . $additionalParams;
                        if ($target = $this->settings['detectDomainRecords.']['target']) {
@@ -1259,7 +1259,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                        $this->domainRecords[$id] = array();
                        $rl = $GLOBALS['TSFE']->sys_page->getRootLine($id, $pathMP);
                        $path = '';
-                       if (is_array($rl) && count($rl)) {
+                       if (is_array($rl) && !empty($rl)) {
                                foreach ($rl as $k => $v) {
                                        // Check fe_user
                                        if ($v['fe_group'] && ($v['uid'] == $id || $v['extendToSubpages'])) {
index 5755ad8..784482f 100644 (file)
@@ -671,7 +671,8 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
                                $this->internal['res_count'] = $resData['count'];
                                $this->internal['results_at_a_time'] = $this->piVars['results'];
                                $this->internal['maxPages'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->conf['search.']['page_links'], 1, 100, 10);
-                               $addString = $resData['count'] && $this->piVars['group'] == 'sections' && $freeIndexUid <= 0 ? ' ' . sprintf($this->pi_getLL((count($this->resultSections) > 1 ? 'inNsections' : 'inNsection')), count($this->resultSections)) : '';
+                               $resultSectionsCount = count($this->resultSections);
+                               $addString = $resData['count'] && $this->piVars['group'] == 'sections' && $freeIndexUid <= 0 ? ' ' . sprintf($this->pi_getLL(($resultSectionsCount > 1 ? 'inNsections' : 'inNsection')), $resultSectionsCount) : '';
                                $browseBox1 = $this->pi_list_browseresults(1, $addString, $this->printResultSectionLinks(), $freeIndexUid);
                                $browseBox2 = $this->pi_list_browseresults(0, '', '', $freeIndexUid);
                        }
@@ -753,9 +754,10 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
                                                } else {
                                                        $sectionTitleLinked = htmlspecialchars($sectionName);
                                                }
-                                               $this->resultSections[$id] = array($sectionName, count($resultRows));
+                                               $resultRowsCount = count($resultRows);
+                                               $this->resultSections[$id] = array($sectionName, $resultRowsCount);
                                                // Add content header:
-                                               $content .= $this->makeSectionHeader($id, $sectionTitleLinked, count($resultRows));
+                                               $content .= $this->makeSectionHeader($id, $sectionTitleLinked, $resultRowsCount);
                                                // Render result rows:
                                                $resultlist = '';
                                                foreach ($resultRows as $row) {
@@ -1484,7 +1486,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
         * @return      string
         */
        public function printResultSectionLinks() {
-               if (count($this->resultSections)) {
+               if (!empty($this->resultSections)) {
                        $lines = array();
                        $html = $this->cObj->getSubpart($this->templateCode, '###RESULT_SECTION_LINKS###');
                        $item = $this->cObj->getSubpart($this->templateCode, '###RESULT_SECTION_LINKS_LINK###');
@@ -2087,7 +2089,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
         * @return string <img> tag if access is limited.
         */
        public function makeAccessIndication($id) {
-               if (is_array($this->fe_groups_required[$id]) && count($this->fe_groups_required[$id])) {
+               if (is_array($this->fe_groups_required[$id]) && !empty($this->fe_groups_required[$id])) {
                        return '<img src="' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('indexed_search') . 'pi/res/locked.gif" width="12" height="15" vspace="5" title="' . sprintf($this->pi_getLL('res_memberGroups', '', TRUE), implode(',', array_unique($this->fe_groups_required[$id]))) . '" alt="" />';
                }
        }
@@ -2121,15 +2123,13 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
                        $this->getPathFromPageId($id);
                }
                // If external domain, then link to that:
-               if (count($this->domain_records[$id])) {
+               if (!empty($this->domain_records[$id])) {
                        reset($this->domain_records[$id]);
                        $firstDom = current($this->domain_records[$id]);
                        $scheme = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://';
                        $addParams = '';
-                       if (is_array($urlParameters)) {
-                               if (count($urlParameters)) {
-                                       $addParams .= GeneralUtility::implodeArrayForUrl('', $urlParameters);
-                               }
+                       if (is_array($urlParameters) && !empty($urlParameters)) {
+                               $addParams .= GeneralUtility::implodeArrayForUrl('', $urlParameters);
                        }
                        if ($target = $this->conf['search.']['detect_sys_domain_records.']['target']) {
                                $target = ' target="' . $target . '"';
@@ -2182,7 +2182,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
                        $rl = $this->getRootLine($id, $pathMP);
                        $hitRoot = 0;
                        $path = '';
-                       if (is_array($rl) && count($rl)) {
+                       if (is_array($rl) && !empty($rl)) {
                                foreach ($rl as $k => $v) {
                                        // Check fe_user
                                        if ($v['fe_group'] && ($v['uid'] == $id || $v['extendToSubpages'])) {
index 831d7b9..381626c 100644 (file)
@@ -308,11 +308,12 @@ class AdministrationRepository {
         */
        protected function addAdditionalInformation(array &$row) {
                $grListRec = $this->getGrlistRecord($row['phash']);
+               $unserializedCHashParams = unserialize($row['cHashParams']);
 
                $row['numberOfWords'] = $this->getNumberOfWords($row['phash']);
                $row['numberOfSections'] = $this->getNumberOfSections($row['phash']);
                $row['numberOfFulltext'] = $this->getNumberOfFulltextRecords($row['phash']);
-               $row['cHashParams'] = count(unserialize($row['cHashParams'])) ? unserialize($row['cHashParams']) : '';
+               $row['cHashParams'] = !empty($unserializedCHashParams) ? $unserializedCHashParams : '';
                $row['grList'] = $grListRec;
        }
 
index d5965e2..05324c1 100644 (file)
@@ -237,7 +237,7 @@ class CrawlerHook {
                        $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $cfgRec['table2index'], 'pid = ' . $pid . '
                                                        AND uid > ' . (int)$session_data['uid'] . BackendUtility::deleteClause($cfgRec['table2index']) . BackendUtility::BEenableFields($cfgRec['table2index']), '', 'uid', $numberOfRecords);
                        // Traverse:
-                       if (count($recs)) {
+                       if (!empty($recs)) {
                                foreach ($recs as $r) {
                                        // Index single record:
                                        $this->indexSingleRecord($r, $cfgRec, $rl);
@@ -376,7 +376,7 @@ class CrawlerHook {
                $downloadUrls = array();
                // Dummy.
                // Submit URLs:
-               if (count($res)) {
+               if (!empty($res)) {
                        foreach ($res as $paramSetKey => $vv) {
                                $urlList = $pObj->urlListFromUrlArray($vv, $pageRow, $GLOBALS['EXEC_TIME'], 30, 1, 0, $duplicateTrack, $downloadUrls, array('tx_indexedsearch_reindex'));
                        }
@@ -386,7 +386,7 @@ class CrawlerHook {
                        // Subpages selected
                        $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title', 'pages', 'pid = ' . $pageUid . BackendUtility::deleteClause('pages'));
                        // Traverse subpages and add to queue:
-                       if (count($recs)) {
+                       if (!empty($recs)) {
                                foreach ($recs as $r) {
                                        $this->instanceCounter++;
                                        $url = 'pages:' . $r['uid'] . ': ' . $r['title'];
@@ -637,7 +637,7 @@ class CrawlerHook {
        public function deleteFromIndex($id) {
                // Lookup old phash rows:
                $oldPhashRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('phash', 'index_section', 'page_id=' . (int)$id);
-               if (count($oldPhashRows)) {
+               if (!empty($oldPhashRows)) {
                        $pHashesToDelete = array();
                        foreach ($oldPhashRows as $pHashRow) {
                                $pHashesToDelete[] = $pHashRow['phash'];
@@ -684,7 +684,7 @@ class CrawlerHook {
         */
        public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $pObj) {
                // Check if any fields are actually updated:
-               if (count($fieldArray)) {
+               if (!empty($fieldArray)) {
                        // Translate new ids.
                        if ($status == 'new') {
                                $id = $pObj->substNEWwithIDs[$id];
index ce5d9e4..67acc47 100644 (file)
@@ -1822,16 +1822,17 @@ class Indexer {
         */
        public function checkWordList($wordListArray) {
                if (\TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::isTableUsed('index_words')) {
-                       if (count($wordListArray)) {
+                       if (!empty($wordListArray)) {
                                $phashArray = array();
                                foreach ($wordListArray as $value) {
                                        $phashArray[] = (int)$value['hash'];
                                }
                                $cwl = implode(',', $phashArray);
                                $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('baseword', 'index_words', 'wid IN (' . $cwl . ')');
-                               if ($count != count($wordListArray)) {
+                               $wordListArrayCount = count($wordListArray);
+                               if ($count !== $wordListArrayCount) {
                                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('baseword', 'index_words', 'wid IN (' . $cwl . ')');
-                                       $this->log_setTSlogMessage('Inserting words: ' . (count($wordListArray) - $count), 1);
+                                       $this->log_setTSlogMessage('Inserting words: ' . ($wordListArrayCount - $count), 1);
                                        while (FALSE != ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
                                                unset($wordListArray[$row['baseword']]);
                                        }