Skip to content

Commit 9fe7725

Browse files
Fix nullable types for PHP 8.4 (#6)
1 parent 33eae10 commit 9fe7725

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2023 odan
3+
Copyright (c) 2025 odan
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A PSR-15 middleware to secure your site with SameSite cookies :cookie:
1212

1313
## Requirements
1414

15-
* PHP 8.1+
15+
* PHP 8.1 - 8.4
1616

1717
## Installation
1818

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
],
1212
"homepage": "https://github.com/selective-php/samesite-cookie",
1313
"require": {
14-
"php": "^7.2 || ^8.0",
14+
"php": "8.1.* || 8.2.* || 8.3.* || 8.4.*",
1515
"psr/http-message": "^1",
1616
"psr/http-server-handler": "^1",
1717
"psr/http-server-middleware": "^1"
1818
},
1919
"require-dev": {
2020
"friendsofphp/php-cs-fixer": "^3",
21-
"middlewares/utils": "^3",
22-
"phpstan/phpstan": "^1",
21+
"middlewares/utils": "^3 || ^4",
22+
"phpstan/phpstan": "^1 || ^2",
2323
"phpunit/phpunit": "^10",
2424
"slim/psr7": "^1",
2525
"squizlabs/php_codesniffer": "^3"
@@ -49,13 +49,16 @@
4949
"sniffer:check": "phpcs --standard=phpcs.xml",
5050
"sniffer:fix": "phpcbf --standard=phpcs.xml",
5151
"stan": "phpstan analyse -c phpstan.neon --no-progress --ansi",
52-
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always",
52+
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --no-coverage",
5353
"test:all": [
5454
"@cs:check",
5555
"@sniffer:check",
5656
"@stan",
5757
"@test"
5858
],
59-
"test:coverage": "php -d xdebug.mode=coverage -r \"require 'vendor/bin/phpunit';\" -- --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/logs/clover.xml --coverage-html build/coverage"
59+
"test:coverage": [
60+
"@putenv XDEBUG_MODE=coverage",
61+
"phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-clover build/coverage/clover.xml --coverage-html build/coverage --coverage-text"
62+
]
6063
}
6164
}

src/SameSiteCookieMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ final class SameSiteCookieMiddleware implements MiddlewareInterface
3030
* @param SessionHandlerInterface|null $sessionHandler The session handler
3131
*/
3232
public function __construct(
33-
SameSiteCookieConfiguration $configuration = null,
34-
SessionHandlerInterface $sessionHandler = null
33+
?SameSiteCookieConfiguration $configuration = null,
34+
?SessionHandlerInterface $sessionHandler = null
3535
) {
3636
$this->configuration = $configuration ?: new SameSiteCookieConfiguration();
3737
$this->sessionHandler = $sessionHandler ?: new PhpSessionHandler();

src/SameSiteSessionMiddleware.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ final class SameSiteSessionMiddleware implements MiddlewareInterface
2222
*
2323
* @param SessionHandlerInterface|null $sessionHandler The session handler
2424
*/
25-
public function __construct(SessionHandlerInterface $sessionHandler = null)
26-
{
25+
public function __construct(
26+
?SessionHandlerInterface $sessionHandler = null
27+
) {
2728
$this->sessionHandler = $sessionHandler ?: new PhpSessionHandler();
2829
}
2930

tests/SameSiteCookieMiddlewareTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,29 @@ public function testDefaultConfiguration(): void
3232
$this->assertSame('PHPSESSID=v3absd19o9pi6cjvhb5pkmsfo9; path=/; Secure; HttpOnly; SameSite=Lax;', $cookie);
3333
$this->assertSame('', (string)$response->getBody());
3434
}
35+
36+
/**
37+
* Test with own settings.
38+
*/
39+
public function testDefaultConfigurationWithOwnSettings(): void
40+
{
41+
$settings = [
42+
'start_session' => true,
43+
'same_site' => 'Strict',
44+
'http_only' => false,
45+
];
46+
47+
$configuration = new SameSiteCookieConfiguration($settings);
48+
49+
session_id('v3absd19o9pi6cjvhb5pkmsfo9');
50+
51+
$response = $this->runQueue([
52+
new SameSiteSessionMiddleware(),
53+
new SameSiteCookieMiddleware($configuration),
54+
]);
55+
56+
$cookie = $response->getHeaderLine('Set-Cookie');
57+
$this->assertSame('PHPSESSID=v3absd19o9pi6cjvhb5pkmsfo9; path=/; Secure; SameSite=Strict;', $cookie);
58+
$this->assertSame('', (string)$response->getBody());
59+
}
3560
}

0 commit comments

Comments
 (0)