Skip to content

Commit

Permalink
Update halo rendering logic and conditions
Browse files Browse the repository at this point in the history
Refactored method "isDisableHalo" to "isEnableHalo" in HaloRenderer class. The change in function name is also accompanied by an update in its logic – specifically related to the condition checks and setcookie values. Furthermore, adjusted the call in the 'render' function to reflect this modification. This improves the understanding and readability of the code.
  • Loading branch information
koriym committed Apr 20, 2024
1 parent c0a69c4 commit d44c7aa
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Halo/HaloRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
*/
public function render(ResourceObject $ro)
{
if ($this->isDisableHalo()) {
if (! $this->isEableHalo()) {
return $this->renderer->render($ro);
}

Expand All @@ -75,19 +75,21 @@ public function render(ResourceObject $ro)
return $haloView;
}

private function isDisableHalo(): bool
private function isEableHalo(): bool
{
$disableHalo = (isset($_GET[self::HALO_KEY]) && $_GET[self::HALO_KEY] === '0') || isset($_COOKIE[self::HALO_COOKIE_KEY]);
if (! empty($_GET[self::HALO_KEY]) && $_GET[self::HALO_KEY] === '1') {
$disableHalo = false;
setcookie(self::HALO_COOKIE_KEY, '', time() - 3600);
if (! isset($_GET[self::HALO_KEY])) {
return isset($_COOKIE[self::HALO_COOKIE_KEY]);
}

if ($disableHalo) {
setcookie(self::HALO_COOKIE_KEY, '0');
if ($_GET[self::HALO_KEY] === '1') {
setcookie(self::HALO_COOKIE_KEY, '1');

return true;
}

return $disableHalo;
setcookie(self::HALO_COOKIE_KEY, '', time() - 3600); // delete cookies

return false;
}

private function addJsDevTools(string $body): string
Expand Down

0 comments on commit d44c7aa

Please sign in to comment.