Skip to content

Commit 1494060

Browse files
committed
apply zend coding standard
1 parent cd3ae2c commit 1494060

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/.coveralls.yml export-ignore
55
/spec/ export-ignore
6-
/CONTRIBUTING.md export-ignore
6+
/CONTRIBUTING.md export-ignore
7+
/phpcs.xml export-ignore

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"php-coveralls/php-coveralls": "^2.1",
3939
"phpstan/phpstan": "^0.10.8",
4040
"phpstan/phpstan-webmozart-assert": "^0.10.0",
41+
"zendframework/zend-coding-standard": "^1.0",
4142
"zendframework/zend-expressive": "^3.0",
4243
"zendframework/zend-mvc": "^3.0"
4344
},
@@ -59,5 +60,9 @@
5960
"psr-4": {
6061
"ForceHttpsModule\\Spec\\": "spec/"
6162
}
63+
},
64+
"scripts": {
65+
"cs-check": "phpcs",
66+
"cs-fix": "phpcbf"
6267
}
6368
}

phpcs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Zend Framework Coding Standard">
3+
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
4+
5+
<!-- Paths to check -->
6+
<file>src</file>
7+
</ruleset>

src/HttpsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private function isGoingToBeForcedToHttps($match = null) : bool
5858
* @param Response|ResponseInterface $response
5959
*
6060
*/
61-
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null, $response) : bool
61+
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $response, $match = null) : bool
6262
{
6363
return ! $this->isSchemeHttps($uriScheme) ||
6464
! $this->isGoingToBeForcedToHttps($match) ||

src/Listener/ForceHttps.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,21 @@ public function attach(EventManagerInterface $events, $priority = 1) : void
3636
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'forceHttpsScheme'], 1000);
3737
}
3838

39-
private function setHttpStrictTransportSecurity(string $uriScheme, RouteMatch $match = null, Response $response) : Response
40-
{
41-
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match, $response)) {
39+
private function setHttpStrictTransportSecurity(
40+
string $uriScheme,
41+
Response $response,
42+
RouteMatch $match = null
43+
) : Response {
44+
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $response, $match)) {
4245
return $response;
4346
}
4447

4548
if ($this->config['strict_transport_security']['enable'] === true) {
4649
$response->getHeaders()
47-
->addHeaderLine('Strict-Transport-Security: ' . $this->config['strict_transport_security']['value']);
50+
->addHeaderLine(sprintf(
51+
'Strict-Transport-Security: %s',
52+
$this->config['strict_transport_security']['value']
53+
));
4854
return $response;
4955
}
5056

@@ -70,7 +76,7 @@ public function forceHttpsScheme(MvcEvent $e) : void
7076

7177
/** @var RouteMatch|null $routeMatch */
7278
$routeMatch = $e->getRouteMatch();
73-
$response = $this->setHttpStrictTransportSecurity($uriScheme, $routeMatch, $response);
79+
$response = $this->setHttpStrictTransportSecurity($uriScheme, $response, $routeMatch);
7480
if (! $this->isGoingToBeForcedToHttps($routeMatch)) {
7581
return;
7682
}

src/Middleware/ForceHttps.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ public function __construct(array $config, RouterInterface $router)
2828
$this->router = $router;
2929
}
3030

31-
private function setHttpStrictTransportSecurity($uriScheme, RouteResult $match, ResponseInterface $response) : ResponseInterface
32-
{
33-
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match, $response)) {
31+
private function setHttpStrictTransportSecurity(
32+
string $uriScheme,
33+
ResponseInterface $response,
34+
RouteResult $match
35+
) : ResponseInterface {
36+
37+
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $response, $match)) {
3438
return $response;
3539
}
3640

3741
if ($this->config['strict_transport_security']['enable'] === true) {
38-
return $response->withHeader('Strict-Transport-Security', $this->config['strict_transport_security']['value']);
42+
return $response->withHeader(
43+
'Strict-Transport-Security',
44+
$this->config['strict_transport_security']['value']
45+
);
3946
}
4047

4148
return $response->withHeader('Strict-Transport-Security', 'max-age=0');
@@ -53,7 +60,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5360
$uri = $request->getUri();
5461
$uriScheme = $uri->getScheme();
5562

56-
$response = $this->setHttpStrictTransportSecurity($uriScheme, $match, $response);
63+
$response = $this->setHttpStrictTransportSecurity($uriScheme, $response, $match);
5764
if (! $this->isGoingToBeForcedToHttps($match)) {
5865
return $response;
5966
}

0 commit comments

Comments
 (0)