| Conditions | 19 |
| Paths | 823 |
| Total Lines | 85 |
| 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 |
||
| 123 | public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = true): DataResponse { |
||
| 124 | |||
| 125 | // only search for string larger than a given threshold |
||
| 126 | $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
||
| 127 | if (strlen($search) < $threshold) { |
||
| 128 | return new DataResponse($this->result); |
||
| 129 | } |
||
| 130 | |||
| 131 | // never return more than the max. number of results configured in the config.php |
||
| 132 | $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0); |
||
| 133 | if ($maxResults > 0) { |
||
| 134 | $perPage = min($perPage, $maxResults); |
||
| 135 | } |
||
| 136 | if ($perPage <= 0) { |
||
| 137 | throw new OCSBadRequestException('Invalid perPage argument'); |
||
| 138 | } |
||
| 139 | if ($page <= 0) { |
||
| 140 | throw new OCSBadRequestException('Invalid page'); |
||
| 141 | } |
||
| 142 | |||
| 143 | $shareTypes = [ |
||
| 144 | Share::SHARE_TYPE_USER, |
||
| 145 | ]; |
||
| 146 | |||
| 147 | if ($itemType === null) { |
||
| 148 | throw new OCSBadRequestException('Missing itemType'); |
||
| 149 | } elseif ($itemType === 'file' || $itemType === 'folder') { |
||
| 150 | if ($this->shareManager->allowGroupSharing()) { |
||
| 151 | $shareTypes[] = Share::SHARE_TYPE_GROUP; |
||
| 152 | } |
||
| 153 | |||
| 154 | if ($this->isRemoteSharingAllowed($itemType)) { |
||
| 155 | $shareTypes[] = Share::SHARE_TYPE_REMOTE; |
||
| 156 | } |
||
| 157 | |||
| 158 | if ($this->isRemoteGroupSharingAllowed($itemType)) { |
||
| 159 | $shareTypes[] = Share::SHARE_TYPE_REMOTE_GROUP; |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) { |
||
| 163 | $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
||
| 164 | } |
||
| 165 | } else { |
||
| 166 | $shareTypes[] = Share::SHARE_TYPE_GROUP; |
||
| 167 | $shareTypes[] = Share::SHARE_TYPE_EMAIL; |
||
| 168 | } |
||
| 169 | |||
| 170 | // FIXME: DI |
||
| 171 | if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
||
| 172 | $shareTypes[] = Share::SHARE_TYPE_CIRCLE; |
||
| 173 | } |
||
| 174 | |||
| 175 | if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
||
| 176 | $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
||
| 177 | sort($shareTypes); |
||
| 178 | } else if (is_numeric($shareType)) { |
||
| 179 | $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
||
| 180 | sort($shareTypes); |
||
| 181 | } |
||
| 182 | |||
| 183 | $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
||
| 184 | $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
||
| 185 | $this->limit = (int) $perPage; |
||
| 186 | $this->offset = $perPage * ($page - 1); |
||
| 187 | |||
| 188 | list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
||
| 189 | |||
| 190 | // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
||
| 191 | if(isset($result['exact'])) { |
||
| 192 | $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
||
| 193 | } |
||
| 194 | $this->result = array_merge($this->result, $result); |
||
| 195 | $response = new DataResponse($this->result); |
||
| 196 | |||
| 197 | if ($hasMoreResults) { |
||
| 198 | $response->addHeader('Link', $this->getPaginationLink($page, [ |
||
| 199 | 'search' => $search, |
||
| 200 | 'itemType' => $itemType, |
||
| 201 | 'shareType' => $shareTypes, |
||
| 202 | 'perPage' => $perPage, |
||
| 203 | ])); |
||
| 204 | } |
||
| 205 | |||
| 206 | return $response; |
||
| 207 | } |
||
| 208 | |||
| 260 |