| Conditions | 12 |
| Paths | 160 |
| Total Lines | 37 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 38 | function backendLayoutVars() |
||
| 39 | { |
||
| 40 | $layoutOptions = []; |
||
| 41 | $skin = theme()->settings('skin'); |
||
| 42 | $boxClass = 'success'; |
||
| 43 | $pendingComments = Cache::read('pending_comments', 'pending_comments'); |
||
| 44 | |||
| 45 | if ($pendingComments === false) { |
||
| 46 | $pendingComments = TableRegistry::get('Comment.Comments') |
||
| 47 | ->find()->where(['Comments.status' => 'pending', 'Comments.table_alias' => 'contents']) |
||
| 48 | ->count(); |
||
| 49 | Cache::write('pending_comments', $pendingComments, 'pending_comments'); |
||
| 50 | } |
||
| 51 | $pendingComments = !$pendingComments ? '' : $pendingComments; |
||
| 52 | |||
| 53 | if (strpos($skin, 'blue') !== false || strpos($skin, 'black') !== false) { |
||
| 54 | $boxClass = 'info'; |
||
| 55 | } elseif (strpos($skin, 'green') !== false) { |
||
| 56 | $boxClass = 'success'; |
||
| 57 | } elseif (strpos($skin, 'red') !== false || strpos($skin, 'purple') !== false) { |
||
| 58 | $boxClass = 'danger'; |
||
| 59 | } elseif (strpos($skin, 'yellow') !== false) { |
||
| 60 | $boxClass = 'warning'; |
||
| 61 | } |
||
| 62 | |||
| 63 | if (theme()->settings('fixed_layout')) { |
||
| 64 | $layoutOptions[] = 'fixed'; |
||
| 65 | } |
||
| 66 | if (theme()->settings('boxed_layout')) { |
||
| 67 | $layoutOptions[] = 'layout-boxed'; |
||
| 68 | } |
||
| 69 | if (theme()->settings('collapsed_sidebar')) { |
||
| 70 | $layoutOptions[] = 'sidebar-collapse'; |
||
| 71 | } |
||
| 72 | |||
| 73 | return compact('skin', 'layoutOptions', 'boxClass', 'pendingComments'); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |