diff options
author | Faraz Samapoor <f.samapoor@gmail.com> | 2023-06-02 15:43:47 +0330 |
---|---|---|
committer | Faraz Samapoor <f.samapoor@gmail.com> | 2023-06-02 15:43:47 +0330 |
commit | 437631a33435db6902d09cf0fd58c35ac9e4f1f9 (patch) | |
tree | 4a435be8ba13ca9c58f7d966ba8cbf4d01daba6e | |
parent | 09c5f997c6d185d8b23b37a996e7a1130a426d75 (diff) | |
download | nextcloud-server-437631a33435db6902d09cf0fd58c35ac9e4f1f9.tar.gz nextcloud-server-437631a33435db6902d09cf0fd58c35ac9e4f1f9.zip |
Refactors "strpos" calls in /apps/theming to improve code readability.
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
-rw-r--r-- | apps/theming/lib/Command/UpdateConfig.php | 2 | ||||
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 4 | ||||
-rw-r--r-- | apps/theming/lib/ImageManager.php | 8 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 2 |
4 files changed, 8 insertions, 8 deletions
diff --git a/apps/theming/lib/Command/UpdateConfig.php b/apps/theming/lib/Command/UpdateConfig.php index 58dfcff8a8e..aebb6b9be15 100644 --- a/apps/theming/lib/Command/UpdateConfig.php +++ b/apps/theming/lib/Command/UpdateConfig.php @@ -112,7 +112,7 @@ class UpdateConfig extends Command { } if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { - if (strpos($value, '/') !== 0) { + if (!str_starts_with($value, '/')) { $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); return 1; } diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index a323bac180b..c247f2c9d56 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -182,7 +182,7 @@ class ThemingController extends Controller { * Check that a string is a valid http/https url */ private function isValidUrl(string $url): bool { - return ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) && + return ((str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) && filter_var($url, FILTER_VALIDATE_URL) !== false); } @@ -400,7 +400,7 @@ class ThemingController extends Controller { $info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); $name = $info['name'] . ' - ' . $this->themingDefaults->getName(); $shortName = $info['name']; - if (strpos($this->request->getRequestUri(), '/index.php/') !== false) { + if (str_contains($this->request->getRequestUri(), '/index.php/')) { $startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/'; } else { $startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index d088699fd3c..87123a6f7c9 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -266,7 +266,7 @@ class ImageManager { $newTmpFile = $this->tempManager->getTemporaryFile(); imageinterlace($outputImage, 1); // Keep jpeg images encoded as jpeg - if (strpos($detectedMimeType, 'image/jpeg') !== false) { + if (str_contains($detectedMimeType, 'image/jpeg')) { if (!imagejpeg($outputImage, $newTmpFile, 90)) { throw new \Exception('Could not recompress background image as JPEG'); } @@ -300,16 +300,16 @@ class ImageManager { */ private function shouldOptimizeBackgroundImage(string $mimeType, int $contentSize): bool { // Do not touch SVGs - if (strpos($mimeType, 'image/svg') !== false) { + if (str_contains($mimeType, 'image/svg')) { return false; } // GIF does not benefit from converting - if (strpos($mimeType, 'image/gif') !== false) { + if (str_contains($mimeType, 'image/gif')) { return false; } // WebP also does not benefit from converting // We could possibly try to convert to progressive image, but normally webP images are quite small - if (strpos($mimeType, 'image/webp') !== false) { + if (str_contains($mimeType, 'image/webp')) { return false; } // As a rule of thumb background images should be max. 150-300 KiB, small images do not benefit from converting diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 6cb204d1b1b..454e0505543 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -404,7 +404,7 @@ class ThemingDefaults extends \OC_Defaults { } $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]); } - if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { + if (str_starts_with($image, 'filetypes/') && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); } |