| Conditions | 10 |
| Paths | 8 |
| Total Lines | 32 |
| 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 |
||
| 102 | protected function _isEditingForbidden(PostingInterface $posting, CurrentUserInterface $User) |
||
| 103 | { |
||
| 104 | if ($User->isLoggedIn() !== true) { |
||
| 105 | return true; |
||
| 106 | } elseif ($User->permission('saito.core.posting.edit.unrestricted')) { |
||
| 107 | return false; |
||
| 108 | } |
||
| 109 | |||
| 110 | $editPeriod = Configure::read('Saito.Settings.edit_period') * 60; |
||
| 111 | $timeLimit = $editPeriod + ($posting->get('time')->format('U')); |
||
| 112 | $isOverTime = time() > $timeLimit; |
||
| 113 | |||
| 114 | $isOwn = $User->getId() === $posting->get('user_id'); |
||
| 115 | |||
| 116 | if ($User->permission('saito.core.posting.edit.restricted')) { |
||
| 117 | if ($isOwn && $isOverTime && !$posting->isPinned()) { |
||
| 118 | return 'time'; |
||
| 119 | } else { |
||
| 120 | return false; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!$isOwn) { |
||
| 125 | return 'user'; |
||
| 126 | } elseif ($isOverTime) { |
||
| 127 | return 'time'; |
||
| 128 | } elseif ($this->isLocked()) { |
||
| 129 | return 'locked'; |
||
| 130 | } |
||
| 131 | |||
| 132 | return false; |
||
| 133 | } |
||
| 134 | |||
| 177 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.