| Conditions | 7 |
| Paths | 24 |
| Total Lines | 66 |
| Code Lines | 33 |
| 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 |
||
| 60 | $this->menuLogin(), |
||
| 61 | $this->menuLogout(), |
||
| 62 | ]); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Create a menu of palette options |
||
| 67 | * |
||
| 68 | * @return Menu |
||
| 69 | */ |
||
| 70 | public function menuPalette(): Menu |
||
| 71 | { |
||
| 72 | /* I18N: A colour scheme */ |
||
| 73 | $menu = new Menu(I18N::translate('Palette'), '#', 'menu-color'); |
||
| 74 | |||
| 75 | foreach ($this->palettes() as $palette_id => $palette_name) { |
||
| 76 | $url = $this->request->getRequestUri(); |
||
| 77 | $url = preg_replace('/&themecolor=[a-z]+/', '', $url); |
||
| 78 | $url .= '&themecolor=' . $palette_id; |
||
| 79 | |||
| 80 | $menu->addSubmenu(new Menu( |
||
| 81 | $palette_name, |
||
| 82 | '#', |
||
| 83 | 'menu-color-' . $palette_id . ($this->palette() === $palette_id ? ' active' : ''), |
||
| 84 | [ |
||
| 85 | 'onclick' => 'document.location=\'' . $url . '\'', |
||
| 86 | ] |
||
| 87 | )); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $menu; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * A list of CSS files to include for this page. |
||
| 95 | * |
||
| 96 | * @return string[] |
||
| 97 | */ |
||
| 98 | public function stylesheets(): array |
||
| 99 | { |
||
| 100 | return [ |
||
| 101 | asset('css/colors.min.css'), |
||
| 102 | asset('css/colors/' . $this->palette() . '.min.css'), |
||
| 103 | ]; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | private function palette(): string { |
||
| 110 | $palettes = $this->palettes(); |
||
| 111 | |||
| 112 | // If we've selected a new palette, and we are logged in, set this value as a default. |
||
| 113 | if (isset($_GET['themecolor'])) { |
||
| 114 | // Request to change color |
||
| 115 | $palette = $_GET['themecolor']; |
||
| 116 | Auth::user()->setPreference('themecolor', $palette); |
||
| 117 | if (Auth::isAdmin()) { |
||
| 118 | Site::setPreference('DEFAULT_COLOR_PALETTE', $palette); |
||
| 119 | } |
||
| 120 | unset($_GET['themecolor']); |
||
| 121 | // Rember that we have selected a value |
||
| 122 | Session::put('subColor', $palette); |
||
| 123 | } |
||
| 124 | |||
| 125 | // If we are logged in, use our preference |
||
| 126 | $palette = Auth::user()->getPreference('themecolor'); |
||
| 190 |