diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-01-26 16:26:58 +0300 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-01-26 16:26:58 +0300 |
commit | e3a12b348206adcfbfb0fbc8435ba91240ac2b0a (patch) | |
tree | a95db61139c9399dd51c10bed7faaeee42919c30 /apps/theming | |
parent | a145edd00db95135bee6f584e21301267fb5ac16 (diff) |
Fix psalm issues in theming app
After this change, we are down to only one psalm warning for this app
and related to the Application.php. This also make composer
psam:update-baseline not silently ignore new errors.
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Command/UpdateConfig.php | 1 | ||||
-rw-r--r-- | apps/theming/lib/Controller/IconController.php | 23 | ||||
-rw-r--r-- | apps/theming/lib/ImageManager.php | 10 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 8 | ||||
-rw-r--r-- | apps/theming/lib/Util.php | 7 |
5 files changed, 25 insertions, 24 deletions
diff --git a/apps/theming/lib/Command/UpdateConfig.php b/apps/theming/lib/Command/UpdateConfig.php index 1ff75b5ba70..bb226668943 100644 --- a/apps/theming/lib/Command/UpdateConfig.php +++ b/apps/theming/lib/Command/UpdateConfig.php @@ -79,6 +79,7 @@ class UpdateConfig extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $key = $input->getArgument('key'); $value = $input->getArgument('value'); + assert(is_string($value) || $value === null, 'At most one value should be provided.'); if ($key === null) { $output->writeln('Current theming config:'); diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php index b9df2e95622..4235c66a457 100644 --- a/apps/theming/lib/Controller/IconController.php +++ b/apps/theming/lib/Controller/IconController.php @@ -95,13 +95,9 @@ class IconController extends Controller { } $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon); } - if ($iconFile !== false) { - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); - $response->cacheFor(86400); - return $response; - } - - return new NotFoundResponse(); + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); + $response->cacheFor(86400); + return $response; } /** @@ -111,7 +107,8 @@ class IconController extends Controller { * @NoCSRFRequired * * @param $app string app name - * @return FileDisplayResponse|DataDisplayResponse + * @psalm-return FileDisplayResponse|DataDisplayResponse + * @return Response * @throws \Exception */ public function getFavicon(string $app = 'core'): Response { @@ -129,9 +126,7 @@ class IconController extends Controller { $icon = $this->iconBuilder->getFavicon($app); $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); } - if ($iconFile !== false) { - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); - } + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); } if ($response === null) { $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; @@ -148,7 +143,7 @@ class IconController extends Controller { * @NoCSRFRequired * * @param $app string app name - * @return FileDisplayResponse|NotFoundResponse + * @return DataDisplayResponse|FileDisplayResponse * @throws \Exception */ public function getTouchIcon(string $app = 'core'): Response { @@ -165,9 +160,7 @@ class IconController extends Controller { $icon = $this->iconBuilder->getTouchIcon($app); $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); } - if ($iconFile !== false) { - $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); - } + $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); } if ($response === null) { $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index b5ace6c968e..762461e7a1a 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -92,6 +92,7 @@ class ImageManager { case 'background': return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; } + return ''; } public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { @@ -131,6 +132,9 @@ class ImageManager { return $folder->getFile($key); } + /** + * @return array<string, array{mime: string, url: string}> + */ public function getCustomImages(): array { $images = []; foreach ($this->supportedImageKeys as $key) { @@ -192,7 +196,7 @@ class ImageManager { return $file; } - public function delete(string $key) { + public function delete(string $key): void { /* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */ try { $file = $this->appData->getFolder('images')->getFile($key); @@ -208,7 +212,7 @@ class ImageManager { } } - public function updateImage(string $key, string $tmpFile) { + public function updateImage(string $key, string $tmpFile): string { $this->delete($key); try { @@ -255,7 +259,7 @@ class ImageManager { * "favicon" images are only allowed to be SVG when imagemagick with SVG support is available. * * @param string $key The image key, e.g. "favicon" - * @return array + * @return string[] */ private function getSupportedUploadImageFormats(string $key): array { $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 3bfccda4a43..aafeb2498b6 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -157,6 +157,10 @@ class ThemingDefaults extends \OC_Defaults { return $this->config->getAppValue('theming', 'url', $this->url); } + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress InvalidReturnType + */ public function getSlogan(?string $lang = null) { return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); } @@ -404,8 +408,8 @@ class ThemingDefaults extends \OC_Defaults { * Increases the cache buster key */ private function increaseCacheBuster() { - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey + 1); + $cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0'); + $this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1)); $this->cacheFactory->createDistributed('theming-')->clear(); $this->cacheFactory->createDistributed('imagePath')->clear(); } diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 208cd42934e..05b954d5059 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -155,6 +155,7 @@ class Util { /** * @param string $color rgb color value * @return int[] + * @psalm-return array{0: int, 1: int, 2: int} */ public function hexToRGB($color) { $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); @@ -162,7 +163,7 @@ class Util { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } if (strlen($hex) !== 6) { - return 0; + return [0, 0, 0]; } return [ hexdec(substr($hex, 0, 2)), @@ -205,9 +206,7 @@ class Util { $logoFile = null; try { $folder = $this->appData->getFolder('images'); - if ($folder !== null) { - return $folder->getFile('logo'); - } + return $folder->getFile('logo'); } catch (NotFoundException $e) { } } |