7070class ThemingController extends Controller {
7171 public const VALID_UPLOAD_KEYS = ['header ' , 'logo ' , 'logoheader ' , 'background ' , 'favicon ' ];
7272
73- private ThemingDefaults $ themingDefaults ;
7473 private IL10N $ l10n ;
75- private IConfig $ config ;
76- private ITempManager $ tempManager ;
77- private IAppData $ appData ;
78- private IURLGenerator $ urlGenerator ;
79- private IAppManager $ appManager ;
80- private ImageManager $ imageManager ;
81- private ThemesService $ themesService ;
8274
8375 public function __construct (
8476 $ appName ,
8577 IRequest $ request ,
86- IConfig $ config ,
87- ThemingDefaults $ themingDefaults ,
78+ private IConfig $ config ,
79+ private ThemingDefaults $ themingDefaults ,
8880 IL10N $ l ,
89- ITempManager $ tempManager ,
90- IAppData $ appData ,
91- IURLGenerator $ urlGenerator ,
92- IAppManager $ appManager ,
93- ImageManager $ imageManager ,
94- ThemesService $ themesService
81+ private ITempManager $ tempManager ,
82+ private IAppData $ appData ,
83+ private IURLGenerator $ urlGenerator ,
84+ private IAppManager $ appManager ,
85+ private ImageManager $ imageManager ,
86+ private ThemesService $ themesService,
9587 ) {
9688 parent ::__construct ($ appName , $ request );
9789
98- $ this ->themingDefaults = $ themingDefaults ;
9990 $ this ->l10n = $ l ;
100- $ this ->config = $ config ;
101- $ this ->tempManager = $ tempManager ;
102- $ this ->appData = $ appData ;
103- $ this ->urlGenerator = $ urlGenerator ;
104- $ this ->appManager = $ appManager ;
105- $ this ->imageManager = $ imageManager ;
106- $ this ->themesService = $ themesService ;
10791 }
10892
10993 /**
11094 * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin)
11195 * @param string $setting
11296 * @param string $value
113- * @return DataResponse
11497 * @throws NotPermittedException
11598 */
116- public function updateStylesheet ($ setting , $ value ) {
99+ public function updateStylesheet ($ setting , $ value ): DataResponse {
117100 $ value = trim ($ value );
118101 $ error = null ;
119102 switch ($ setting ) {
@@ -188,7 +171,7 @@ public function updateStylesheet($setting, $value) {
188171 * @return DataResponse
189172 * @throws NotPermittedException
190173 */
191- public function updateAppMenu ($ setting , $ value ) {
174+ public function updateAppMenu ($ setting , $ value ): DataResponse {
192175 $ error = null ;
193176 switch ($ setting ) {
194177 case 'defaultApps ' :
@@ -226,8 +209,15 @@ public function updateAppMenu($setting, $value) {
226209 * Check that a string is a valid http/https url
227210 */
228211 private function isValidUrl (string $ url ): bool {
229- return ((str_starts_with ($ url , 'http:// ' ) || str_starts_with ($ url , 'https:// ' )) &&
230- filter_var ($ url , FILTER_VALIDATE_URL ) !== false );
212+ if (!str_starts_with ($ url , 'http:// ' ) && !str_starts_with ($ url , 'https:// ' )) {
213+ return false ;
214+ }
215+
216+ if (filter_var ($ url , FILTER_VALIDATE_URL ) === false ) {
217+ return false ;
218+ }
219+
220+ return true ;
231221 }
232222
233223 /**
@@ -369,7 +359,7 @@ public function undoAll(): DataResponse {
369359 * 200: Image returned
370360 * 404: Image not found
371361 */
372- public function getImage (string $ key , bool $ useSvg = true ) {
362+ public function getImage (string $ key , bool $ useSvg = true ): NotFoundResponse | FileDisplayResponse {
373363 try {
374364 $ file = $ this ->imageManager ->getImage ($ key , $ useSvg );
375365 } catch (NotFoundException $ e ) {
@@ -407,7 +397,7 @@ public function getImage(string $key, bool $useSvg = true) {
407397 * 200: Stylesheet returned
408398 * 404: Theme not found
409399 */
410- public function getThemeStylesheet (string $ themeId , bool $ plain = false , bool $ withCustomCss = false ) {
400+ public function getThemeStylesheet (string $ themeId , bool $ plain = false , bool $ withCustomCss = false ): NotFoundResponse | DataDisplayResponse {
411401 $ themes = $ this ->themesService ->getThemes ();
412402 if (!in_array ($ themeId , array_keys ($ themes ))) {
413403 return new NotFoundResponse ();
@@ -430,7 +420,6 @@ public function getThemeStylesheet(string $themeId, bool $plain = false, bool $w
430420 $ compiler = new Compiler ();
431421 $ compiledCss = $ compiler ->compileString ("[data-theme- $ themeId] { $ variables $ customCss } " );
432422 $ css = $ compiledCss ->getCss ();
433- ;
434423 }
435424
436425 try {
0 commit comments