Skip to content

Commit 3b24734

Browse files
committed
add $needsWwwPrefix and $alreadyHasWwwPrefix properties at HttpsTrait for reuse state
1 parent 885cde6 commit 3b24734

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/HttpsTrait.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
trait HttpsTrait
1313
{
14+
/** @var bool */
15+
private $needsWwwPrefix;
16+
17+
/** @var bool */
18+
private $alreadyHasWwwPrefix;
19+
1420
private function isSchemeHttps(string $uriScheme) : bool
1521
{
1622
return $uriScheme === 'https';
@@ -57,10 +63,10 @@ private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match,
5763
*/
5864
private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
5965
{
60-
$addWwwPrefix = $this->config['add_www_prefix'] ?? false;
61-
$alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;
66+
$this->needsWwwPrefix = $this->config['add_www_prefix'] ?? false;
67+
$this->alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;
6268

63-
if (! $addWwwPrefix || $alreadyHasWwwPrefix) {
69+
if (! $this->needsWwwPrefix || $this->alreadyHasWwwPrefix) {
6470
return $httpsRequestUri;
6571
}
6672

@@ -73,15 +79,12 @@ private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
7379
*/
7480
private function withoutWwwPrefixWhenNotRequired(string $httpsRequestUri) : string
7581
{
76-
$addWwwPrefix = $this->config['add_www_prefix'] ?? false;
77-
if ($addWwwPrefix) {
82+
if ($this->needsWwwPrefix) {
7883
return $httpsRequestUri;
7984
}
8085

8186
$removeWwwPrefix = $this->config['remove_www_prefix'] ?? false;
82-
$alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;
83-
84-
if (! $removeWwwPrefix || ! $alreadyHasWwwPrefix) {
87+
if (! $removeWwwPrefix || ! $this->alreadyHasWwwPrefix) {
8588
return $httpsRequestUri;
8689
}
8790

0 commit comments

Comments
 (0)