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