| Conditions | 3 |
| Paths | 4 |
| Total Lines | 69 |
| 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 |
||
| 63 | function getACL() { |
||
|
|
|||
| 64 | // getACL is called so frequently that we cache the config result |
||
| 65 | if ($this->disableFreeBusy === null) { |
||
| 66 | $this->disableFreeBusy = ($this->config->getAppValue('dav', 'disableFreeBusy', 'no') === 'yes'); |
||
| 67 | } |
||
| 68 | |||
| 69 | $commonAcl = [ |
||
| 70 | [ |
||
| 71 | 'privilege' => '{DAV:}read', |
||
| 72 | 'principal' => $this->getOwner(), |
||
| 73 | 'protected' => true, |
||
| 74 | ], |
||
| 75 | [ |
||
| 76 | 'privilege' => '{DAV:}read', |
||
| 77 | 'principal' => $this->getOwner() . '/calendar-proxy-read', |
||
| 78 | 'protected' => true, |
||
| 79 | ], |
||
| 80 | [ |
||
| 81 | 'privilege' => '{DAV:}read', |
||
| 82 | 'principal' => $this->getOwner() . '/calendar-proxy-write', |
||
| 83 | 'protected' => true, |
||
| 84 | ], |
||
| 85 | ]; |
||
| 86 | |||
| 87 | // schedule-send is an aggregate privilege for: |
||
| 88 | // - schedule-send-invite |
||
| 89 | // - schedule-send-reply |
||
| 90 | // - schedule-send-freebusy |
||
| 91 | // |
||
| 92 | // If FreeBusy is disabled, we have to remove the latter privilege |
||
| 93 | |||
| 94 | if ($this->disableFreeBusy) { |
||
| 95 | return array_merge($commonAcl, [ |
||
| 96 | [ |
||
| 97 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
||
| 98 | 'principal' => $this->getOwner(), |
||
| 99 | 'protected' => true, |
||
| 100 | ], |
||
| 101 | [ |
||
| 102 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-invite', |
||
| 103 | 'principal' => $this->getOwner() . '/calendar-proxy-write', |
||
| 104 | 'protected' => true, |
||
| 105 | ], |
||
| 106 | [ |
||
| 107 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
||
| 108 | 'principal' => $this->getOwner(), |
||
| 109 | 'protected' => true, |
||
| 110 | ], |
||
| 111 | [ |
||
| 112 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send-reply', |
||
| 113 | 'principal' => $this->getOwner() . '/calendar-proxy-write', |
||
| 114 | 'protected' => true, |
||
| 115 | ], |
||
| 116 | ]); |
||
| 117 | } |
||
| 118 | |||
| 119 | return array_merge($commonAcl, [ |
||
| 120 | [ |
||
| 121 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
||
| 122 | 'principal' => $this->getOwner(), |
||
| 123 | 'protected' => true, |
||
| 124 | ], |
||
| 125 | [ |
||
| 126 | 'privilege' => '{' . CalDAVPlugin::NS_CALDAV . '}schedule-send', |
||
| 127 | 'principal' => $this->getOwner() . '/calendar-proxy-write', |
||
| 128 | 'protected' => true, |
||
| 129 | ], |
||
| 130 | ]); |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
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.