]> source.dussan.org Git - nextcloud-server.git/commitdiff
Modernize accessibility app
authorCarl Schwan <carl@carlschwan.eu>
Tue, 15 Mar 2022 16:31:37 +0000 (17:31 +0100)
committerCarl Schwan <carl@carlschwan.eu>
Fri, 18 Mar 2022 11:39:42 +0000 (12:39 +0100)
- Use php 7.4 typed properties
- More typed methods (and replace existing php doc in some cases)

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
apps/accessibility/lib/AccessibilityProvider.php
apps/accessibility/lib/Controller/AccessibilityController.php
apps/accessibility/lib/Controller/ConfigController.php
apps/accessibility/lib/Migration/RepairUserConfig.php
apps/accessibility/lib/Service/JSDataService.php

index 417cf7d039cc2460f1315c746da1a3d9f1860b07..80ba4753dfa0f20c99f1da7355da4842616ae819 100644 (file)
@@ -33,22 +33,10 @@ use OCP\IURLGenerator;
 
 class AccessibilityProvider {
 
-       /** @var string */
-       protected $appName;
+       protected string $appName;
+       private IURLGenerator $urlGenerator;
+       private IL10N $l;
 
-       /** @var IURLGenerator */
-       private $urlGenerator;
-
-       /** @var IL10N */
-       private $l;
-
-       /**
-        * Account constructor.
-        *
-        * @param string $appName
-        * @param IURLGenerator $urlGenerator
-        * @param IL10N $l
-        */
        public function __construct(string $appName,
                                                                IURLGenerator $urlGenerator,
                                                                IL10N $l) {
@@ -57,7 +45,10 @@ class AccessibilityProvider {
                $this->l = $l;
        }
 
-       public function getThemes() {
+       /**
+        * @psalm-return array<array-key, array{id: string, img: string, title: string, enableLabel: string, text: string}>
+        */
+       public function getThemes(): array {
                return [
                        [
                                'id' => 'dark',
@@ -69,7 +60,10 @@ class AccessibilityProvider {
                ];
        }
 
-       public function getHighContrast() {
+       /**
+        * @psalm-return array{id: string, img: string, title: string, enableLabel: string, text: string}
+        */
+       public function getHighContrast(): array {
                return [
                        'id' => 'highcontrast',
                        'img' => $this->urlGenerator->imagePath($this->appName, 'mode-highcontrast.jpg'),
@@ -79,7 +73,10 @@ class AccessibilityProvider {
                ];
        }
 
-       public function getFonts() {
+       /**
+        * @psalm-return array<array-key, array{id: string, img: string, title: string, enableLabel: string, text: string}>
+        */
+       public function getFonts(): array {
                return [
                        [
                                'id' => 'fontdyslexic',
index 7a5a82085dc6a6470fe4ab35e14e1d57806b18d9..d175e3167cc1e02128719a1f96808157e6f9d8fc 100644 (file)
@@ -48,36 +48,19 @@ use ScssPhp\ScssPhp\OutputStyle;
 
 class AccessibilityController extends Controller {
 
-       /** @var string */
-       protected $appName;
-
-       /** @var string */
-       protected $serverRoot;
-
-       /** @var IConfig */
-       private $config;
-
-       /** @var LoggerInterface */
-       private $logger;
-
-       /** @var ITimeFactory */
-       protected $timeFactory;
-
-       /** @var IUserSession */
-       private $userSession;
-
-       /** @var IconsCacher */
-       protected $iconsCacher;
-
-       /** @var \OC_Defaults */
-       private $defaults;
-
-       /** @var null|string */
-       private $injectedVariables;
-
-       /** @var string */
-       private $appRoot;
+       protected string $serverRoot;
+       private IConfig $config;
+       private LoggerInterface $logger;
+       protected ITimeFactory $timeFactory;
+       private IUserSession $userSession;
+       protected IconsCacher $iconsCacher;
+       private \OC_Defaults $defaults;
+       private ?string $injectedVariables = null;
+       private string $appRoot;
 
+       /**
+        * @param string $appName
+        */
        public function __construct(string $appName,
                                                                IRequest $request,
                                                                IConfig $config,
@@ -104,8 +87,6 @@ class AccessibilityController extends Controller {
         * @PublicPage
         * @NoCSRFRequired
         * @NoSameSiteCookieRequired
-        *
-        * @return DataDisplayResponse
         */
        public function getCss(): DataDisplayResponse {
                $css = '';
@@ -186,8 +167,6 @@ class AccessibilityController extends Controller {
 
        /**
         * Return an array with the user theme & font settings
-        *
-        * @return array
         */
        private function getUserValues(): array {
                $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false);
@@ -210,10 +189,6 @@ class AccessibilityController extends Controller {
 
        /**
         * Add the correct uri prefix to make uri valid again
-        *
-        * @param string $css
-        * @param string $webDir
-        * @return string
         */
        private function rebaseUrls(string $css, string $webDir): string {
                $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x';
@@ -226,9 +201,8 @@ class AccessibilityController extends Controller {
         * Remove all matches from the $rule regex
         *
         * @param string $css string to parse
-        * @return string
         */
-       private function invertSvgIconsColor(string $css) {
+       private function invertSvgIconsColor(string $css): string {
                return str_replace(
                        ['color=000&', 'color=fff&', 'color=***&'],
                        ['color=***&', 'color=000&', 'color=fff&'],
index 592c2268eb8ae44c59f120fa67c180b71a908956..3cc66ed4cb47db8241922323f19da3b0041cbe1a 100644 (file)
@@ -41,32 +41,13 @@ use OCP\PreConditionNotMetException;
 
 class ConfigController extends OCSController {
 
-       /** @var string */
-       protected $appName;
-
-       /** @var string */
-       protected $userId;
-
-       /** @var string */
-       protected $serverRoot;
-
-       /** @var IConfig */
-       private $config;
-
-       /** @var IUserSession */
-       private $userSession;
-
-       /** @var AccessibilityProvider */
-       private $accessibilityProvider;
+       protected string $userId;
+       private IConfig $config;
+       private IUserSession $userSession;
+       private AccessibilityProvider $accessibilityProvider;
 
        /**
         * Config constructor.
-        *
-        * @param string $appName
-        * @param IRequest $request
-        * @param IConfig $config
-        * @param IUserSession $userSession
-        * @param AccessibilityProvider $accessibilityProvider
         */
        public function __construct(string $appName,
                                                                IRequest $request,
@@ -74,7 +55,6 @@ class ConfigController extends OCSController {
                                                                IUserSession $userSession,
                                                                AccessibilityProvider $accessibilityProvider) {
                parent::__construct($appName, $request);
-               $this->appName = $appName;
                $this->config = $config;
                $this->userSession = $userSession;
                $this->accessibilityProvider = $accessibilityProvider;
@@ -102,7 +82,8 @@ class ConfigController extends OCSController {
         *
         * Set theme or font config
         *
-        * @param string $key theme or font
+        * @param string $key the theme or font
+        * @param string|false $value the value
         * @return DataResponse
         * @throws OCSBadRequestException|PreConditionNotMetException
         */
index 45a2ca3c0959461431b930145946bbe927d5c2e4..c15280ae26dca262ce7914974b29701c142baf44 100644 (file)
@@ -35,17 +35,11 @@ use OCP\Migration\IRepairStep;
 
 class RepairUserConfig implements IRepairStep {
 
-       /** @var IUserManager */
-       protected $userManager;
-
-       /** @var IConfig */
-       protected $config;
+       protected IUserManager $userManager;
+       protected IConfig $config;
 
        /**
         * MigrateUserConfig constructor.
-        *
-        * @param IConfig $config
-        * @param IUserManager $userManager
         */
        public function __construct(IConfig $config,
                                                                IUserManager $userManager) {
index d705957a49c0353ea19e9646ff0de77048753ee4..e3a562de394d7080f6816970370d357c229d3a4a 100644 (file)
@@ -31,10 +31,8 @@ use OCP\IConfig;
 use OCP\IUserSession;
 
 class JSDataService extends InitialStateProvider {
-       /** @var IUserSession */
-       private $userSession;
-       /** @var IConfig */
-       private $config;
+       private IUserSession $userSession;
+       private IConfig $config;
 
        public function __construct(
                IUserSession $userSession,