Skip to content

Commit

Permalink
use coalesesce operator when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 11, 2018
1 parent a121b8a commit 404b083
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/HttpsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match,
*/
private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
{
if (
! isset($this->config['add_www_prefix']) ||
! $this->config['add_www_prefix'] ||
(
$this->config['add_www_prefix'] === true &&
\substr($httpsRequestUri, 8, 4) === 'www.'
)
) {
$addWwwPrefix = $this->config['add_www_prefix'] ?? false;
$alreadyHasWwwPrefix = \substr($httpsRequestUri, 8, 4) === 'www.';

if (! $addWwwPrefix || $alreadyHasWwwPrefix) {
return $httpsRequestUri;
}

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

if (
! isset($this->config['remove_www_prefix']) ||
! $this->config['remove_www_prefix'] ||
(
$this->config['remove_www_prefix'] === true &&
\substr($httpsRequestUri, 8, 4) !== 'www.'
)
) {
$removeWwwPrefix = $this->config['remove_www_prefix'] ?? false;
$alreadyHasWwwPrefix = \substr($httpsRequestUri, 8, 4) === 'www.';

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

Expand Down

0 comments on commit 404b083

Please sign in to comment.