| Conditions | 14 |
| Paths | 52 |
| Total Lines | 68 |
| Code Lines | 43 |
| Lines | 10 |
| Ratio | 14.71 % |
| 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 |
||
| 53 | public function search($search, $limit, $offset, ISearchResult $searchResult) { |
||
| 54 | $result = ['wide' => [], 'exact' => []]; |
||
| 55 | $resultType = new SearchResultType('remotes'); |
||
| 56 | |||
| 57 | // Search in contacts |
||
| 58 | //@todo Pagination missing |
||
| 59 | $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); |
||
| 60 | foreach ($addressBookContacts as $contact) { |
||
| 61 | if (isset($contact['isLocalSystemBook'])) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | if (isset($contact['CLOUD'])) { |
||
| 65 | $cloudIds = $contact['CLOUD']; |
||
| 66 | if (!is_array($cloudIds)) { |
||
| 67 | $cloudIds = [$cloudIds]; |
||
| 68 | } |
||
| 69 | $lowerSearch = strtolower($search); |
||
| 70 | foreach ($cloudIds as $cloudId) { |
||
| 71 | try { |
||
| 72 | list(, $serverUrl) = $this->splitUserRemote($cloudId); |
||
| 73 | } catch (\InvalidArgumentException $e) { |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { |
||
| 78 | if (strtolower($cloudId) === $lowerSearch) { |
||
| 79 | $searchResult->markExactIdMatch($resultType); |
||
| 80 | } |
||
| 81 | $result['exact'][] = [ |
||
| 82 | 'label' => $contact['FN'] . " ($cloudId)", |
||
| 83 | 'value' => [ |
||
| 84 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
||
| 85 | 'shareWith' => $cloudId, |
||
| 86 | 'server' => $serverUrl, |
||
| 87 | ], |
||
| 88 | ]; |
||
| 89 | View Code Duplication | } else { |
|
| 90 | $result['wide'][] = [ |
||
| 91 | 'label' => $contact['FN'] . " ($cloudId)", |
||
| 92 | 'value' => [ |
||
| 93 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
||
| 94 | 'shareWith' => $cloudId, |
||
| 95 | 'server' => $serverUrl, |
||
| 96 | ], |
||
| 97 | ]; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!$this->shareeEnumeration) { |
||
| 104 | $result['wide'] = []; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
||
| 108 | $result['exact'][] = [ |
||
| 109 | 'label' => $search, |
||
| 110 | 'value' => [ |
||
| 111 | 'shareType' => Share::SHARE_TYPE_REMOTE, |
||
| 112 | 'shareWith' => $search, |
||
| 113 | ], |
||
| 114 | ]; |
||
| 115 | } |
||
| 116 | |||
| 117 | $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
||
| 118 | |||
| 119 | return true; |
||
| 120 | } |
||
| 121 | |||
| 138 |