| Conditions | 9 |
| Paths | 20 |
| Total Lines | 113 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 85 | public function getCSSVariables(): array { |
||
| 86 | $colorMainText = '#222222'; |
||
| 87 | $colorMainBackground = '#ffffff'; |
||
| 88 | $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground)); |
||
| 89 | $colorBoxShadow = $this->util->darken($colorMainBackground, 70); |
||
| 90 | $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); |
||
| 91 | |||
| 92 | $variables = [ |
||
| 93 | '--color-main-background' => $colorMainBackground, |
||
| 94 | '--color-main-background-rgb' => $colorMainBackgroundRGB, |
||
| 95 | '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)', |
||
| 96 | |||
| 97 | // to use like this: background-image: linear-gradient(0, var('--gradient-main-background)); |
||
| 98 | '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%', |
||
| 99 | |||
| 100 | // used for different active/hover/focus/disabled states |
||
| 101 | '--color-background-hover' => $this->util->darken($colorMainBackground, 4), |
||
| 102 | '--color-background-dark' => $this->util->darken($colorMainBackground, 7), |
||
| 103 | '--color-background-darker' => $this->util->darken($colorMainBackground, 14), |
||
| 104 | |||
| 105 | '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10), |
||
| 106 | '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20), |
||
| 107 | |||
| 108 | // primary related colours |
||
| 109 | '--color-primary' => $this->primaryColor, |
||
| 110 | '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', |
||
| 111 | '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 80), |
||
| 112 | '--color-primary-light' => $this->util->mix($this->primaryColor, $colorMainBackground, 10), |
||
| 113 | '--color-primary-light-text' => $this->primaryColor, |
||
| 114 | '--color-primary-light-hover' => $this->util->mix($this->primaryColor, $colorMainText, 10), |
||
| 115 | '--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7), |
||
| 116 | // used for buttons, inputs... |
||
| 117 | '--color-primary-element' => $this->util->elementColor($this->primaryColor), |
||
| 118 | '--color-primary-element-hover' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 80), |
||
| 119 | '--color-primary-element-light' => $this->util->lighten($this->util->elementColor($this->primaryColor), 15), |
||
| 120 | '--color-primary-element-lighter' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 15), |
||
| 121 | |||
| 122 | // max contrast for WCAG compliance |
||
| 123 | '--color-main-text' => $colorMainText, |
||
| 124 | '--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33), |
||
| 125 | '--color-text-light' => $colorMainText, |
||
| 126 | '--color-text-lighter' => $this->util->lighten($colorMainText, 33), |
||
| 127 | |||
| 128 | // info/warning/success feedback colours |
||
| 129 | '--color-error' => '#e9322d', |
||
| 130 | '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 80), |
||
| 131 | '--color-warning' => '#eca700', |
||
| 132 | '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 80), |
||
| 133 | '--color-success' => '#46ba61', |
||
| 134 | '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 80), |
||
| 135 | |||
| 136 | // used for the icon loading animation |
||
| 137 | '--color-loading-light' => '#cccccc', |
||
| 138 | '--color-loading-dark' => '#444444', |
||
| 139 | |||
| 140 | '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
||
| 141 | '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)", |
||
| 142 | |||
| 143 | '--color-border' => $this->util->darken($colorMainBackground, 7), |
||
| 144 | '--color-border-dark' => $this->util->darken($colorMainBackground, 14), |
||
| 145 | |||
| 146 | '--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", |
||
| 147 | '--default-font-size' => '15px', |
||
| 148 | |||
| 149 | // TODO: support "(prefers-reduced-motion)" |
||
| 150 | '--animation-quick' => '100ms', |
||
| 151 | '--animation-slow' => '300ms', |
||
| 152 | |||
| 153 | // Default variables -------------------------------------------- |
||
| 154 | '--border-radius' => '3px', |
||
| 155 | '--border-radius-large' => '10px', |
||
| 156 | // pill-style button, value is large so big buttons also have correct roundness |
||
| 157 | '--border-radius-pill' => '100px', |
||
| 158 | |||
| 159 | '--default-line-height' => '24px', |
||
| 160 | |||
| 161 | // various structure data |
||
| 162 | '--header-height' => '50px', |
||
| 163 | '--navigation-width' => '300px', |
||
| 164 | '--sidebar-min-width' => '300px', |
||
| 165 | '--sidebar-max-width' => '500px', |
||
| 166 | '--list-min-width' => '200px', |
||
| 167 | '--list-max-width' => '300px', |
||
| 168 | '--header-menu-item-height' => '44px', |
||
| 169 | '--header-menu-profile-item-height' => '66px', |
||
| 170 | |||
| 171 | // mobile. Keep in sync with core/js/js.js |
||
| 172 | '--breakpoint-mobile' => '1024px', |
||
| 173 | |||
| 174 | // invert filter if primary is too bright |
||
| 175 | // to be used for legacy reasons only. Use inline |
||
| 176 | // svg with proper css variable instead or material |
||
| 177 | // design icons. |
||
| 178 | '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'unset', |
||
| 179 | '--background-invert-if-dark' => 'unset', |
||
| 180 | ]; |
||
| 181 | |||
| 182 | // Register image variables only if custom-defined |
||
| 183 | $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor'; |
||
| 184 | foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) { |
||
| 185 | if ($this->imageManager->hasImage($image)) { |
||
| 186 | // If primary as background has been request, let's not define the background image |
||
| 187 | if ($image === 'background' && $backgroundDeleted) { |
||
| 188 | $variables["--image-background-plain"] = true; |
||
| 189 | continue; |
||
| 190 | } else if ($image === 'background') { |
||
| 191 | $variables['--image-background-size'] = 'cover'; |
||
| 192 | } |
||
| 193 | $variables["--image-$image"] = "url('".$this->imageManager->getImageUrl($image)."')"; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | return $variables; |
||
| 198 | } |
||
| 204 |