[CLEANUP] Code cleanup in ext:core/Collection 00/33800/3
authorWouter Wolters <typo3@wouterwolters.nl>
Tue, 4 Nov 2014 18:58:29 +0000 (19:58 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 5 Nov 2014 21:08:25 +0000 (22:08 +0100)
* Use short class name where possible
* Correct curly bracket at end of defining the interface
* Create getDatabaseConnection method

Resolves: #62704
Releases: master
Change-Id: I2f52a045a34aa188e79f9b729e3df34a27bf9220
Reviewed-on: http://review.typo3.org/33800
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Collection/AbstractRecordCollection.php
typo3/sysext/core/Classes/Collection/CollectionInterface.php
typo3/sysext/core/Classes/Collection/EditableCollectionInterface.php
typo3/sysext/core/Classes/Collection/NameableCollectionInterface.php
typo3/sysext/core/Classes/Collection/PersistableCollectionInterface.php
typo3/sysext/core/Classes/Collection/RecordCollectionRepository.php
typo3/sysext/core/Classes/Collection/SortableCollectionInterface.php
typo3/sysext/core/Classes/Collection/StaticRecordCollection.php

index b45368d..3d72d42 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Abstract implementation of a RecordCollection
  *
@@ -27,7 +28,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * @author Steffen Ritter <typo3@steffen-ritter.net>
  */
-abstract class AbstractRecordCollection implements \TYPO3\CMS\Core\Collection\RecordCollectionInterface, \TYPO3\CMS\Core\Collection\PersistableCollectionInterface, \TYPO3\CMS\Core\Collection\SortableCollectionInterface {
+abstract class AbstractRecordCollection implements RecordCollectionInterface, PersistableCollectionInterface, SortableCollectionInterface {
 
        /**
         * The table name collections are stored to
@@ -74,7 +75,7 @@ abstract class AbstractRecordCollection implements \TYPO3\CMS\Core\Collection\Re
        /**
         * The local storage
         *
-        * @var SplDoublyLinkedList
+        * @var \SplDoublyLinkedList
         */
        protected $storage;
 
@@ -306,7 +307,11 @@ abstract class AbstractRecordCollection implements \TYPO3\CMS\Core\Collection\Re
         * @return \TYPO3\CMS\Core\Collection\CollectionInterface
         */
        static public function load($id, $fillItems = FALSE) {
-               $collectionRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', static::$storageTableName, 'uid=' . (int)$id . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause(static::$storageTableName));
+               $collectionRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
+                       '*',
+                       static::$storageTableName,
+                       'uid=' . (int)$id . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause(static::$storageTableName)
+               );
                return self::create($collectionRecord, $fillItems);
        }
 
@@ -409,4 +414,4 @@ abstract class AbstractRecordCollection implements \TYPO3\CMS\Core\Collection\Re
                $this->itemTableName = $array['table_name'];
        }
 
-}
+}
\ No newline at end of file
index db109d5..41781c4 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Marker interface for collection classes
  *
index 8c99cff..5e5ca40 100644 (file)
@@ -13,13 +13,14 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Interface for collection classes which es enabled to be modified
  *
  * @author Steffen Ritter <typo3steffen-ritter.net>
  */
