| Conditions | 18 |
| Paths | 16384 |
| Total Lines | 76 |
| Code Lines | 44 |
| Lines | 76 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 49 | function buildXml() |
||
| 50 | { |
||
| 51 | if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') { |
||
| 52 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
||
| 53 | } |
||
| 54 | |||
| 55 | if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME)) { |
||
| 56 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED); |
||
| 57 | } |
||
| 58 | |||
| 59 | if (!isset($_GET["fileName"])) { |
||
| 60 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
||
| 61 | } |
||
| 62 | if (!isset($_GET["newFileName"])) { |
||
| 63 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
||
| 64 | } |
||
| 65 | |||
| 66 | $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); |
||
| 67 | $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["fileName"]); |
||
| 68 | $newFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["newFileName"]); |
||
| 69 | |||
| 70 | $oRenamedFileNode = new Ckfinder_Connector_Utils_XmlNode("RenamedFile"); |
||
| 71 | $this->_connectorNode->addChild($oRenamedFileNode); |
||
| 72 | $oRenamedFileNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName)); |
||
| 73 | |||
| 74 | $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig(); |
||
| 75 | if (!$resourceTypeInfo->checkExtension($newFileName)) { |
||
| 76 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName) || $resourceTypeInfo->checkIsHiddenFile($fileName)) { |
||
| 80 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!CKFinder_Connector_Utils_FileSystem::checkFileName($newFileName) || $resourceTypeInfo->checkIsHiddenFile($newFileName)) { |
||
| 84 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME); |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!$resourceTypeInfo->checkExtension($fileName, false)) { |
||
| 88 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($_config->forceAscii()) { |
||
| 92 | $newFileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($newFileName); |
||
| 93 | } |
||
| 94 | $filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName); |
||
| 95 | $newFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $newFileName); |
||
| 96 | |||
| 97 | $bMoved = false; |
||
| 98 | |||
| 99 | if (!file_exists($filePath)) { |
||
| 100 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!is_writable(dirname($newFilePath))) { |
||
| 104 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!is_writable($filePath)) { |
||
| 108 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED); |
||
| 109 | } |
||
| 110 | if (file_exists($newFilePath)) { |
||
| 111 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST); |
||
| 112 | } |
||
| 113 | |||
| 114 | $bMoved = @rename($filePath, $newFilePath); |
||
| 115 | |||
| 116 | if (!$bMoved) { |
||
| 117 | $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNKNOWN, "File " . CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName) . "has not been renamed"); |
||
| 118 | } else { |
||
| 119 | $oRenamedFileNode->addAttribute("newName", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($newFileName)); |
||
| 120 | |||
| 121 | $thumbPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName); |
||
| 122 | CKFinder_Connector_Utils_FileSystem::unlink($thumbPath); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 |