From f2ca29d3f0ee759f859a8ec73969c34b3abbbdb1 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 5 Apr 2024 15:46:20 -0400 Subject: [PATCH] refactor: PHPstan code cleanup --- src/Twigpack.php | 7 ++++--- src/helpers/Manifest.php | 4 ++-- src/services/Manifest.php | 6 +++--- src/variables/ManifestVariable.php | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Twigpack.php b/src/Twigpack.php index b6449af..6027f43 100644 --- a/src/Twigpack.php +++ b/src/Twigpack.php @@ -43,14 +43,14 @@ class Twigpack extends Plugin // ========================================================================= /** - * @var Twigpack + * @var ?Twigpack */ - public static Twigpack $plugin; + public static ?Twigpack $plugin = null; /** * @var string */ - public static string $templateName; + public static string $templateName = ''; // Static Methods // ========================================================================= @@ -121,6 +121,7 @@ public function clearAllCaches(): void public function injectErrorEntry(): void { if (Craft::$app->getResponse()->isServerError || Craft::$app->getResponse()->isClientError) { + /** @var ?Settings $settings */ $settings = self::$plugin->getSettings(); if ($settings && !empty($settings->errorEntry) && $settings->useDevServer) { try { diff --git a/src/helpers/Manifest.php b/src/helpers/Manifest.php index 5938881..872cc5b 100644 --- a/src/helpers/Manifest.php +++ b/src/helpers/Manifest.php @@ -473,7 +473,7 @@ public static function getFileFromManifest(array $config, string $fileName, stri } try { if (is_file($localPath)) { - return self::getFile($localPath) ?? ''; + return self::getFile($localPath); } } catch (Exception $e) { Craft::error($e->getMessage(), __METHOD__); @@ -653,7 +653,7 @@ function() use ($path, $callback) { */ protected static function getHttpResponseCode($url, $context): bool|string { - $headers = @get_headers($url, 0, $context); + $headers = @get_headers($url, false, $context); if (empty($headers)) { return '404'; } diff --git a/src/services/Manifest.php b/src/services/Manifest.php index 2005c3b..5197e89 100644 --- a/src/services/Manifest.php +++ b/src/services/Manifest.php @@ -124,7 +124,7 @@ public function getSafariNomoduleFix(array $attributes = []): string * * @param string $moduleName * @param string $type - * @param null $config + * @param ?array $config * * @return null|string * @throws NotFoundHttpException @@ -142,7 +142,7 @@ public function getModule(string $moduleName, string $type = 'modern', $config = * * @param string $moduleName * @param string $type - * @param null $config + * @param ?array $config * * @return null|string * @throws NotFoundHttpException @@ -172,7 +172,7 @@ public function getFile(string $path): string * * @param string $fileName * @param string $type - * @param null $config + * @param ?array $config * * @return string */ diff --git a/src/variables/ManifestVariable.php b/src/variables/ManifestVariable.php index 718ddd5..2afd23b 100644 --- a/src/variables/ManifestVariable.php +++ b/src/variables/ManifestVariable.php @@ -36,7 +36,7 @@ class ManifestVariable public static function includeCssRelPreloadPolyfill(): Markup { return Template::raw( - Twigpack::$plugin->manifest->getCssRelPreloadPolyfill() ?? '' + Twigpack::$plugin->manifest->getCssRelPreloadPolyfill() ); } @@ -51,7 +51,7 @@ public static function includeCssRelPreloadPolyfill(): Markup public function includeCssModule(string $moduleName, bool $async = false, array $attributes = []): Markup { return Template::raw( - Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, null, $attributes) ?? '' + Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, null, $attributes) ); } @@ -66,7 +66,7 @@ public function includeCssModule(string $moduleName, bool $async = false, array public function includeInlineCssTags(string $path, array $attributes = []): Markup { return Template::raw( - Twigpack::$plugin->manifest->getCssInlineTags($path, $attributes) ?? '' + Twigpack::$plugin->manifest->getCssInlineTags($path, $attributes) ); } @@ -83,7 +83,7 @@ public function includeInlineCssTags(string $path, array $attributes = []): Mark public function includeCriticalCssTags(?string $name = null, array $attributes = []): Markup { return Template::raw( - Twigpack::$plugin->manifest->getCriticalCssTags($name, null, $attributes) ?? '' + Twigpack::$plugin->manifest->getCriticalCssTags($name, null, $attributes) ); } @@ -98,7 +98,7 @@ public function includeCriticalCssTags(?string $name = null, array $attributes = public function includeJsModule(string $moduleName, bool $async = false, array $attributes = []): Markup { return Template::raw( - Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, null, $attributes) ?? '' + Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, null, $attributes) ); } @@ -115,7 +115,7 @@ public function includeJsModule(string $moduleName, bool $async = false, array $ public function getModuleUri(string $moduleName, string $type = 'modern', $config = null): Markup { return Template::raw( - Twigpack::$plugin->manifest->getModule($moduleName, $type, $config) ?? '' + Twigpack::$plugin->manifest->getModule($moduleName, $type, $config) ); } @@ -132,7 +132,7 @@ public function getModuleUri(string $moduleName, string $type = 'modern', $confi public function getModuleHash(string $moduleName, string $type = 'modern', $config = null): Markup { return Template::raw( - Twigpack::$plugin->manifest->getModuleHash($moduleName, $type, $config) ?? '' + Twigpack::$plugin->manifest->getModuleHash($moduleName, $type, $config) ); } @@ -146,7 +146,7 @@ public function getModuleHash(string $moduleName, string $type = 'modern', $conf public function includeSafariNomoduleFix(array $attributes = []): Markup { return Template::raw( - Twigpack::$plugin->manifest->getSafariNomoduleFix($attributes) ?? '' + Twigpack::$plugin->manifest->getSafariNomoduleFix($attributes) ); } @@ -160,7 +160,7 @@ public function includeSafariNomoduleFix(array $attributes = []): Markup public function includeFile(string $path): Markup { return Template::raw( - Twigpack::$plugin->manifest->getFile($path) ?? '' + Twigpack::$plugin->manifest->getFile($path) ); } @@ -176,7 +176,7 @@ public function includeFile(string $path): Markup public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): Markup { return Template::raw( - Twigpack::$plugin->manifest->getFileFromManifest($fileName, $type, $config) ?? '' + Twigpack::$plugin->manifest->getFileFromManifest($fileName, $type, $config) ); } }