Skip to content

Commit d7284c6

Browse files
committed
cs
1 parent 2d9163d commit d7284c6

File tree

9 files changed

+54
-50
lines changed

9 files changed

+54
-50
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CONTRIBUTING
33
To contribute, you can send pull requests with :
44

55
- Typo fix.
6-
- Use [Zend Coding Standard](https://github.com/laminas/laminas-coding-standard).
6+
- Use [Laminas Coding Standard](https://github.com/laminas/laminas-coding-standard).
77
- patch(es) need new/updated test(s).
88
- new feature(s) need test(s).
99

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"php-coveralls/php-coveralls": "^2.1",
3838
"phpstan/phpstan": "^0.10.8",
3939
"phpstan/phpstan-webmozart-assert": "^0.10.0",
40-
"laminas/laminas-coding-standard": "^1.0",
40+
"laminas/laminas-coding-standard": "^2.0",
4141
"mezzio/mezzio": "^3.0",
4242
"laminas/laminas-mvc": "^3.0"
4343
},
@@ -63,5 +63,7 @@
6363
"scripts": {
6464
"cs-check": "phpcs",
6565
"cs-fix": "phpcbf"
66-
}
66+
},
67+
"minimum-stability": "alpha",
68+
"prefer-stable": true
6769
}

phpcs.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Zend Framework Coding Standard">
3-
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
2+
<ruleset name="Laminas Coding Standard">
3+
<rule ref="./vendor/laminas/laminas-coding-standard/src/LaminasCodingStandard/ruleset.xml"/>
44

55
<!-- Paths to check -->
66
<file>src</file>

src/HttpsTrait.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace ForceHttpsModule;
66

7-
use Psr\Http\Message\ResponseInterface;
8-
use Webmozart\Assert\Assert;
9-
use Mezzio\Router\RouteResult;
10-
use Laminas\Http\PhpEnvironment\Response;
117
use 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

1315
trait 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);

src/Listener/ForceHttps.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@
88
use Laminas\Console\Console;
99
use Laminas\EventManager\AbstractListenerAggregate;
1010
use Laminas\EventManager\EventManagerInterface;
11+
use Laminas\Http\PhpEnvironment\Request;
1112
use Laminas\Http\PhpEnvironment\Response;
1213
use Laminas\Mvc\MvcEvent;
1314
use Laminas\Router\RouteMatch;
1415

16+
use function sprintf;
17+
1518
class ForceHttps extends AbstractListenerAggregate
1619
{
1720
use HttpsTrait;
1821

19-
/**
20-
* @var array
21-
*/
22+
/** @var array */
2223
private $config;
2324

2425
public function __construct(array $config)
2526
{
2627
$this->config = $config;
2728
}
2829

29-
public function attach(EventManagerInterface $events, $priority = 1) : void
30+
/**
31+
* @param int $priority
32+
*/
33+
public function attach(EventManagerInterface $events, $priority = 1): void
3034
{
3135
if (Console::isConsole() || ! $this->config['enable']) {
3236
return;
@@ -37,10 +41,10 @@ public function attach(EventManagerInterface $events, $priority = 1) : void
3741
}
3842

3943
private function setHttpStrictTransportSecurity(
40-
string $uriScheme,
41-
Response $response,
44+
string $uriScheme,
45+
Response $response,
4246
?RouteMatch $match
43-
) : Response {
47+
): Response {
4448
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match)) {
4549
return $response;
4650
}
@@ -63,14 +67,14 @@ private function setHttpStrictTransportSecurity(
6367
/**
6468
* Force Https Scheme handle.
6569
*/
66-
public function forceHttpsScheme(MvcEvent $e) : void
70+
public function forceHttpsScheme(MvcEvent $e): void
6771
{
68-
/** @var \Laminas\Http\PhpEnvironment\Request $request */
69-
$request = $e->getRequest();
72+
/** @var Request $request */
73+
$request = $e->getRequest();
7074
/** @var Response $response */
71-
$response = $e->getResponse();
75+
$response = $e->getResponse();
7276

73-
$uri = $request->getUri();
77+
$uri = $request->getUri();
7478
/** @var string $uriScheme*/
7579
$uriScheme = $uri->getScheme();
7680

src/Listener/ForceHttpsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class ForceHttpsFactory
1010
{
11-
public function __invoke(ContainerInterface $container) : ForceHttps
11+
public function __invoke(ContainerInterface $container): ForceHttps
1212
{
1313
$config = $container->get('config');
1414
$forceHttpsConfig = $config['force-https-module'] ?? ['enable' => false];

src/Middleware/ForceHttps.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace ForceHttpsModule\Middleware;
66

77
use ForceHttpsModule\HttpsTrait;
8+
use Mezzio\Router\RouteResult;
9+
use Mezzio\Router\RouterInterface;
810
use Psr\Http\Message\ResponseInterface;
911
use Psr\Http\Message\ServerRequestInterface;
1012
use Psr\Http\Server\MiddlewareInterface;
1113
use Psr\Http\Server\RequestHandlerInterface;
12-
use Mezzio\Router\RouteResult;
13-
use Mezzio\Router\RouterInterface;
1414

1515
class ForceHttps implements MiddlewareInterface
1616
{
@@ -29,10 +29,10 @@ public function __construct(array $config, RouterInterface $router)
2929
}
3030

3131
private function setHttpStrictTransportSecurity(
32-
string $uriScheme,
32+
string $uriScheme,
3333
ResponseInterface $response,
34-
RouteResult $match
35-
) : ResponseInterface {
34+
RouteResult $match
35+
): ResponseInterface {
3636
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match)) {
3737
return $response;
3838
}
@@ -47,14 +47,14 @@ private function setHttpStrictTransportSecurity(
4747
return $response->withHeader('Strict-Transport-Security', 'max-age=0');
4848
}
4949

50-
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
50+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
5151
{
5252
$response = $handler->handle($request);
5353
if (! $this->config['enable']) {
5454
return $response;
5555
}
5656

57-
$match = $this->router->match($request);
57+
$match = $this->router->match($request);
5858

5959
$uri = $request->getUri();
6060
$uriScheme = $uri->getScheme();

src/Middleware/ForceHttpsFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace ForceHttpsModule\Middleware;
66

7-
use Psr\Container\ContainerInterface;
87
use Mezzio\Router\RouterInterface;
8+
use Psr\Container\ContainerInterface;
99

1010
class ForceHttpsFactory
1111
{
12-
public function __invoke(ContainerInterface $container) : ForceHttps
12+
public function __invoke(ContainerInterface $container): ForceHttps
1313
{
14-
$config = $container->get('config');
15-
$router = $container->get(RouterInterface::class);
14+
$config = $container->get('config');
15+
$router = $container->get(RouterInterface::class);
1616
$forceHttpsConfig = $config['force-https-module'] ?? ['enable' => false];
1717

1818
return new ForceHttps($forceHttpsConfig, $router);

src/Module.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class Module
88
{
9-
public function getConfig() : array
9+
public function getConfig(): array
1010
{
11-
return include __DIR__.'./../config/module.config.php';
11+
return include __DIR__ . './../config/module.config.php';
1212
}
1313
}

0 commit comments

Comments
 (0)