Skip to content

Commit

Permalink
refactor: PHPstan code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 5, 2024
1 parent 1aeba4c commit f2ca29d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/Twigpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =========================================================================
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down Expand Up @@ -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';
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -172,7 +172,7 @@ public function getFile(string $path): string
*
* @param string $fileName
* @param string $type
* @param null $config
* @param ?array $config
*
* @return string
*/
Expand Down
20 changes: 10 additions & 10 deletions src/variables/ManifestVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ManifestVariable
public static function includeCssRelPreloadPolyfill(): Markup
{
return Template::raw(
Twigpack::$plugin->manifest->getCssRelPreloadPolyfill() ?? ''
Twigpack::$plugin->manifest->getCssRelPreloadPolyfill()
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}
}

0 comments on commit f2ca29d

Please sign in to comment.