[CLEANUP] File object 29/39429/4
authorSascha Egerer <sascha.egerer@dkd.de>
Mon, 11 May 2015 10:29:56 +0000 (12:29 +0200)
committerFrank Nägler <typo3@naegler.net>
Mon, 1 Jun 2015 15:15:49 +0000 (17:15 +0200)
In the TYPO3\CMS\Core\Resource\File object the logic to load
metaDataProperties was implemented at multiple places but there
is also a method _getMetaData() that handles this logic.
The method _getMetaData() should be used instead of duplicating
the logic at multiple places.

Additionally some code is removed, which checks the
metaDataProperties member for NULL values, which can never
be the case.

Resolves: #66878
Releases: master
Change-Id: I01939a66aa58629f2c6dc08656647375460cc4e9
Reviewed-on: http://review.typo3.org/39429
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/core/Classes/Resource/File.php

index f2225fc..9687614 100644 (file)
@@ -55,12 +55,12 @@ class File extends AbstractFile {
         * @param ResourceStorage $storage
         * @param array $metaData
         */
-       public function __construct(array $fileData, ResourceStorage $storage, $metaData = array()) {
+       public function __construct(array $fileData, ResourceStorage $storage, array $metaData = array()) {
                $this->identifier = $fileData['identifier'];
                $this->name = $fileData['name'];
                $this->properties = $fileData;
                $this->storage = $storage;
-               if ($metaData !== array()) {
+               if (!empty($metaData)) {
                        $this->metaDataLoaded = TRUE;
                        $this->metaDataProperties = $metaData;
                }
@@ -79,10 +79,8 @@ class File extends AbstractFile {
                if (parent::hasProperty($key)) {
                        return parent::getProperty($key);
                } else {
-                       if (!$this->metaDataLoaded) {
-                               $this->loadMetaData();
-                       }
-                       return array_key_exists($key, $this->metaDataProperties) ? $this->metaDataProperties[$key] : NULL;
+                       $metaData = $this->_getMetaData();
+                       return isset($metaData[$key]) ? $metaData[$key] : NULL;
                }
        }
 
@@ -95,10 +93,7 @@ class File extends AbstractFile {
         */
        public function hasProperty($key) {
                if (!parent::hasProperty($key)) {
-                       if (!$this->metaDataLoaded) {
-                               $this->loadMetaData();
-                       }
-                       return array_key_exists($key, $this->metaDataProperties);
+                       return array_key_exists($key, $this->_getMetaData());
                }
                return TRUE;
        }
@@ -110,16 +105,13 @@ class File extends AbstractFile {
         * @return array
         */
        public function getProperties() {
-               if (!$this->metaDataLoaded) {
-                       $this->loadMetaData();
-               }
-               return array_merge(parent::getProperties(), array_diff_key((array)$this->metaDataProperties, parent::getProperties()));
+               return array_merge(parent::getProperties(), array_diff_key($this->_getMetaData(), parent::getProperties()));
        }
 
        /**
         * Returns the MetaData
         *
-        * @return array|null
+        * @return array
         * @internal
         */
        public function _getMetaData() {
@@ -244,11 +236,7 @@ class File extends AbstractFile {
         * @return void
         */
        public function _updateMetaDataProperties(array $properties) {
-               if ($this->metaDataProperties !== NULL) {
-                       $this->metaDataProperties = array_merge($this->metaDataProperties, $properties);
-               } else {
-                       $this->metaDataProperties = $properties;
-               }
+               $this->metaDataProperties = array_merge($this->metaDataProperties, $properties);
        }
 
        /**