| Conditions | 29 |
| Paths | 1824 |
| Total Lines | 155 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 28 | public function execute(Request $request, Acl $acl, Config $config, ResourceTypeFactory $resourceTypeFactory) |
||
| 29 | { |
||
| 30 | $data = new \stdClass(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The connector is always enabled here. |
||
| 34 | * |
||
| 35 | * @see CKFinder::checkAuth() |
||
| 36 | */ |
||
| 37 | $data->enabled = true; |
||
| 38 | |||
| 39 | $ln = ''; |
||
| 40 | $lc = str_replace('-', '', ($config->get('licenseKey') ?: $config->get('LicenseKey')) . ' '); |
||
| 41 | $pos = strpos(CKFinder::CHARS, $lc[2]) % 5; |
||
| 42 | |||
| 43 | if ($pos == 1 || $pos == 2) { |
||
| 44 | $ln = $config->get('licenseName') ?: $config->get('LicenseName'); |
||
| 45 | } |
||
| 46 | |||
| 47 | $data->s = $ln; |
||
| 48 | $data->c = trim($lc[1] . $lc[8] . $lc[17] . $lc[22] . $lc[3] . $lc[13] . $lc[11] . $lc[20] . $lc[5] . $lc[24] . $lc[27]); |
||
| 49 | |||
| 50 | // Thumbnails |
||
| 51 | $thumbnailsConfig = $config->get('thumbnails'); |
||
| 52 | |||
| 53 | $thumbnailsEnabled = (bool) $thumbnailsConfig['enabled']; |
||
| 54 | |||
| 55 | if ($thumbnailsEnabled) { |
||
| 56 | $sizes = array(); |
||
| 57 | foreach ($thumbnailsConfig['sizes'] as $sizeInfo) { |
||
| 58 | $sizes[] = sprintf("%dx%d", $sizeInfo['width'], $sizeInfo['height']); |
||
| 59 | } |
||
| 60 | |||
| 61 | $data->thumbs = $sizes; |
||
| 62 | } |
||
| 63 | |||
| 64 | // Images |
||
| 65 | $imagesConfig = $config->get('images'); |
||
| 66 | |||
| 67 | $images = array( |
||
| 68 | 'max' => $imagesConfig['maxWidth'] . 'x' . $imagesConfig['maxHeight'] |
||
| 69 | ); |
||
| 70 | |||
| 71 | if (isset($imagesConfig['sizes'])) { |
||
| 72 | $resize = array(); |
||
| 73 | |||
| 74 | foreach ($imagesConfig['sizes'] as $name => $sizeInfo) { |
||
| 75 | $resize[$name] = $sizeInfo['width'] . 'x' . $sizeInfo['height']; |
||
| 76 | } |
||
| 77 | |||
| 78 | $images['sizes'] = $resize; |
||
| 79 | } |
||
| 80 | |||
| 81 | $data->images = $images; |
||
| 82 | |||
| 83 | $resourceTypesNames = $config->getDefaultResourceTypes() ? : $config->getResourceTypes(); |
||
| 84 | |||
| 85 | $data->resourceTypes = array(); |
||
| 86 | |||
| 87 | if (!empty($resourceTypesNames)) { |
||
| 88 | $phpMaxSize = 0; |
||
| 89 | |||
| 90 | $maxUpload = Utils::returnBytes(ini_get('upload_max_filesize')); |
||
| 91 | if ($maxUpload) { |
||
| 92 | $phpMaxSize = $maxUpload; |
||
| 93 | } |
||
| 94 | |||
| 95 | $maxPost = Utils::returnBytes(ini_get('post_max_size')); |
||
| 96 | if ($maxPost) { |
||
| 97 | $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $maxPost) : $maxPost; |
||
| 98 | } |
||
| 99 | |||
| 100 | //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" |
||
| 101 | $memoryLimit = Utils::returnBytes(@ini_get('memory_limit')); |
||
| 102 | if ($memoryLimit && $memoryLimit != -1) { |
||
| 103 | $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memoryLimit) : $memoryLimit; |
||
| 104 | } |
||
| 105 | |||
| 106 | $data->uploadMaxSize = $phpMaxSize; |
||
| 107 | $data->uploadCheckImages = !$config->get('checkSizeAfterScaling'); |
||
| 108 | |||
| 109 | $requestedType = (string) $request->query->get('type'); |
||
| 110 | |||
| 111 | foreach ($resourceTypesNames as $resourceTypeName) { |
||
| 112 | if ($requestedType && $requestedType !== $resourceTypeName) { |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | |||
| 116 | $aclMask = $acl->getComputedMask($resourceTypeName, '/'); |
||
| 117 | |||
| 118 | if (!(Permission::FOLDER_VIEW & $aclMask)) { |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | |||
| 122 | $resourceType = $resourceTypeFactory->getResourceType($resourceTypeName); |
||
| 123 | |||
| 124 | $resourceTypeObject = array( |
||
| 125 | 'name' => $resourceTypeName, |
||
| 126 | 'allowedExtensions' => implode(",", $resourceType->getAllowedExtensions()), |
||
| 127 | 'deniedExtensions' => implode(",", $resourceType->getDeniedExtensions()), |
||
| 128 | 'hash' => $resourceType->getHash(), |
||
| 129 | 'acl' => $aclMask, |
||
| 130 | 'maxSize' => $resourceType->getMaxSize() ? min($resourceType->getMaxSize(), $phpMaxSize) : $phpMaxSize |
||
| 131 | ); |
||
| 132 | |||
| 133 | $resourceTypeBackend = $resourceType->getBackend(); |
||
| 134 | |||
| 135 | if ($resourceType->isLazyLoaded()) { |
||
| 136 | $resourceTypeObject['hasChildren'] = false; |
||
| 137 | $resourceTypeObject['lazyLoad'] = true; |
||
| 138 | } else { |
||
| 139 | $resourceTypeObject['hasChildren'] = $resourceTypeBackend->containsDirectories($resourceType, $resourceType->getDirectory()); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($label = $resourceType->getLabel()) { |
||
| 143 | $resourceTypeObject['label'] = $label; |
||
| 144 | } |
||
| 145 | |||
| 146 | $useProxyCommand = $resourceTypeBackend->usesProxyCommand(); |
||
| 147 | |||
| 148 | if ($useProxyCommand) { |
||
| 149 | $resourceTypeObject['useProxyCommand'] = true; |
||
| 150 | } else { |
||
| 151 | $baseUrl = $resourceTypeBackend->getBaseUrl(); |
||
| 152 | |||
| 153 | if ($baseUrl) { |
||
|
|
|||
| 154 | $resourceTypeObject['url'] = rtrim(Path::combine($baseUrl, $resourceType->getDirectory()), '/') . '/'; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | |||
| 159 | $trackedOperations = $resourceTypeBackend->getTrackedOperations(); |
||
| 160 | |||
| 161 | if (!empty($trackedOperations)) { |
||
| 162 | $resourceTypeObject['trackedOperations'] = $trackedOperations; |
||
| 163 | } |
||
| 164 | |||
| 165 | $data->resourceTypes[] = $resourceTypeObject; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | $enabledPlugins = $config->get('plugins'); |
||
| 170 | |||
| 171 | if (!empty($enabledPlugins)) { |
||
| 172 | $data->plugins = $enabledPlugins; |
||
| 173 | } |
||
| 174 | |||
| 175 | $proxyCacheLifetime = (int) $config->get('cache.proxyCommand'); |
||
| 176 | |||
| 177 | if ($proxyCacheLifetime) { |
||
| 178 | $data->proxyCache = $proxyCacheLifetime; |
||
| 179 | } |
||
| 180 | |||
| 181 | return $data; |
||
| 182 | } |
||
| 183 | } |
||
| 184 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: