Skip to content

Commit 8f58938

Browse files
author
Greg Bowler
authored
Improve typehinting (#116)
1 parent c40aca5 commit 8f58938

5 files changed

+55
-42
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66

77
"require": {
8-
"php": ">=7.2",
8+
"php": ">=7.4",
99
"phpgt/dom": "2.*",
1010
"phpgt/session": "1.*"
1111
},

composer.lock

+47-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ArrayTokenStore.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* session - it has no other way of remembering the tokens!
1010
*/
1111
class ArrayTokenStore extends TokenStore {
12-
private $arrayStore = [];
12+
/** @var array<string, ?int> */
13+
private array $arrayStore = [];
1314

1415
public function __construct(int $maxTokens = null) {
1516
parent::__construct($maxTokens);

src/HTMLDocumentProtector.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class HTMLDocumentProtector {
1616
*/
1717
const TOKEN_NAME = "csrf-token";
1818

19-
private $document;
20-
private $tokenStore;
19+
private HTMLDocument $document;
20+
private TokenStore $tokenStore;
2121

2222
public function __construct(
2323
HTMLDocument $document,

src/TokenStore.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
* the tokens is provided by the base class, but can be overridden.
1111
*/
1212
abstract class TokenStore {
13-
/**
14-
* @var int|null The maximum number of tokens to be retained.
15-
*/
16-
protected $maxTokens = 1000;
17-
protected $tokenLength = 32;
18-
protected $tokenGenerator;
13+
protected ?int $maxTokens = 1000;
14+
protected int $tokenLength = 32;
1915

2016
/**
2117
* An optional limit of the number of valid tokens the TokenStore will retain may be passed.
@@ -57,6 +53,7 @@ public function generateNewToken():string {
5753
* If a $_POST global exists, check that it contains a token and that the token is valid.
5854
* The name the token is stored-under is contained in HTMLDocumentProtector::TOKEN_NAME.
5955
*
56+
* @param array<string, int>|callable $postData
6057
* @throws CsrfTokenMissingException There's a $_POST request present but no
6158
* token present
6259
* @throws CsrfTokenInvalidException There's a token included on the $_POST,

0 commit comments

Comments
 (0)