Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Plugin/Framework/App/Response/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +40,7 @@ public function beforeSetNoCacheHeaders(ResponseHttp $subject): void
}

$cacheControlHeader = $subject->getHeader('Cache-Control');
if (!$cacheControlHeader) {
if (!$cacheControlHeader instanceof HeaderInterface) {
return;
}

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

Expand Down Expand Up @@ -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 : '';
}
}
6 changes: 4 additions & 2 deletions ViewModel/SpeculationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ViewModel/ViewTransitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Loading