| Conditions | 13 |
| Paths | 49 |
| Total Lines | 37 |
| Code Lines | 26 |
| 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 |
||
| 68 | public function findOne(IUser $user, $shareType, $shareWith) { |
||
| 69 | switch($shareType) { |
||
| 70 | case 0: |
||
| 71 | case 6: |
||
| 72 | $filter = ['UID']; |
||
| 73 | break; |
||
| 74 | case 4: |
||
| 75 | $filter = ['EMAIL']; |
||
| 76 | break; |
||
| 77 | default: |
||
| 78 | return null; |
||
| 79 | } |
||
| 80 | |||
| 81 | $userId = $user->getUID(); |
||
| 82 | $allContacts = $this->contactsManager->search($shareWith, $filter); |
||
| 83 | $contacts = array_filter($allContacts, function($contact) use ($userId) { |
||
| 84 | return $contact['UID'] !== $userId; |
||
| 85 | }); |
||
| 86 | $match = null; |
||
| 87 | |||
| 88 | foreach ($contacts as $contact) { |
||
| 89 | if ($shareType === 4 && isset($contact['EMAIL'])) { |
||
| 90 | if (in_array($shareWith, $contact['EMAIL'])) { |
||
| 91 | $match = $contact; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | if ($shareType === 0 || $shareType === 6) { |
||
| 96 | if ($contact['UID'] === $shareWith && $contact['isLocalSystemBook'] === true) { |
||
| 97 | $match = $contact; |
||
| 98 | break; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | return $match ? $this->contactArrayToEntry($match) : null; |
||
| 104 | } |
||
| 105 | |||
| 140 |