Skip to content

Commit 8f46768

Browse files
committed
Bump to PHP 8.2 and PHP 8.4 support
1 parent 4ab20c4 commit 8f46768

File tree

7 files changed

+88
-94
lines changed

7 files changed

+88
-94
lines changed

.github/workflows/ci_build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['7.4', '8.0', '8.1']
16+
php-versions: ['8.2', '8.3', '8.4']
1717
steps:
1818
- name: Setup PHP Action
1919
uses: shivammathur/setup-php@v2
@@ -35,6 +35,7 @@ jobs:
3535
- name: "Run test suite"
3636
run: "mkdir -p build/logs && bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml"
3737
- name: Upload coverage to Codecov
38+
if: github.event.pull_request.head.repo.full_name == 'samsonasik/ForceHttpsModule'
3839
uses: codecov/codecov-action@v1
3940
with:
4041
token: ${{ secrets.CODECOV_TOKEN }}

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^7.4|^8.0",
28-
"webmozart/assert": "^1.9"
27+
"php": "^8.2",
28+
"webmozart/assert": "^1.11"
2929
},
3030
"conflict": {
3131
"mezzio/mezzio": "<3.0",
3232
"laminas/laminas-mvc": "<3.0"
3333
},
3434
"require-dev": {
35-
"kahlan/kahlan": "^5.2",
36-
"laminas/laminas-coding-standard": "^2.0",
37-
"laminas/laminas-mvc": "^3.0",
38-
"mezzio/mezzio": "^3.0",
39-
"php-coveralls/php-coveralls": "^2.1",
40-
"phpstan/phpstan": "^1.1",
41-
"phpstan/phpstan-webmozart-assert": "^1.0",
35+
"kahlan/kahlan": "^6.0",
36+
"laminas/laminas-coding-standard": "^2.5",
37+
"laminas/laminas-mvc": "^3.8",
38+
"mezzio/mezzio": "^3.20.1",
39+
"php-coveralls/php-coveralls": "^2.7",
40+
"phpstan/phpstan": "^2.0.4",
41+
"phpstan/phpstan-webmozart-assert": "^2.0",
4242
"rector/rector": "dev-main"
4343
},
4444
"config": {

rector.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,20 @@
22

33
declare(strict_types=1);
44

5-
use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
6-
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
7-
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
85
use Rector\Config\RectorConfig;
9-
use Rector\Set\ValueObject\LevelSetList;
10-
use Rector\Set\ValueObject\SetList;
6+
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
117

12-
return static function (RectorConfig $rectorConfig): void {
13-
$rectorConfig->sets([
14-
SetList::DEAD_CODE,
15-
LevelSetList::UP_TO_PHP_74,
16-
SetList::CODE_QUALITY,
17-
SetList::NAMING,
18-
SetList::TYPE_DECLARATION,
19-
SetList::CODING_STYLE,
20-
]);
21-
22-
$rectorConfig->paths([
8+
return RectorConfig::configure()
9+
->withPhpSets(php82: true)
10+
->withPreparedSets(deadCode: true, codeQuality: true, naming: true, typeDeclarations: true, codingStyle: true)
11+
->withImportNames(removeUnusedImports: true)
12+
->withPaths([
2313
__DIR__ . '/config',
2414
__DIR__ . '/src',
2515
__DIR__ . '/spec',
2616
__DIR__ . '/rector.php'
17+
])
18+
->withRootFiles()
19+
->withSkip([
20+
FirstClassCallableRector::class,
2721
]);
28-
$rectorConfig->importNames();
29-
$rectorConfig->skip([
30-
CallableThisArrayToAnonymousFunctionRector::class,
31-
StaticArrowFunctionRector::class => [
32-
__DIR__ . '/spec',
33-
],
34-
StaticClosureRector::class => [
35-
__DIR__ . '/spec',
36-
],
37-
]);
38-
};

spec/Listener/ForceHttpsSpec.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Kahlan\Plugin\Double;
77
use Kahlan\Plugin\Quit;
88
use Kahlan\QuitException;
9-
use Laminas\Console\Console;
109
use Laminas\EventManager\EventManagerInterface;
1110
use Laminas\Http\PhpEnvironment\Request;
1211
use Laminas\Http\PhpEnvironment\Response;

spec/Middleware/ForceHttpsSpec.php

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939

4040
it('not redirect on router not match', function (): void {
4141

42-
$match = RouteResult::fromRouteFailure(null);
43-
allow($this->router)->toReceive('match')->andReturn($match);
44-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
42+
$routeResult = RouteResult::fromRouteFailure(null);
43+
44+
allow($this->router)->toReceive('match')->andReturn($routeResult);
45+
46+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
47+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
4548

4649
$listener = new ForceHttps(['enable' => true], $this->router);
4750

@@ -56,9 +59,13 @@
5659

5760
it('not redirect on router not match and config allow_404 is false', function (): void {
5861

59-
$match = RouteResult::fromRouteFailure(null);
60-
allow($this->router)->toReceive('match')->andReturn($match);
61-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
62+
$routeResult = RouteResult::fromRouteFailure(null);
63+
64+
allow($this->router)->toReceive('match')->andReturn($routeResult);
65+
66+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
67+
allow($this->uri)->toReceive('__toString')->andReturn('http://example.com/404');
68+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
6269

6370
$listener = new ForceHttps(
6471
[
@@ -79,11 +86,13 @@
7986

8087
it('not redirect on https and match but no strict_transport_security config', function (): void {
8188

82-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
89+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
8390

84-
allow($this->router)->toReceive('match')->andReturn($match);
91+
allow($this->router)->toReceive('match')->andReturn($routeResult);
8592

86-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https');
93+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
94+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about');
95+
allow($this->uri)->toReceive('getScheme')->andReturn('https');
8796

8897
$listener = new ForceHttps(['enable' => true, 'force_all_routes' => true], $this->router);
8998

@@ -98,10 +107,12 @@
98107

99108
it('not redirect on http and match, with force_all_routes is false and matched route name not in force_specific_routes config', function (): void {
100109

101-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
102-
allow($this->router)->toReceive('match')->andReturn($match);
110+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
111+
allow($this->router)->toReceive('match')->andReturn($routeResult);
103112

104-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
113+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
114+
allow($this->uri)->toReceive('__toString')->andReturn('http://example.com/about');
115+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
105116

106117
$listener = new ForceHttps(
107118
[
@@ -127,11 +138,13 @@
127138

128139
it('not redirect on https and match, with strict_transport_security config, but disabled', function (): void {
129140

130-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
141+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
131142

132-
allow($this->router)->toReceive('match')->andReturn($match);
143+
allow($this->router)->toReceive('match')->andReturn($routeResult);
133144

134-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https');
145+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
146+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about');
147+
allow($this->uri)->toReceive('getScheme')->andReturn('https');
135148

136149
$listener = new ForceHttps(
137150
[
@@ -157,10 +170,12 @@
157170

158171
it('not redirect on https and match, with strict_transport_security config, and enabled', function (): void {
159172

160-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
173+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
161174

162-
allow($this->router)->toReceive('match')->andReturn($match);
163-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https');
175+
allow($this->router)->toReceive('match')->andReturn($routeResult);
176+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
177+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about');
178+
allow($this->uri)->toReceive('getScheme')->andReturn('https');
164179

165180
$listener = new ForceHttps(
166181
[
@@ -186,11 +201,14 @@
186201

187202
it('return Response with 308 status on http and match', function (): void {
188203

189-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
204+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
205+
206+
allow($this->router)->toReceive('match')->andReturn($routeResult);
190207

191-
allow($this->router)->toReceive('match')->andReturn($match);
192-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
193-
allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about');
208+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
209+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
210+
allow($this->uri)->toReceive('withScheme')->andReturn($this->uri);
211+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about');
194212

195213
$handler = Double::instance(['implements' => RequestHandlerInterface::class]);
196214
allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response);
@@ -217,11 +235,14 @@
217235

218236
it('return Response with 308 status on http and not match, but allow_404 is true', function (): void {
219237

220-
$match = RouteResult::fromRouteFailure(null);
238+
$routeResult = RouteResult::fromRouteFailure(null);
221239

222-
allow($this->router)->toReceive('match')->andReturn($match);
223-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
224-
allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/404');
240+
allow($this->router)->toReceive('match')->andReturn($routeResult);
241+
242+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
243+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
244+
allow($this->uri)->toReceive('withScheme')->andReturn($this->uri);
245+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/404');
225246

226247
$handler = Double::instance(['implements' => RequestHandlerInterface::class]);
227248
allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response);
@@ -244,11 +265,13 @@
244265

245266
it('return Response with 308 status with include www prefix on http and match with configurable "add_www_prefix"', function (): void {
246267

247-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
268+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
248269

249-
allow($this->router)->toReceive('match')->andReturn($match);
250-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
251-
allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about');
270+
allow($this->router)->toReceive('match')->andReturn($routeResult);
271+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
272+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
273+
allow($this->uri)->toReceive('withScheme')->andReturn($this->uri);
274+
allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about');
252275

253276
$handler = Double::instance(['implements' => RequestHandlerInterface::class]);
254277
allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response);
@@ -276,16 +299,13 @@
276299

277300
it('return Response with 308 status with remove www prefix on http and match with configurable "remove_www_prefix"', function (): void {
278301

279-
$match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
302+
$routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class])));
280303

281-
allow($this->request)->toReceive('getUri', '__toString')->andReturn('http://www.example.com/about');
282-
allow($this->router)->toReceive('match')->andReturn($match);
283-
allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http');
284-
allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://www.example.com/about');
285-
286-
allow($this->response)->toReceive('withStatus')->andReturn($this->response);
287-
$handler = Double::instance(['implements' => RequestHandlerInterface::class]);
288-
allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response);
304+
allow($this->router)->toReceive('match')->andReturn($routeResult);
305+
allow($this->request)->toReceive('getUri')->andReturn($this->uri);
306+
allow($this->uri)->toReceive('getScheme')->andReturn('http');
307+
allow($this->uri)->toReceive('withScheme')->andReturn($this->uri);
308+
allow($this->uri)->toReceive('__toString')->andReturn('https://www.example.com/about');
289309

290310
$handler = Double::instance(['implements' => RequestHandlerInterface::class]);
291311
allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response);
@@ -300,12 +320,10 @@
300320
'enable' => true,
301321
'value' => 'max-age=31536000',
302322
],
303-
'add_www_prefix' => false,
304323
'remove_www_prefix' => true,
305324
],
306325
$this->router
307326
);
308-
309327
$listener->process($this->request, $handler);
310328

311329
expect($this->response)->toReceive('withStatus')->with(308);

src/HttpsTrait.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
trait HttpsTrait
1616
{
17-
/** @var bool */
18-
private $needsWwwPrefix = false;
17+
private bool $needsWwwPrefix = false;
1918

20-
/** @var bool */
21-
private $alreadyHasWwwPrefix = false;
19+
private bool $alreadyHasWwwPrefix = false;
2220

2321
private function isSchemeHttps(string $uriScheme): bool
2422
{
@@ -27,10 +25,8 @@ private function isSchemeHttps(string $uriScheme): bool
2725

2826
/**
2927
* Check Config if is going to be forced to https.
30-
*
31-
* @param RouteMatch|RouteResult|null $match
3228
*/
33-
private function isGoingToBeForcedToHttps($match = null): bool
29+
private function isGoingToBeForcedToHttps(RouteMatch|RouteResult|null $match = null): bool
3430
{
3531
if ($match === null || ($match instanceof RouteResult && $match->isFailure())) {
3632
return $this->config['allow_404'] ?? false;
@@ -49,11 +45,11 @@ private function isGoingToBeForcedToHttps($match = null): bool
4945

5046
/**
5147
* Check if Setup Strict-Transport-Security need to be skipped.
52-
*
53-
* @param RouteMatch|RouteResult|null $match
5448
*/
55-
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null): bool
56-
{
49+
private function isSkippedHttpStrictTransportSecurity(
50+
string $uriScheme,
51+
RouteMatch|RouteResult|null $match = null
52+
): bool {
5753
return ! $this->isSchemeHttps($uriScheme) ||
5854
! $this->isGoingToBeForcedToHttps($match) ||
5955
! isset(

src/Middleware/ForceHttps.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ class ForceHttps implements MiddlewareInterface
1818

1919
private array $config;
2020

21-
private RouterInterface $router;
22-
2321
/**
2422
* @param mixed[] $config
2523
*/
26-
public function __construct(array $config, RouterInterface $router)
24+
public function __construct(array $config, private RouterInterface $router)
2725
{
2826
$this->config = $config;
29-
$this->router = $router;
3027
}
3128

3229
private function setHttpStrictTransportSecurity(

0 commit comments

Comments
 (0)