Conditions | 14 |
Paths | 320 |
Total Lines | 148 |
Code Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 | $colorPrimaryLight = $this->util->mix($this->primaryColor, $colorMainBackground, -80); |
||
92 | |||
93 | $colorPrimaryElement = $this->util->elementColor($this->primaryColor); |
||
94 | $colorPrimaryElementLight = $this->util->mix($colorPrimaryElement, $colorMainBackground, -80); |
||
95 | |||
96 | $hasCustomLogoHeader = $this->imageManager->hasImage('logo') || $this->imageManager->hasImage('logoheader'); |
||
97 | $hasCustomPrimaryColour = !empty($this->config->getAppValue('theming', 'color')); |
||
98 | |||
99 | $variables = [ |
||
100 | '--color-main-background' => $colorMainBackground, |
||
101 | '--color-main-background-rgb' => $colorMainBackgroundRGB, |
||
102 | '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)', |
||
103 | '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)', |
||
104 | '--filter-background-blur' => 'blur(25px)', |
||
105 | |||
106 | // to use like this: background-image: linear-gradient(0, var('--gradient-main-background)); |
||
107 | '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%', |
||
108 | |||
109 | // used for different active/hover/focus/disabled states |
||
110 | '--color-background-hover' => $this->util->darken($colorMainBackground, 4), |
||
111 | '--color-background-dark' => $this->util->darken($colorMainBackground, 7), |
||
112 | '--color-background-darker' => $this->util->darken($colorMainBackground, 14), |
||
113 | |||
114 | '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10), |
||
115 | '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20), |
||
116 | |||
117 | // primary related colours |
||
118 | '--color-primary' => $this->primaryColor, |
||
119 | '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', |
||
120 | '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60), |
||
121 | '--color-primary-light' => $colorPrimaryLight, |
||
122 | '--color-primary-light-text' => $this->primaryColor, |
||
123 | '--color-primary-light-hover' => $this->util->mix($colorPrimaryLight, $colorMainText, 90), |
||
124 | '--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7), |
||
125 | // used for buttons, inputs... |
||
126 | '--color-primary-element' => $colorPrimaryElement, |
||
127 | '--color-primary-element-text' => $this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff', |
||
128 | '--color-primary-element-hover' => $this->util->mix($colorPrimaryElement, $colorMainBackground, 60), |
||
129 | '--color-primary-element-light' => $colorPrimaryElementLight, |
||
130 | '--color-primary-element-light-text' => $colorPrimaryElement, |
||
131 | '--color-primary-element-light-hover' => $this->util->mix($colorPrimaryElementLight, $colorMainText, 90), |
||
132 | '--color-primary-element-text-dark' => $this->util->darken($this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff', 7), |
||
133 | // to use like this: background-image: var(--gradient-primary-background); |
||
134 | '--gradient-primary-background' => 'linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%)', |
||
135 | |||
136 | // max contrast for WCAG compliance |
||
137 | '--color-main-text' => $colorMainText, |
||
138 | '--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33), |
||
139 | '--color-text-light' => $colorMainText, |
||
140 | '--color-text-lighter' => $this->util->lighten($colorMainText, 33), |
||
141 | |||
142 | // info/warning/success feedback colours |
||
143 | '--color-error' => '#e9322d', |
||
144 | '--color-error-rgb' => join(',', $this->util->hexToRGB('#e9322d')), |
||
145 | '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60), |
||
146 | '--color-warning' => '#eca700', |
||
147 | '--color-warning-rgb' => join(',', $this->util->hexToRGB('#eca700')), |
||
148 | '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60), |
||
149 | '--color-success' => '#46ba61', |
||
150 | '--color-success-rgb' => join(',', $this->util->hexToRGB('#46ba61')), |
||
151 | '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60), |
||
152 | |||
153 | // used for the icon loading animation |
||
154 | '--color-loading-light' => '#cccccc', |
||
155 | '--color-loading-dark' => '#444444', |
||
156 | |||
157 | '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
||
158 | '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)", |
||
159 | |||
160 | '--color-border' => $this->util->darken($colorMainBackground, 7), |
||
161 | '--color-border-dark' => $this->util->darken($colorMainBackground, 14), |
||
162 | |||
163 | '--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'", |
||
164 | '--default-font-size' => '15px', |
||
165 | |||
166 | // TODO: support "(prefers-reduced-motion)" |
||
167 | '--animation-quick' => '100ms', |
||
168 | '--animation-slow' => '300ms', |
||
169 | |||
170 | // Default variables -------------------------------------------- |
||
171 | '--border-radius' => '3px', |
||
172 | '--border-radius-large' => '10px', |
||
173 | // pill-style button, value is large so big buttons also have correct roundness |
||
174 | '--border-radius-pill' => '100px', |
||
175 | |||
176 | '--default-line-height' => '24px', |
||
177 | |||
178 | // various structure data |
||
179 | '--header-height' => '50px', |
||
180 | '--navigation-width' => '300px', |
||
181 | '--sidebar-min-width' => '300px', |
||
182 | '--sidebar-max-width' => '500px', |
||
183 | '--list-min-width' => '200px', |
||
184 | '--list-max-width' => '300px', |
||
185 | '--header-menu-item-height' => '44px', |
||
186 | '--header-menu-profile-item-height' => '66px', |
||
187 | |||
188 | // mobile. Keep in sync with core/js/js.js |
||
189 | '--breakpoint-mobile' => '1024px', |
||
190 | |||
191 | // invert filter if primary is too bright |
||
192 | // to be used for legacy reasons only. Use inline |
||
193 | // svg with proper css variable instead or material |
||
194 | // design icons. |
||
195 | // ⚠️ Using 'no' as a value to make sure we specify an |
||
196 | // invalid one with no fallback. 'unset' could here fallback to some |
||
197 | // other theme with media queries |
||
198 | '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no', |
||
199 | '--background-invert-if-dark' => 'no', |
||
200 | '--background-invert-if-bright' => 'invert(100%)', |
||
201 | |||
202 | '--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')", |
||
203 | ]; |
||
204 | |||
205 | $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor'; |
||
206 | // If primary as background has been request or if we have a custom primary colour |
||
207 | // let's not define the background image |
||
208 | if ($backgroundDeleted || $hasCustomPrimaryColour) { |
||
209 | $variables["--image-background-plain"] = 'true'; |
||
210 | } |
||
211 | |||
212 | // Register image variables only if custom-defined |
||
213 | foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) { |
||
214 | if ($this->imageManager->hasImage($image)) { |
||
215 | $imageUrl = $this->imageManager->getImageUrl($image); |
||
216 | if ($image === 'background') { |
||
217 | // If background deleted is set, ignoring variable |
||
218 | if ($backgroundDeleted) { |
||
219 | continue; |
||
220 | } |
||
221 | $variables['--image-background-size'] = 'cover'; |
||
222 | $variables['--image-main-background'] = "url('" . $imageUrl . "')"; |
||
223 | } |
||
224 | $variables["--image-$image"] = "url('" . $imageUrl . "')"; |
||
225 | } |
||
226 | } |
||
227 | |||
228 | if ($hasCustomLogoHeader) { |
||
229 | $variables["--image-logoheader-custom"] = 'true'; |
||
230 | } |
||
231 | |||
232 | return $variables; |
||
233 | } |
||
239 |