[CLEANUP] Replace count with empty in multiple extensions, part III 59/40959/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 7 Jul 2015 14:01:47 +0000 (16:01 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 7 Jul 2015 14:29:08 +0000 (16:29 +0200)
Replace occurences of count() with matching empty() pendants.
Affected extensions:
- scheduler
- sv
- version
- workspaces

Resolves: #67955
Releases: master
Change-Id: I1fd152ed9b581e0f2645837776fd7fab1ccbf73e
Reviewed-on: http://review.typo3.org/40959
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stephan GroƟberndt <stephan@grossberndt.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
19 files changed:
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Classes/CronCommand/NormalizeCommand.php
typo3/sysext/scheduler/Classes/Scheduler.php
typo3/sysext/scheduler/Classes/Task/AbstractTask.php
typo3/sysext/scheduler/Classes/Task/TableGarbageCollectionAdditionalFieldProvider.php
typo3/sysext/sv/Classes/Report/ServicesListReport.php
typo3/sysext/version/Classes/DataHandler/CommandMap.php
typo3/sysext/version/Classes/Dependency/ElementEntity.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php
typo3/sysext/version/Classes/Hook/PreviewHook.php
typo3/sysext/version/Classes/Utility/WorkspacesUtility.php
typo3/sysext/workspaces/Classes/Controller/PreviewController.php
typo3/sysext/workspaces/Classes/ExtDirect/ActionHandler.php
typo3/sysext/workspaces/Classes/ExtDirect/MassActionHandler.php
typo3/sysext/workspaces/Classes/ExtDirect/PagetreeCollectionsProcessor.php
typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
typo3/sysext/workspaces/Classes/Service/GridDataService.php
typo3/sysext/workspaces/Classes/Service/StagesService.php
typo3/sysext/workspaces/Classes/Service/WorkspaceService.php

index fb1a0a2..608ce58 100644 (file)
@@ -435,7 +435,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
        protected function infoScreenAction() {
                $registeredClasses = $this->getRegisteredClasses();
                // No classes available, display information message
-               if (count($registeredClasses) == 0) {
+               if (empty($registeredClasses)) {
                        $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'InfoScreenNoClasses.html');
                        return $this->view->render();
                }
@@ -620,7 +620,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
 
                // If some data was already submitted, use it to override
                // existing data
-               if (count($this->submittedData) > 0) {
+               if (!empty($this->submittedData)) {
                        \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($taskInfo, $this->submittedData);
                }
 
@@ -842,7 +842,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                        $this->scheduler->scheduleNextSchedulerRunUsingAtDaemon();
                }
                // Continue if some elements have been chosen for execution
-               if (isset($this->submittedData['execute']) && count($this->submittedData['execute']) > 0) {
+               if (isset($this->submittedData['execute']) && !empty($this->submittedData['execute'])) {
                        // Get list of registered classes
                        $registeredClasses = $this->getRegisteredClasses();
                        // Loop on all selected tasks
@@ -1517,7 +1517,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                );
                if (empty($this->CMD) || $this->CMD === 'list' || $this->CMD === 'delete' || $this->CMD === 'stop' || $this->CMD === 'toggleHidden') {
                        $buttons['reload'] = '<a href="' . htmlspecialchars($this->moduleUri) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
-                       if ($this->MOD_SETTINGS['function'] === 'scheduler' && count($this->getRegisteredClasses())) {
+                       if ($this->MOD_SETTINGS['function'] === 'scheduler' && !empty($this->getRegisteredClasses())) {
                                $link = $this->moduleUri . '&CMD=add';
                                $image = IconUtility::getSpriteIcon('actions-document-new', array('alt' => $this->getLanguageService()->getLL('action.add')));
                                $buttons['addtask'] = '<a href="' . htmlspecialchars($link) . '" ' . 'title="' . $this->getLanguageService()->getLL('action.add') . '">' . $image . '</a>';
index b31ab6e..285c385 100644 (file)
@@ -223,9 +223,10 @@ class NormalizeCommand {
                        $rangeArray[$fieldNumber] = (int)$fieldValue;
                }
 
-               if (count($rangeArray) === 1) {
+               $rangeArrayCount = count($rangeArray);
+               if ($rangeArrayCount === 1) {
                        $resultList = $rangeArray[0];
-               } elseif (count($rangeArray) === 2) {
+               } elseif ($rangeArrayCount === 2) {
                        $left = $rangeArray[0];
                        $right = $rangeArray[1];
                        if ($left > $right) {
@@ -257,7 +258,8 @@ class NormalizeCommand {
                        throw new \InvalidArgumentException('Unable to convert step values.', 1291234987);
                }
                $stepValuesAndStepArray = explode('/', $stepExpression);
-               if (count($stepValuesAndStepArray) < 1 || count($stepValuesAndStepArray) > 2) {
+               $stepValuesAndStepArrayCount = count($stepValuesAndStepArray);
+               if ($stepValuesAndStepArrayCount < 1 || $stepValuesAndStepArrayCount > 2) {
                        throw new \InvalidArgumentException('Unable to convert step values: Multiple slashes found.', 1291242168);
                }
                $left = $stepValuesAndStepArray[0];
@@ -287,7 +289,7 @@ class NormalizeCommand {
                        }
                        $currentStep--;
                }
-               if (count($validValues) === 0) {
+               if (empty($validValues)) {
                        throw new \InvalidArgumentException('Unable to convert step values: Result value list is empty.', 1291414959);
                }
                return implode(',', $validValues);
index dcec923..f5956bc 100644 (file)
@@ -108,8 +108,9 @@ class Scheduler implements \TYPO3\CMS\Core\SingletonInterface {
                                        }
                                }
                        }
-                       if (count($serialized_executions) != count($executions)) {
-                               if (count($executions) == 0) {
+                       $executionCount = count($executions);
+                       if (count($serialized_executions) !== $executionCount) {
+                               if ($executionCount === 0) {
                                        $value = '';
                                } else {
                                        $value = serialize($executions);
index 14dc00e..c1a0a48 100644 (file)
@@ -417,7 +417,7 @@ abstract class AbstractTask {
                                $runningExecutions = unserialize($row['serialized_executions']);
                                // Remove the selected execution
                                unset($runningExecutions[$executionID]);
-                               if (count($runningExecutions) > 0) {
+                               if (!empty($runningExecutions)) {
                                        // Re-serialize the updated executions list (if necessary)
                                        $runningExecutionsSerialized = serialize($runningExecutions);
                                } else {
index b8ecede..31e2899 100644 (file)
@@ -100,7 +100,7 @@ class TableGarbageCollectionAdditionalFieldProvider implements \TYPO3\CMS\Schedu
                        $options[] = '<option value="" selected="selected"></option>';
                }
                foreach ($tableConfiguration as $tableName => $configuration) {
-                       if ($parentObject->CMD === 'add' && count($options) === 0) {
+                       if ($parentObject->CMD === 'add' && empty($options)) {
                                // Select first table by default if adding a new task
                                $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
                        } elseif ($task->table === $tableName) {
index bc27bb4..89ff85c 100644 (file)
@@ -170,7 +170,7 @@ class ServicesListReport implements ReportInterface {
        protected function renderExecutablesSearchPathList() {
                $searchPaths = CommandUtility::getPaths(TRUE);
                $content = '<h3>' . $this->getLanguageService()->getLL('search_paths') . '</h3>';
-               if (count($searchPaths) === 0) {
+               if (empty($searchPaths)) {
                        $content .= '<p>' . $this->getLanguageService()->getLL('no_search_paths') . '</p>';
                } else {
                        $content .= '
index 4dd5d4b..059ccfa 100644 (file)
@@ -303,7 +303,7 @@ class CommandMap {
                                $extendedCommandMap[$elementTable][$elementIds[0]]['version'] = array_merge($properties, array('swapWith' => $elementIds[1]));
                        }
                }
-               if (count($elementList) > 0) {
+               if (!empty($elementList)) {
                        $this->remove($table, $liveId, 'version');
                        $this->mergeToBottom($extendedCommandMap);
                }
@@ -329,7 +329,7 @@ class CommandMap {
                                $dependency->addElement($elementTable, $elementIds[1], array('liveId' => $elementIds[0], 'properties' => array_merge($properties, array('swapWith' => $elementIds[1]))));
                        }
                }
-               if (count($elementList) === 0) {
+               if (empty($elementList)) {
                        $dependency->addElement($table, $properties['swapWith'], array('liveId' => $liveId, 'properties' => $properties));
                }
        }
@@ -500,7 +500,7 @@ class CommandMap {
                        // Gets the difference (intersection) between elements that were submitted by the user
                        // and the evaluation of all dependent records that should be used for this action instead:
                        $intersectingElements = array_intersect_key($dependentElements, $elementsToBeVersioned);
-                       if (count($intersectingElements) > 0) {
+                       if (!empty($intersectingElements)) {
                                // If at least one element intersects but not all, throw away all elements of the depdendent structure:
                                if (count($intersectingElements) !== count($dependentElements) && $this->workspacesConsiderReferences === FALSE) {
                                        $this->purgeWithErrorMessage($intersectingElements, $scope);
index 5d09f02..09fa524 100644 (file)
@@ -274,7 +274,7 @@ class ElementEntity {
         * @return bool
         */
        public function hasReferences() {
-               return count($this->getChildren()) > 0 || count($this->getParents()) > 0;
+               return !empty($this->getChildren()) || !empty($this->getParents());
        }
 
        /**
@@ -285,7 +285,7 @@ class ElementEntity {
        public function getOuterMostParent() {
                if (!isset($this->outerMostParent)) {
                        $parents = $this->getParents();
-                       if (count($parents) === 0) {
+                       if (empty($parents)) {
                                $this->outerMostParent = $this;
                        } else {
                                $this->outerMostParent = FALSE;
index 119a2cb..2fe34d1 100644 (file)
@@ -314,7 +314,7 @@ class DataHandlerHook {
                } elseif ($destRes == 1 && $WSversion['uid']) {
                        $workspaceAccessBlocked['dest2'] = 'Could not insert other versions in destination PID ';
                }
-               if (!count($workspaceAccessBlocked)) {
+               if (empty($workspaceAccessBlocked)) {
                        // If the move operation is done on a versioned record, which is
                        // NOT new/deleted placeholder and versioningWS is in version 2, then...
                        if ($WSversion['uid'] && !$recIsNewVersion && BackendUtility::isTableMovePlaceholderAware($table)) {
@@ -444,7 +444,7 @@ class DataHandlerHook {
                                        $newStage = 'Unknown state change!?';
                        }
                }
-               if (count($notificationAlternativeRecipients) == 0) {
+               if (empty($notificationAlternativeRecipients)) {
                        // Compile list of recipients:
                        $emails = array();
                        switch ((int)$stat['stagechg_notification']) {
@@ -494,7 +494,7 @@ class DataHandlerHook {
                        $emails = $notificationAlternativeRecipients;
                }
                // prepare and then send the emails
-               if (count($emails)) {
+               if (!empty($emails)) {
                        // Path to record is found:
                        list($elementTable, $elementUid) = explode(':', $elementName);
                        $elementUid = (int)$elementUid;
@@ -911,7 +911,9 @@ class DataHandlerHook {
                                unlink($lockFileName);
                        }
                }
-               if (!count($sqlErrors)) {
+               if (!empty($sqlErrors)) {
+                       $tcemainObj->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), 2);
+               } else {
                        // Register swapped ids for later remapping:
                        $this->remappedIds[$table][$id] = $swapWith;
                        $this->remappedIds[$table][$swapWith] = $id;
@@ -984,8 +986,6 @@ class DataHandlerHook {
                        $refIndexObj->setWorkspaceId(0);
                        $refIndexObj->updateRefIndexTable($table, $id);
                        $refIndexObj->updateRefIndexTable($table, $swapWith);
-               } else {
-                       $tcemainObj->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), 2);
                }
        }
 
index d8ddd2d..e4dc096 100644 (file)
@@ -166,7 +166,7 @@ class PreviewHook implements \TYPO3\CMS\Core\SingletonInterface {
                        // - Make sure to remove fe/be cookies (temporarily);
                        // BE already done in ADMCMD_preview_postInit()
                        if (is_array($previewData)) {
-                               if (!count(GeneralUtility::_POST())) {
+                               if (empty(GeneralUtility::_POST())) {
                                        // Unserialize configuration:
                                        $previewConfig = unserialize($previewData['config']);
                                        // For full workspace preview we only ADD a get variable
index e6883fb..43562cf 100644 (file)
@@ -82,7 +82,7 @@ class WorkspacesUtility {
                                // Select all records from this table in the database from the workspace
                                // This joins the online version with the offline version as tables A and B
                                $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('A.uid, A.t3ver_oid, B.pid AS realpid', $table . ' A,' . $table . ' B', 'A.pid=-1' . ($pageId != -1 ? ($table === 'pages' ? ' AND B.uid=' . $pageId : ' AND B.pid=' . $pageId) : '') . ($wsid > -98 ? ' AND A.t3ver_wsid=' . $wsid : ($wsid === -98 ? ' AND A.t3ver_wsid!=0' : '')) . ($filter === 1 ? ' AND A.t3ver_count=0' : ($filter === 2 ? ' AND A.t3ver_count>0' : '')) . ($stage != -99 ? ' AND A.t3ver_stage=' . (int)$stage : '') . ' AND B.pid>=0' . ' AND A.t3ver_oid=B.uid' . BackendUtility::deleteClause($table, 'A') . BackendUtility::deleteClause($table, 'B'), '', 'B.uid');
-                               if (count($recs)) {
+                               if (!empty($recs)) {
                                        $output[$table] = $recs;
                                }
                        }
index c5dd753..5b3cfe3 100644 (file)
@@ -167,7 +167,7 @@ class PreviewController extends AbstractController {
         * @return bool
         */
        protected function isInvalidStage($stageArray) {
-               return !(is_array($stageArray) && count($stageArray) > 0);
+               return !(is_array($stageArray) && !empty($stageArray));
        }
 
        /**
index 1ad982b..965eb6c 100644 (file)
@@ -399,7 +399,7 @@ class ActionHandler extends AbstractHandler {
                if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($stageId) === FALSE) {
                        throw new \InvalidArgumentException('Missing "stageId" in $parameters array.', 1319488194);
                }
-               if (!is_object($parameters->affects) || count($parameters->affects) == 0) {
+               if (!is_object($parameters->affects) || empty($parameters->affects)) {
                        throw new \InvalidArgumentException('Missing "affected items" in $parameters array.', 1319488195);
                }
                $recipients = $this->getRecipientList($parameters->receipients, $parameters->additional, $stageId);
@@ -778,15 +778,15 @@ class ActionHandler extends AbstractHandler {
                list(, $previousStage) = $stageService->getPreviousStageForElementCollection($workspaceItemsArray);
                $toolbarButtons = array(
                        'feToolbarButtonNextStage' => array(
-                               'visible' => is_array($nextStage) && count($nextStage) > 0,
+                               'visible' => is_array($nextStage) && !empty($nextStage),
                                'text' => $nextStage['title']
                        ),
                        'feToolbarButtonPreviousStage' => array(
-                               'visible' => is_array($previousStage) && count($previousStage),
+                               'visible' => is_array($previousStage) && !empty($previousStage),
                                'text' => $previousStage['title']
                        ),
                        'feToolbarButtonDiscardStage' => array(
-                               'visible' => is_array($nextStage) && count($nextStage) > 0 || is_array($previousStage) && count($previousStage) > 0,
+                               'visible' => is_array($nextStage) && !empty($nextStage) || is_array($previousStage) && !empty($previousStage),
                                'text' => $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:label_doaction_discard', TRUE)
                        )
                );
index 28e289d..cf10355 100644 (file)
@@ -197,19 +197,18 @@ class MassActionHandler extends AbstractHandler {
                        $tce->start(array(), $limitedCmd);
                        $tce->process_cmdmap();
                        $errors = $tce->errorLog;
-                       if (count($errors) > 0) {
+                       if (!empty($errors)) {
                                throw new \Exception(implode(', ', $errors));
-                       } else {
-                               // Unset processed records
-                               foreach ($limitedCmd as $table => $recs) {
-                                       foreach ($recs as $key => $value) {
-                                               $recordsProcessed++;
-                                               unset($processData[$table][$key]);
-                                       }
+                       }
+                       // Unset processed records
+                       foreach ($limitedCmd as $table => $recs) {
+                               foreach ($recs as $key => $value) {
+                                       $recordsProcessed++;
+                                       unset($processData[$table][$key]);
                                }
-                               $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $processData);
-                               $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', $recordsProcessed);
                        }
+                       $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $processData);
+                       $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', $recordsProcessed);
                }
                return $recordsProcessed;
        }
index c97c0bb..3bfdb45 100644 (file)
@@ -72,7 +72,7 @@ class PagetreeCollectionsProcessor implements \TYPO3\CMS\Backend\Tree\Pagetree\C
         * @return void
         */
        protected function highlightVersionizedElements(\TYPO3\CMS\Backend\Tree\TreeNode $node) {
-               if (!$node->getCls() && count(\TYPO3\CMS\Backend\Utility\BackendUtility::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $node->getId(), TRUE))) {
+               if (!$node->getCls() && !empty(\TYPO3\CMS\Backend\Utility\BackendUtility::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $node->getId(), TRUE))) {
                        $node->setCls('ver-versions');
                }
        }
index 479342c..b8035c0 100644 (file)
@@ -97,7 +97,7 @@ class DataHandlerHook {
                                }
                        }
                }
-               if (count($command)) {
+               if (!empty($command)) {
                        $tceMain = $this->getTceMain();
                        $tceMain->start(array(), $command);
                        $tceMain->process_cmdmap();
index 846bb83..4fa5118 100644 (file)
@@ -252,7 +252,7 @@ class GridDataService {
        protected function getDataArray($start, $limit) {
                $dataArrayPart = array();
                $dataArrayCount = count($this->dataArray);
-               $end = ($start + $limit < count($this->dataArray) ? $start + $limit : $dataArrayCount);
+               $end = ($start + $limit < $dataArrayCount ? $start + $limit : $dataArrayCount);
 
                // Ensure that there are numerical indexes
                $this->dataArray = array_values(($this->dataArray));
index 93284ca..40cba92 100644 (file)
@@ -547,7 +547,7 @@ class StagesService {
                $requiredGroups = GeneralUtility::intExplode(',', $grList, TRUE);
                $existingGroups = array_keys($this->userGroups);
                $missingGroups = array_diff($requiredGroups, $existingGroups);
-               if (count($missingGroups) > 0) {
+               if (!empty($missingGroups)) {
                        $this->fetchGroupsFromDB($missingGroups);
                }
                // Traversing records in the correct order
index a2b414e..24710e0 100644 (file)
@@ -47,7 +47,7 @@ class WorkspaceService implements \TYPO3\CMS\Core\SingletonInterface {
                }
                // add custom workspaces (selecting all, filtering by BE_USER check):
                $customWorkspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, title, adminusers, members', 'sys_workspace', 'pid = 0' . BackendUtility::deleteClause('sys_workspace'), '', 'title');
-               if (count($customWorkspaces)) {
+               if (!empty($customWorkspaces)) {
                        foreach ($customWorkspaces as $workspace) {
                                if ($GLOBALS['BE_USER']->checkWorkspace($workspace)) {
                                        $availableWorkspaces[$workspace['uid']] = $workspace['title'];
@@ -218,7 +218,7 @@ class WorkspaceService implements \TYPO3\CMS\Core\SingletonInterface {
                                        $recs = array_merge($recs, $moveRecs);
                                }
                                $recs = $this->filterPermittedElements($recs, $table);
-                               if (count($recs)) {
+                               if (!empty($recs)) {
                                        $output[$table] = $recs;
                                }
                        }