Skip to content

Commit e98460d

Browse files
authored
Merge pull request #16 from samsonasik/apply-zend-coding-standard
apply zend coding standard
2 parents cd3ae2c + 7a288be commit e98460d

File tree

8 files changed

+39
-14
lines changed

8 files changed

+39
-14
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

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ before_script:
1212
- composer dump-autoload -o
1313

1414
script:
15+
- composer cs-check
1516
- bin/phpstan analyse src/ --level=max
1617
- bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml
1718
- bin/php-coveralls -v --exclude-no-stmt

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 PSR-2 Coding Standard.
6+
- Use [Zend Coding Standard](https://github.com/zendframework/zend-coding-standard).
77
- patch(es) need new/updated test(s).
88
- new feature(s) need test(s).
99

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ private function isGoingToBeForcedToHttps($match = null) : bool
5555
* Check if Setup Strict-Transport-Security need to be skipped.
5656
*
5757
* @param RouteMatch|RouteResult|null $match
58-
* @param Response|ResponseInterface $response
5958
*
6059
*/
61-
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null, $response) : bool
60+
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null) : bool
6261
{
6362
return ! $this->isSchemeHttps($uriScheme) ||
6463
! $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, $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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ 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+
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match)) {
3437
return $response;
3538
}
3639

3740
if ($this->config['strict_transport_security']['enable'] === true) {
38-
return $response->withHeader('Strict-Transport-Security', $this->config['strict_transport_security']['value']);
41+
return $response->withHeader(
42+
'Strict-Transport-Security',
43+
$this->config['strict_transport_security']['value']
44+
);
3945
}
4046

4147
return $response->withHeader('Strict-Transport-Security', 'max-age=0');
@@ -53,7 +59,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5359
$uri = $request->getUri();
5460
$uriScheme = $uri->getScheme();
5561

56-
$response = $this->setHttpStrictTransportSecurity($uriScheme, $match, $response);
62+
$response = $this->setHttpStrictTransportSecurity($uriScheme, $response, $match);
5763
if (! $this->isGoingToBeForcedToHttps($match)) {
5864
return $response;
5965
}

0 commit comments

Comments
 (0)