diff --git a/Plugin/Framework/App/Response/Http.php b/Plugin/Framework/App/Response/Http.php index 10acd93..a557945 100644 --- a/Plugin/Framework/App/Response/Http.php +++ b/Plugin/Framework/App/Response/Http.php @@ -2,6 +2,8 @@ namespace MageOS\ThemeOptimization\Plugin\Framework\App\Response; +use Laminas\Http\Header\CacheControl; +use Laminas\Http\Header\HeaderInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Framework\App\Response\Http as ResponseHttp; @@ -38,7 +40,7 @@ public function beforeSetNoCacheHeaders(ResponseHttp $subject): void } $cacheControlHeader = $subject->getHeader('Cache-Control'); - if (!$cacheControlHeader) { + if (!$cacheControlHeader instanceof HeaderInterface) { return; } @@ -63,13 +65,11 @@ public function afterSetNoCacheHeaders(ResponseHttp $subject, mixed $result): mi return $result; } - $cacheControlHeader = $subject->getHeader('Cache-Control'); - if (!$cacheControlHeader) { - return $result; - } - if ($this->isRequestCacheable === true) { - $cacheControlHeader->removeDirective('no-store'); + $cacheControlHeader = $subject->getHeader('Cache-Control'); + if ($cacheControlHeader instanceof CacheControl) { + $cacheControlHeader->removeDirective('no-store'); + } } $this->isRequestCacheable = false; @@ -151,10 +151,12 @@ protected function isEnabled(): bool */ protected function getConfig(string $configPath, int|string|null $store = null): string { - return (string)$this->scopeConfig->getValue( + $value = $this->scopeConfig->getValue( $configPath, ScopeInterface::SCOPE_STORE, $store ); + + return is_scalar($value) ? (string) $value : ''; } } diff --git a/ViewModel/SpeculationRules.php b/ViewModel/SpeculationRules.php index ecaec46..57ab1d3 100644 --- a/ViewModel/SpeculationRules.php +++ b/ViewModel/SpeculationRules.php @@ -127,7 +127,9 @@ public function getSpeculationRules(): array */ public function getSpeculationRulesJson(): string { - return $this->serializer->serialize($this->getSpeculationRules()); + $json = $this->serializer->serialize($this->getSpeculationRules()); + + return is_string($json) ? $json : ''; } /** @@ -173,7 +175,7 @@ protected function getConfigValue(string $key): ?string ScopeInterface::SCOPE_STORE ); - return $value === null ? null : (string)$value; + return is_scalar($value) ? (string)$value : null; } /** diff --git a/ViewModel/ViewTransitions.php b/ViewModel/ViewTransitions.php index ae3a3c4..8bc55d1 100644 --- a/ViewModel/ViewTransitions.php +++ b/ViewModel/ViewTransitions.php @@ -26,7 +26,7 @@ protected function getConfigValue(string $key): ?string ScopeInterface::SCOPE_STORE ); - return $value === null ? null : (string)$value; + return is_scalar($value) ? (string)$value : null; } /**