| Conditions | 9 |
| Paths | 33 |
| Total Lines | 54 |
| 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 |
||
| 63 | public function search($search, $limit, $offset, ISearchResult $searchResult) { |
||
| 64 | $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
||
| 65 | $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
||
| 66 | // if case of Global Scale we always search the lookup server |
||
| 67 | if (!$isLookupServerEnabled && !$isGlobalScaleEnabled) { |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | |||
| 71 | $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
||
| 72 | $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
||
| 73 | $result = []; |
||
| 74 | |||
| 75 | try { |
||
| 76 | $client = $this->clientService->newClient(); |
||
| 77 | $response = $client->get( |
||
| 78 | $lookupServerUrl . '/users?search=' . urlencode($search), |
||
| 79 | [ |
||
| 80 | 'timeout' => 10, |
||
| 81 | 'connect_timeout' => 3, |
||
| 82 | ] |
||
| 83 | ); |
||
| 84 | |||
| 85 | $body = json_decode($response->getBody(), true); |
||
| 86 | |||
| 87 | foreach ($body as $lookup) { |
||
| 88 | try { |
||
| 89 | $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
||
| 90 | } catch (\Exception $e) { |
||
| 91 | $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
||
| 92 | $this->logger->error($e->getMessage()); |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | if ($this->currentUserRemote === $remote) { |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
||
| 99 | $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
||
| 100 | $result[] = [ |
||
| 101 | 'label' => $label, |
||
| 102 | 'value' => [ |
||
| 103 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
||
| 104 | 'shareWith' => $lookup['federationId'], |
||
| 105 | ], |
||
| 106 | 'extra' => $lookup, |
||
| 107 | ]; |
||
| 108 | } |
||
| 109 | } catch (\Exception $e) { |
||
|
|
|||
| 110 | } |
||
| 111 | |||
| 112 | $type = new SearchResultType('lookup'); |
||
| 113 | $searchResult->addResultSet($type, $result, []); |
||
| 114 | |||
| 115 | return false; |
||
| 116 | } |
||
| 117 | } |
||
| 118 |