-interface EditableCollectionInterface
-{
+interface EditableCollectionInterface {
+
        /**
         * Adds on entry to the collection
         *
@@ -31,10 +32,10 @@ interface EditableCollectionInterface
        /**
         * Adds a set of entries to the collection
         *
-        * @param \TYPO3\CMS\Core\Collection\CollectionInterface $other
+        * @param CollectionInterface $other
         * @return void
         */
-       public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other);
+       public function addAll(CollectionInterface $other);
 
        /**
         * Remove the given entry from collection
index 15ec58a..65add40 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Marker interface for a collection class with title and description
  *
@@ -23,8 +24,8 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * @author Steffen Ritter <typo3steffen-ritter.net>
  */
-interface NameableCollectionInterface
-{
+interface NameableCollectionInterface {
+
        /**
         * Setter for the title
         *
index 9a09da5..a73e9fa 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Interface for collection class being persistable
  *
@@ -24,6 +25,7 @@ namespace TYPO3\CMS\Core\Collection;
  * @author Steffen Ritter <typo3steffen-ritter.net>
  */
 interface PersistableCollectionInterface {
+
        /**
         * Get the identifier of the collection
         *
index 34f6d23..b212820 100644 (file)
@@ -13,6 +13,9 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+
 /**
  * Implements the repository for record collections.
  *
@@ -20,7 +23,11 @@ namespace TYPO3\CMS\Core\Collection;
  */
 class RecordCollectionRepository {
 
+       /**
+        * @var string
+        */
        const TYPE_Static = 'static';
+
        /**
         * Name of the table the collection records are stored to
         *
@@ -46,7 +53,11 @@ class RecordCollectionRepository {
         */
        public function findByUid($uid) {
                $result = NULL;
-               $data = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . (int)$uid . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table));
+               $data = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
+                       '*',
+                       $this->table,
+                       'uid=' . (int)$uid . BackendUtility::deleteClause($this->table)
+               );
                if (is_array($data)) {
                        $result = $this->createDomainObject($data);
                }
@@ -121,12 +132,16 @@ class RecordCollectionRepository {
         */
        protected function queryMultipleRecords(array $conditions = array()) {
                $result = NULL;
-               if (count($conditions) > 0) {
+               if (!empty($conditions)) {
                        $conditionsWhereClause = implode(' AND ', $conditions);
                } else {
                        $conditionsWhereClause = '1=1';
                }
-               $data = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $this->table, $conditionsWhereClause . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table));
+               $data = $this->getDatabaseConnection()->exec_SELECTgetRows(
+                       '*',
+                       $this->table,
+                       $conditionsWhereClause . BackendUtility::deleteClause($this->table)
+               );
                if ($data !== NULL) {
                        $result = $this->createMultipleDomainObjects($data);
                }
@@ -138,11 +153,12 @@ class RecordCollectionRepository {
         *
         * @param array $record Database record to be reconstituted
         * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection
+        * @throws \RuntimeException
         */
        protected function createDomainObject(array $record) {
                switch ($record['type']) {
                        case self::TYPE_Static:
-                               $collection = \TYPO3\CMS\Core\Collection\StaticRecordCollection::create($record);
+                               $collection = StaticRecordCollection::create($record);
                                break;
                        default:
                                throw new \RuntimeException('Unknown record collection type "' . $record['type'], 1328646798);
index 283786e..bbf5ee4 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Interface for collection class being sortable
  *
@@ -24,8 +25,8 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * @author Steffen Ritter <typo3steffen-ritter.net>
  */
-interface SortableCollectionInterface
-{
+interface SortableCollectionInterface {
+
        /**
         * Sorts collection via given callBackFunction
         *
index 86f533e..5c61e0b 100644 (file)
@@ -13,12 +13,13 @@ namespace TYPO3\CMS\Core\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 /**
  * Implementation of a RecordCollection for static TCA-Records
  *
  * @author Steffen Ritter <typo3@steffen-ritter.net>
  */
-class StaticRecordCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCollection implements \TYPO3\CMS\Core\Collection\EditableCollectionInterface {
+class StaticRecordCollection extends AbstractRecordCollection implements EditableCollectionInterface {
 
        /**
         * Creates a new collection objects and reconstitutes the
@@ -29,8 +30,11 @@ class StaticRecordCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCo
         * @return \TYPO3\CMS\Core\Collection\StaticRecordCollection
         */
        static public function create(array $collectionRecord, $fillItems = FALSE) {
-               /** @var $collection \TYPO3\CMS\Core\Collection\StaticRecordCollection */
-               $collection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $collectionRecord['table_name']);
+               /** @var $collection StaticRecordCollection */
+               $collection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       'TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection',
+                       $collectionRecord['table_name']
+               );
                $collection->fromArray($collectionRecord);
                if ($fillItems) {
                        $collection->loadContents();
@@ -42,6 +46,7 @@ class StaticRecordCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCo
         * Creates this object.
         *
         * @param string $tableName Name of the table to be working on
+        * @throws \RuntimeException
         */
        public function __construct($tableName = NULL) {
                parent::__construct();
@@ -103,10 +108,10 @@ class StaticRecordCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCo
        /**
         * Adds a set of entries to the collection
         *
-        * @param \TYPO3\CMS\Core\Collection\CollectionInterface $other
+        * @param CollectionInterface $other
         * @return void
         */
-       public function addAll(\TYPO3\CMS\Core\Collection\CollectionInterface $other) {
+       public function addAll(CollectionInterface $other) {
                foreach ($other as $value) {
                        $this->add($value);
                }
@@ -151,14 +156,29 @@ class StaticRecordCollection extends \TYPO3\CMS\Core\Collection\AbstractRecordCo
         */
        protected function getCollectedRecords() {
                $relatedRecords = array();
-               $resource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query($this->getItemTableName() . '.*', self::$storageTableName, 'sys_collection_entries', $this->getItemTableName(), 'AND ' . self::$storageTableName . '.uid=' . (int)$this->getIdentifier());
+               $resource = $this->getDatabaseConnection()->exec_SELECT_mm_query(
+                       $this->getItemTableName() . '.*',
+                       self::$storageTableName,
+                       'sys_collection_entries',
+                       $this->getItemTableName(),
+                       'AND ' . self::$storageTableName . '.uid=' . (int)$this->getIdentifier()
+               );
                if ($resource) {
-                       while ($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resource)) {
+                       while ($record = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) {
                                $relatedRecords[] = $record;
                        }
-                       $GLOBALS['TYPO3_DB']->sql_free_result($resource);
+                       $this->getDatabaseConnection()->sql_free_result($resource);
                }
                return $relatedRecords;
        }
 
+       /**
+        * Gets the database object.
+        *
+        * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }