44
55namespace ForceHttpsModule ;
66
7- use Psr \Http \Message \ResponseInterface ;
8- use Webmozart \Assert \Assert ;
9- use Mezzio \Router \RouteResult ;
10- use Laminas \Http \PhpEnvironment \Response ;
117use Laminas \Router \RouteMatch ;
8+ use Mezzio \Router \RouteResult ;
9+ use Webmozart \Assert \Assert ;
10+
11+ use function in_array ;
12+ use function strpos ;
13+ use function substr_replace ;
1214
1315trait HttpsTrait
1416{
@@ -18,7 +20,7 @@ trait HttpsTrait
1820 /** @var bool */
1921 private $ alreadyHasWwwPrefix ;
2022
21- private function isSchemeHttps (string $ uriScheme ) : bool
23+ private function isSchemeHttps (string $ uriScheme ): bool
2224 {
2325 return $ uriScheme === 'https ' ;
2426 }
@@ -28,7 +30,7 @@ private function isSchemeHttps(string $uriScheme) : bool
2830 *
2931 * @param RouteMatch|RouteResult|null $match
3032 */
31- private function isGoingToBeForcedToHttps ($ match = null ) : bool
33+ private function isGoingToBeForcedToHttps ($ match = null ): bool
3234 {
3335 if ($ match === null || ($ match instanceof RouteResult && $ match ->isFailure ())) {
3436 return $ this ->config ['allow_404 ' ] ?? false ;
@@ -39,7 +41,7 @@ private function isGoingToBeForcedToHttps($match = null) : bool
3941 }
4042
4143 Assert::notNull ($ match );
42- if (! \ in_array ($ match ->getMatchedRouteName (), $ this ->config ['force_specific_routes ' ])) {
44+ if (! in_array ($ match ->getMatchedRouteName (), $ this ->config ['force_specific_routes ' ])) {
4345 return false ;
4446 }
4547
@@ -50,9 +52,8 @@ private function isGoingToBeForcedToHttps($match = null) : bool
5052 * Check if Setup Strict-Transport-Security need to be skipped.
5153 *
5254 * @param RouteMatch|RouteResult|null $match
53- *
5455 */
55- private function isSkippedHttpStrictTransportSecurity (string $ uriScheme , $ match = null ) : bool
56+ private function isSkippedHttpStrictTransportSecurity (string $ uriScheme , $ match = null ): bool
5657 {
5758 return ! $ this ->isSchemeHttps ($ uriScheme ) ||
5859 ! $ this ->isGoingToBeForcedToHttps ($ match ) ||
@@ -65,43 +66,40 @@ private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match
6566 /**
6667 * Add www. prefix when use add_www_prefix = true
6768 */
68- private function withWwwPrefixWhenRequired (string $ httpsRequestUri ) : string
69+ private function withWwwPrefixWhenRequired (string $ httpsRequestUri ): string
6970 {
7071 $ this ->needsWwwPrefix = $ this ->config ['add_www_prefix ' ] ?? false ;
71- $ this ->alreadyHasWwwPrefix = \ strpos ($ httpsRequestUri , 'www. ' , 8 ) === 8 ;
72+ $ this ->alreadyHasWwwPrefix = strpos ($ httpsRequestUri , 'www. ' , 8 ) === 8 ;
7273
7374 if (! $ this ->needsWwwPrefix || $ this ->alreadyHasWwwPrefix ) {
7475 return $ httpsRequestUri ;
7576 }
7677
77- return \ substr_replace ($ httpsRequestUri , 'www. ' , 8 , 0 );
78+ return substr_replace ($ httpsRequestUri , 'www. ' , 8 , 0 );
7879 }
7980
8081 /**
8182 * Remove www. prefix when use remove_www_prefix = true
8283 * It only works if previous's config 'add_www_prefix' => false
8384 */
84- private function withoutWwwPrefixWhenNotRequired (string $ httpsRequestUri ) : string
85+ private function withoutWwwPrefixWhenNotRequired (string $ httpsRequestUri ): string
8586 {
8687 if ($ this ->needsWwwPrefix ) {
8788 return $ httpsRequestUri ;
8889 }
8990
90- $ removeWwwPrefix = $ this ->config ['remove_www_prefix ' ] ?? false ;
91+ $ removeWwwPrefix = $ this ->config ['remove_www_prefix ' ] ?? false ;
9192 if (! $ removeWwwPrefix || ! $ this ->alreadyHasWwwPrefix ) {
9293 return $ httpsRequestUri ;
9394 }
9495
95- return \ substr_replace ($ httpsRequestUri , '' , 8 , 4 );
96+ return substr_replace ($ httpsRequestUri , '' , 8 , 4 );
9697 }
9798
9899 /**
99100 * Get Final Request Uri with configured with or without www prefix
100- *
101- * @param string $httpsRequestUri
102- * @return string
103101 */
104- private function getFinalhttpsRequestUri (string $ httpsRequestUri ) : string
102+ private function getFinalhttpsRequestUri (string $ httpsRequestUri ): string
105103 {
106104 $ httpsRequestUri = $ this ->withWwwPrefixWhenRequired ($ httpsRequestUri );
107105 $ httpsRequestUri = $ this ->withoutWwwPrefixWhenNotRequired ($ httpsRequestUri );
0 commit comments