Passed
Push — master ( f116c8...be892d )
by John
15:58 queued 12s
created

DefaultTheme::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 8
dl 0
loc 23
rs 9.8666
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2022 Joas Schilling <[email protected]>
5
 *
6
 * @author Joas Schilling <[email protected]>
7
 * @author John Molakvoæ <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
namespace OCA\Theming\Themes;
26
27
use OCA\Theming\ImageManager;
28
use OCA\Theming\ITheme;
29
use OCA\Theming\Service\BackgroundService;
30
use OCA\Theming\ThemingDefaults;
31
use OCA\Theming\Util;
32
use OCP\App\IAppManager;
33
use OCP\IConfig;
34
use OCP\IL10N;
35
use OCP\IURLGenerator;
36
use OCP\IUserSession;
37
38
class DefaultTheme implements ITheme {
39
	use CommonThemeTrait;
40
41
	public Util $util;
42
	public ThemingDefaults $themingDefaults;
43
	public IUserSession $userSession;
44
	public IURLGenerator $urlGenerator;
45
	public ImageManager $imageManager;
46
	public IConfig $config;
47
	public IL10N $l;
48
	public IAppManager $appManager;
49
50
	public string $defaultPrimaryColor;
51
	public string $primaryColor;
52
53
	public function __construct(Util $util,
54
								ThemingDefaults $themingDefaults,
55
								IUserSession $userSession,
56
								IURLGenerator $urlGenerator,
57
								ImageManager $imageManager,
58
								IConfig $config,
59
								IL10N $l,
60
								IAppManager $appManager) {
61
		$this->util = $util;
62
		$this->themingDefaults = $themingDefaults;
63
		$this->userSession = $userSession;
64
		$this->urlGenerator = $urlGenerator;
65
		$this->imageManager = $imageManager;
66
		$this->config = $config;
67
		$this->l = $l;
68
		$this->appManager = $appManager;
69
70
		$this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
71
		$this->primaryColor = $this->themingDefaults->getColorPrimary();
72
73
		// Override default defaultPrimaryColor if set to improve accessibility
74
		if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) {
75
			$this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
76
		}
77
	}
78
79
	public function getId(): string {
80
		return 'default';
81
	}
82
83
	public function getType(): int {
84
		return ITheme::TYPE_THEME;
85
	}
86
87
	public function getTitle(): string {
88
		return $this->l->t('System default theme');
89
	}
90
91
	public function getEnableLabel(): string {
92
		return $this->l->t('Enable the system default');
93
	}
94
95
	public function getDescription(): string {
96
		return $this->l->t('Using the default system appearance.');
97
	}
98
99
	public function getMediaQuery(): string {
100
		return '';
101
	}
102
103
	public function getCSSVariables(): array {
104
		$colorMainText = '#222222';
105
		$colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
106
		$colorTextMaxcontrast = $this->util->lighten($colorMainText, 33);
107
		$colorMainBackground = '#ffffff';
108
		$colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
109
		$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
110
		$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
111
112
		$variables = [
113
			'--color-main-background' => $colorMainBackground,
114
			'--color-main-background-rgb' => $colorMainBackgroundRGB,
115
			'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
116
			'--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
117
			'--filter-background-blur' => 'blur(25px)',
118
119
			// to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
120
			'--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
121
122
			// used for different active/hover/focus/disabled states
123
			'--color-background-hover' => $this->util->darken($colorMainBackground, 4),
124
			'--color-background-dark' => $this->util->darken($colorMainBackground, 7),
125
			'--color-background-darker' => $this->util->darken($colorMainBackground, 14),
126
127
			'--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
128
			'--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
129
130
			// max contrast for WCAG compliance
131
			'--color-main-text' => $colorMainText,
132
			'--color-text-maxcontrast' => $colorTextMaxcontrast,
133
			'--color-text-maxcontrast-default' => $colorTextMaxcontrast,
134
			'--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
135
			'--color-text-light' => $colorMainText,
136
			'--color-text-lighter' => $this->util->lighten($colorMainText, 33),
137
138
			'--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
139
140
			// info/warning/success feedback colours
141
			'--color-error' => '#e9322d',
142
			'--color-error-rgb' => join(',', $this->util->hexToRGB('#e9322d')),
143
			'--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60),
144
			'--color-warning' => '#eca700',
145
			'--color-warning-rgb' => join(',', $this->util->hexToRGB('#eca700')),
146
			'--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60),
147
			'--color-success' => '#46ba61',
148
			'--color-success-rgb' => join(',', $this->util->hexToRGB('#46ba61')),
149
			'--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60),
150
151
			// used for the icon loading animation
152
			'--color-loading-light' => '#cccccc',
153
			'--color-loading-dark' => '#444444',
154
155
			'--color-box-shadow-rgb' => $colorBoxShadowRGB,
156
			'--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
157
158
			'--color-border' => $this->util->darken($colorMainBackground, 7),
159
			'--color-border-dark' => $this->util->darken($colorMainBackground, 14),
160
161
			'--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'",
162
			'--default-font-size' => '15px',
163
164
			// TODO: support "(prefers-reduced-motion)"
165
			'--animation-quick' => '100ms',
166
			'--animation-slow' => '300ms',
167
168
			// Default variables --------------------------------------------
169
			'--border-radius' => '3px',
170
			'--border-radius-large' => '10px',
171
			// pill-style button, value is large so big buttons also have correct roundness
172
			'--border-radius-pill' => '100px',
173
174
			'--default-clickable-area' => '44px',
175
			'--default-line-height' => '24px',
176
			'--default-grid-baseline' => '4px',
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
			'--background-invert-if-dark' => 'no',
191
			'--background-invert-if-bright' => 'invert(100%)',
192
193
			// Default last fallback values
194
			'--image-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
195
			'--color-background-plain' => $this->defaultPrimaryColor,
196
		];
197
198
		// Primary variables
199
		$variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
200
		$variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
201
		$variables = array_merge($variables, $this->generateUserBackgroundVariables());
202
203
		return $variables;
204
	}
205
206
	public function getCustomCss(): string {
207
		return '';
208
	}
209
}
210