| Conditions | 13 |
| Paths | 54 |
| Total Lines | 48 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 55 | public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
||
| 56 | $hasMoreResults = false; |
||
| 57 | |||
| 58 | // Trim leading and trailing whitespace characters, e.g. when query is copy-pasted |
||
| 59 | $search = trim($search); |
||
| 60 | |||
| 61 | /** @var ISearchResult $searchResult */ |
||
| 62 | $searchResult = $this->c->resolve(SearchResult::class); |
||
| 63 | |||
| 64 | foreach ($shareTypes as $type) { |
||
| 65 | if (!isset($this->pluginList[$type])) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | foreach ($this->pluginList[$type] as $plugin) { |
||
| 69 | /** @var ISearchPlugin $searchPlugin */ |
||
| 70 | $searchPlugin = $this->c->resolve($plugin); |
||
| 71 | $hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // Get from lookup server, not a separate share type |
||
| 76 | if ($lookup) { |
||
| 77 | $searchPlugin = $this->c->resolve(LookupPlugin::class); |
||
| 78 | $hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults; |
||
|
|
|||
| 79 | } |
||
| 80 | |||
| 81 | // sanitizing, could go into the plugins as well |
||
| 82 | |||
| 83 | // if we have a exact match, either for the federated cloud id or for the |
||
| 84 | // email address we only return the exact match. It is highly unlikely |
||
| 85 | // that the exact same email address and federated cloud id exists |
||
| 86 | $emailType = new SearchResultType('emails'); |
||
| 87 | $remoteType = new SearchResultType('remotes'); |
||
| 88 | if ($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
||
| 89 | $searchResult->unsetResult($remoteType); |
||
| 90 | } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
||
| 91 | $searchResult->unsetResult($emailType); |
||
| 92 | } |
||
| 93 | |||
| 94 | // if we have an exact local user match with an email-a-like query, |
||
| 95 | // there is no need to show the remote and email matches. |
||
| 96 | $userType = new SearchResultType('users'); |
||
| 97 | if (strpos($search, '@') !== false && $searchResult->hasExactIdMatch($userType)) { |
||
| 98 | $searchResult->unsetResult($remoteType); |
||
| 99 | $searchResult->unsetResult($emailType); |
||
| 100 | } |
||
| 101 | |||
| 102 | return [$searchResult->asArray(), (bool)$hasMoreResults]; |
||
| 103 | } |
||
| 113 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.