| Conditions | 11 |
| Paths | 12 |
| Total Lines | 39 |
| Code Lines | 21 |
| 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 |
||
| 98 | protected function _isEditingAllowed(BasicPostingInterface $posting, CurrentUserInterface $User) |
||
| 99 | { |
||
| 100 | if ($User->isLoggedIn() !== true) { |
||
| 101 | return false; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($User->permission('saito.core.posting.edit.unrestricted')) { |
||
| 105 | return true; |
||
| 106 | } |
||
| 107 | |||
| 108 | /// Check category |
||
| 109 | $action = $posting->isRoot() ? 'thread' : 'answer'; |
||
| 110 | $categoryAllowed = $User->getCategories() |
||
| 111 | ->permission($action, $posting->get('category_id')); |
||
| 112 | if (!$categoryAllowed) { |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | $editPeriod = Configure::read('Saito.Settings.edit_period') * 60; |
||
| 117 | $timeLimit = $editPeriod + ($posting->get('time')->format('U')); |
||
| 118 | $isOverTime = time() > $timeLimit; |
||
| 119 | |||
| 120 | $isOwn = $User->permission( |
||
| 121 | 'saito.core.posting.edit', |
||
| 122 | (new ResourceAI())->onOwner($posting->get('user_id')) |
||
| 123 | ); |
||
| 124 | |||
| 125 | if (!$isOverTime && $isOwn && !$this->isLocked()) { |
||
| 126 | // Normal posting without special conditions. |
||
| 127 | return true; |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($User->permission('saito.core.posting.edit.restricted')) { |
||
| 131 | if (!$isOwn || $posting->isPinned()) { |
||
| 132 | return true; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | return false; |
||
| 137 | } |
||
| 181 |