Skip to content

Commit 54433bf

Browse files
committed
Optimize the consent was given methods
Only get the stored consent when consent is enabled. The other methods need no adjusting as the short-circuiting by the first condition prevents those expressions from being executed. Consider: `(true || $this->expensiveMethodCall())` The expensiveMethodCall is never called as the first condition already decided the rest of the condition. https://www.php.net/manual/en/language.operators.logical.php
1 parent 2be3625 commit 54433bf

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

library/EngineBlock/Corto/Model/Consent.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ public function __construct(
8484

8585
public function explicitConsentWasGivenFor(ServiceProvider $serviceProvider): bool
8686
{
87+
if (!$this->_consentEnabled) {
88+
return true;
89+
}
8790
$consent = $this->_hasStoredConsent($serviceProvider, ConsentType::TYPE_EXPLICIT);
88-
return !$this->_consentEnabled || $consent->given();
91+
return $consent->given();
8992
}
9093

9194
/**
@@ -103,8 +106,11 @@ public function upgradeAttributeHashFor(ServiceProvider $serviceProvider, string
103106

104107
public function implicitConsentWasGivenFor(ServiceProvider $serviceProvider): bool
105108
{
109+
if (!$this->_consentEnabled) {
110+
return true;
111+
}
106112
$consent = $this->_hasStoredConsent($serviceProvider, ConsentType::TYPE_IMPLICIT);
107-
return !$this->_consentEnabled || $consent->given();
113+
return $consent->given();
108114
}
109115

110116
public function giveExplicitConsentFor(ServiceProvider $serviceProvider): bool

0 commit comments

Comments
 (0)