| Conditions | 12 |
| Paths | 10 |
| Total Lines | 30 |
| Code Lines | 15 |
| Lines | 11 |
| Ratio | 36.67 % |
| 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 |
||
| 84 | function getChild($name) { |
||
| 85 | // Special nodes |
||
| 86 | if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
||
| 87 | return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
||
| 88 | } |
||
| 89 | if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
||
| 90 | return new Outbox($this->principalInfo['uri']); |
||
| 91 | } |
||
| 92 | View Code Duplication | if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
| 93 | return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
||
| 94 | } |
||
| 95 | |||
| 96 | // Calendars |
||
| 97 | foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
||
| 98 | if ($calendar['uri'] === $name) { |
||
| 99 | return new Calendar($this->caldavBackend, $calendar, $this->l10n); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | View Code Duplication | if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 104 | foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
||
| 105 | if ($subscription['uri'] === $name) { |
||
| 106 | return new Subscription($this->caldavBackend, $subscription); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | } |
||
| 111 | |||
| 112 | throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
||
| 113 | } |
||
| 114 | } |
||
| 115 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.