@@ -20,6 +20,9 @@ class DateMatch extends BaseMatch
20
20
21
21
public $ pattern = 'date ' ;
22
22
23
+ /**
24
+ * @var array<int, array<array<int, int>>>
25
+ */
23
26
private static $ DATE_SPLITS = [
24
27
4 => [ # For length-4 strings, eg 1191 or 9111, two ways to split:
25
28
[1 , 2 ], # 1 1 91 (2nd split starts at index 1, 3rd at index 2)
@@ -57,23 +60,39 @@ class DateMatch extends BaseMatch
57
60
*/
58
61
protected const DATE_WITH_SEPARATOR = '/^(\d{1,4})([\s\/ \\\\_.-])(\d{1,2})\2(\d{1,4})$/u ' ;
59
62
60
- /** @var int The day portion of the date in the token. */
63
+ /**
64
+ * The day portion of the date in the token.
65
+ *
66
+ * @var int
67
+ */
61
68
public $ day ;
62
69
63
- /** @var int The month portion of the date in the token. */
70
+ /**
71
+ * The month portion of the date in the token.
72
+ *
73
+ * @var int
74
+ */
64
75
public $ month ;
65
76
66
- /** @var int The year portion of the date in the token. */
77
+ /**
78
+ * The year portion of the date in the token.
79
+ *
80
+ * @var int
81
+ */
67
82
public $ year ;
68
83
69
- /** @var string The separator used for the date in the token. */
84
+ /**
85
+ * The separator used for the date in the token.
86
+ *
87
+ * @var string
88
+ */
70
89
public $ separator ;
71
90
72
91
/**
73
92
* Match occurences of dates in a password
74
93
*
75
94
* @param string $password
76
- * @param array $userInputs
95
+ * @param array<int, string> $userInputs
77
96
* @return DateMatch[]
78
97
*/
79
98
public static function match (string $ password , array $ userInputs = []): array
@@ -124,7 +143,7 @@ public function getFeedback(bool $isSoleMatch): array
124
143
* @param int $begin
125
144
* @param int $end
126
145
* @param string $token
127
- * @param array $params An array with keys: [day , month, year, separator].
146
+ * @param array{day: int , month: int , year: int , separator: string} $params
128
147
*/
129
148
public function __construct (string $ password , int $ begin , int $ end , string $ token , array $ params )
130
149
{
@@ -272,7 +291,7 @@ public static function getReferenceYear(): int
272
291
273
292
/**
274
293
* @param int[] $ints Three numbers in an array representing day, month and year (not necessarily in that order).
275
- * @return array|bool Returns an associative array containing 'day', 'month' and 'year' keys, or false if the
294
+ * @return array{year: int, month: int, day: int}|false Returns an associative array containing 'day', 'month' and 'year' keys, or false if the
276
295
* provided date array is invalid.
277
296
*/
278
297
protected static function checkDate (array $ ints )
@@ -319,7 +338,8 @@ protected static function checkDate(array $ints)
319
338
320
339
foreach ($ possibleYearSplits as [$ year , $ rest ]) {
321
340
if ($ year >= static ::MIN_YEAR && $ year <= static ::MAX_YEAR ) {
322
- if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
341
+ $ dm = static ::mapIntsToDayMonth ($ rest );
342
+ if ($ dm ) {
323
343
return [
324
344
'year ' => $ year ,
325
345
'month ' => $ dm ['month ' ],
@@ -334,7 +354,8 @@ protected static function checkDate(array $ints)
334
354
}
335
355
336
356
foreach ($ possibleYearSplits as [$ year , $ rest ]) {
337
- if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
357
+ $ dm = static ::mapIntsToDayMonth ($ rest );
358
+ if ($ dm ) {
338
359
return [
339
360
'year ' => static ::twoToFourDigitYear ($ year ),
340
361
'month ' => $ dm ['month ' ],
@@ -348,7 +369,9 @@ protected static function checkDate(array $ints)
348
369
349
370
/**
350
371
* @param int[] $ints Two numbers in an array representing day and month (not necessarily in that order).
351
- * @return array|bool Returns an associative array containing 'day' and 'month' keys, or false if any combination
372
+ *
373
+ * @return array{day: int, month: int}|false
374
+ * Returns an associative array containing 'day' and 'month' keys, or false if any combination
352
375
* of the two numbers does not match a day and month.
353
376
*/
354
377
protected static function mapIntsToDayMonth (array $ ints )
0 commit comments