| Conditions | 12 |
| Paths | 48 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 31 | public function checkAccess($element, $user = null) |
||
| 32 | { |
||
| 33 | $access = NULL; |
||
| 34 | foreach ($this->accessCheckers as $getter) { |
||
| 35 | foreach ($getter['classes'] as $className) { |
||
| 36 | if ($element instanceof $className) { |
||
| 37 | $access = $getter['get']($element); |
||
| 38 | break; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | if (is_null($access)) { |
||
| 43 | $access = []; |
||
| 44 | } |
||
| 45 | if (is_null($user)) { |
||
| 46 | $user = Users\User::$cur; |
||
| 47 | } |
||
| 48 | if (empty($access)) { |
||
| 49 | return true; |
||
| 50 | } |
||
| 51 | |||
| 52 | if ((!$user->group_id && !empty($access)) || ($user->group_id && !empty($access) && !in_array($user->group_id, $access))) |
||
| 53 | return false; |
||
| 54 | |||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 82 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: