@@ -20,6 +20,9 @@ class DateMatch extends BaseMatch
2020
2121 public $ pattern = 'date ' ;
2222
23+ /**
24+ * @var array<int, array<array<int, int>>>
25+ */
2326 private static $ DATE_SPLITS = [
2427 4 => [ # For length-4 strings, eg 1191 or 9111, two ways to split:
2528 [1 , 2 ], # 1 1 91 (2nd split starts at index 1, 3rd at index 2)
@@ -57,23 +60,39 @@ class DateMatch extends BaseMatch
5760 */
5861 protected const DATE_WITH_SEPARATOR = '/^(\d{1,4})([\s\/ \\\\_.-])(\d{1,2})\2(\d{1,4})$/u ' ;
5962
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+ */
6168 public $ day ;
6269
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+ */
6475 public $ month ;
6576
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+ */
6782 public $ year ;
6883
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+ */
7089 public $ separator ;
7190
7291 /**
7392 * Match occurences of dates in a password
7493 *
7594 * @param string $password
76- * @param array $userInputs
95+ * @param array<int, string> $userInputs
7796 * @return DateMatch[]
7897 */
7998 public static function match (string $ password , array $ userInputs = []): array
@@ -124,7 +143,7 @@ public function getFeedback(bool $isSoleMatch): array
124143 * @param int $begin
125144 * @param int $end
126145 * @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
128147 */
129148 public function __construct (string $ password , int $ begin , int $ end , string $ token , array $ params )
130149 {
@@ -272,7 +291,7 @@ public static function getReferenceYear(): int
272291
273292 /**
274293 * @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
276295 * provided date array is invalid.
277296 */
278297 protected static function checkDate (array $ ints )
@@ -319,7 +338,8 @@ protected static function checkDate(array $ints)
319338
320339 foreach ($ possibleYearSplits as [$ year , $ rest ]) {
321340 if ($ year >= static ::MIN_YEAR && $ year <= static ::MAX_YEAR ) {
322- if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
341+ $ dm = static ::mapIntsToDayMonth ($ rest );
342+ if ($ dm ) {
323343 return [
324344 'year ' => $ year ,
325345 'month ' => $ dm ['month ' ],
@@ -334,7 +354,8 @@ protected static function checkDate(array $ints)
334354 }
335355
336356 foreach ($ possibleYearSplits as [$ year , $ rest ]) {
337- if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
357+ $ dm = static ::mapIntsToDayMonth ($ rest );
358+ if ($ dm ) {
338359 return [
339360 'year ' => static ::twoToFourDigitYear ($ year ),
340361 'month ' => $ dm ['month ' ],
@@ -348,7 +369,9 @@ protected static function checkDate(array $ints)
348369
349370 /**
350371 * @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
352375 * of the two numbers does not match a day and month.
353376 */
354377 protected static function mapIntsToDayMonth (array $ ints )
0 commit comments