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