[TASK] Code cleanup RenameFileController.php 98/37398/2
authorMichael Oehlhof <typo3@oehlhof.de>
Sun, 1 Mar 2015 08:07:26 +0000 (09:07 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 1 Mar 2015 10:52:32 +0000 (11:52 +0100)
backend/Classes/Controller/File/RenameFileController.php
To get it "green" in PhpStorm several changes are made:

- set correct parameter type in PhpDoc comment
- set correct return type in PhpDoc comment
- add getter for LanguageService
- add getter for DocumentTemplate

Resolves: #65426
Releases: master
Change-Id: I1794d12fed33ab06d460c043632139bc30682a76
Reviewed-on: http://review.typo3.org/37398
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>
typo3/sysext/backend/Classes/Controller/File/RenameFileController.php
typo3/sysext/core/Classes/Resource/ResourceFactory.php

index a587889..a556cc1 100644 (file)
@@ -48,7 +48,7 @@ class RenameFileController {
        /**
         * The file or folder object that should be renamed
         *
        /**
         * The file or folder object that should be renamed
         *
-        * @var \TYPO3\CMS\Core\Resource\ResourceInterface $fileOrFolderObject
+        * @var \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject
         */
        protected $fileOrFolderObject;
 
         */
        protected $fileOrFolderObject;
 
@@ -78,7 +78,7 @@ class RenameFileController {
        /**
         * Initialize
         *
        /**
         * Initialize
         *
-        * @return void
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
         */
        protected function init() {
                // Initialize GPvars:
         */
        protected function init() {
                // Initialize GPvars:
@@ -89,8 +89,8 @@ class RenameFileController {
                        $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
                }
                if (!$this->fileOrFolderObject) {
                        $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
                }
                if (!$this->fileOrFolderObject) {
-                       $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
-                       $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
+                       $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
+                       $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
                        throw new \RuntimeException($title . ': ' . $message, 1294586844);
                }
                if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
                        throw new \RuntimeException($title . ': ' . $message, 1294586844);
                }
                if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
@@ -129,8 +129,8 @@ class RenameFileController {
         */
        public function main() {
                // Make page header:
         */
        public function main() {
                // Make page header:
-               $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
-               $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
+               $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
+               $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
                if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                        $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
                } else {
                if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                        $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
                } else {
@@ -141,15 +141,15 @@ class RenameFileController {
                $pageContent .= '
 
                        <div class="form-group">
                $pageContent .= '
 
                        <div class="form-group">
-                               <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(40) . ' />
+                               <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' />
                                <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
                        </div>
                ';
                // Making submit button:
                $pageContent .= '
                        <div class="form-group">
                                <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
                        </div>
                ';
                // Making submit button:
                $pageContent .= '
                        <div class="form-group">
-                               <input class="btn btn-primary" type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" />
-                               <input class="btn btn-danger" type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
+                               <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" />
+                               <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
                                <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
                                ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
                        </div>
                                <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
                                ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
                        </div>
@@ -161,12 +161,12 @@ class RenameFileController {
                $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename');
                // Back
                if ($this->returnUrl) {
                $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename');
                // Back
                if ($this->returnUrl) {
-                       $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
+                       $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
                }
                // Add the HTML as a section:
                $markerArray = array(
                        'CSH' => $docHeaderButtons['csh'],
                }
                // Add the HTML as a section:
                $markerArray = array(
                        'CSH' => $docHeaderButtons['csh'],
-                       'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
+                       'FUNC_MENU' => '',
                        'CONTENT' => $pageContent,
                        'PATH' => $this->title
                );
                        'CONTENT' => $pageContent,
                        'PATH' => $this->title
                );
@@ -184,4 +184,22 @@ class RenameFileController {
                echo $this->content;
        }
 
                echo $this->content;
        }
 
+       /**
+        * Returns LanguageService
+        *
+        * @return \TYPO3\CMS\Lang\LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
+
+       /**
+        * Returns an instance of DocumentTemplate
+        *
+        * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
+        */
+       protected function getDocumentTemplate() {
+               return $GLOBALS['TBE_TEMPLATE'];
+       }
+
 }
 }
index 18d175b..37aedf3 100644 (file)
@@ -422,7 +422,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
         * - "file:23"
         *
         * @param string $input
         * - "file:23"
         *
         * @param string $input
-        * @return FileInterface|Folder
+        * @return File|Folder
         */
        public function retrieveFileOrFolderObject($input) {
                // Remove PATH_site because absolute paths under Windows systems contain ':'
         */
        public function retrieveFileOrFolderObject($input) {
                // Remove PATH_site because absolute paths under Windows systems contain ':'