Skip to content

Commit

Permalink
add $needsWwwPrefix and $alreadyHasWwwPrefix properties at HttpsTrait…
Browse files Browse the repository at this point in the history
… for reuse state
  • Loading branch information
samsonasik committed Apr 16, 2018
1 parent 885cde6 commit 3b24734
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/HttpsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

trait HttpsTrait
{
/** @var bool */
private $needsWwwPrefix;

/** @var bool */
private $alreadyHasWwwPrefix;

private function isSchemeHttps(string $uriScheme) : bool
{
return $uriScheme === 'https';
Expand Down Expand Up @@ -57,10 +63,10 @@ private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match,
*/
private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
{
$addWwwPrefix = $this->config['add_www_prefix'] ?? false;
$alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;
$this->needsWwwPrefix = $this->config['add_www_prefix'] ?? false;
$this->alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;

if (! $addWwwPrefix || $alreadyHasWwwPrefix) {
if (! $this->needsWwwPrefix || $this->alreadyHasWwwPrefix) {
return $httpsRequestUri;
}

Expand All @@ -73,15 +79,12 @@ private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
*/
private function withoutWwwPrefixWhenNotRequired(string $httpsRequestUri) : string
{
$addWwwPrefix = $this->config['add_www_prefix'] ?? false;
if ($addWwwPrefix) {
if ($this->needsWwwPrefix) {
return $httpsRequestUri;
}

$removeWwwPrefix = $this->config['remove_www_prefix'] ?? false;
$alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;

if (! $removeWwwPrefix || ! $alreadyHasWwwPrefix) {
if (! $removeWwwPrefix || ! $this->alreadyHasWwwPrefix) {
return $httpsRequestUri;
}

Expand Down

0 comments on commit 3b24734

Please sign in to comment.