11<?php
22
3+ declare (strict_types=1 );
4+
35namespace ZxcvbnPhp \Matchers ;
46
7+ use JetBrains \PhpStorm \ArrayShape ;
58use ZxcvbnPhp \Matcher ;
69
710class DateMatch extends BaseMatch
@@ -105,6 +108,7 @@ public static function match(string $password, array $userInputs = []): array
105108 return $ matches ;
106109 }
107110
111+ #[ArrayShape(['warning ' => 'string ' , 'suggestions ' => 'string[] ' ])]
108112 public function getFeedback (bool $ isSoleMatch ): array
109113 {
110114 return [
@@ -202,9 +206,9 @@ protected static function datesWithoutSeparators(string $password): array
202206
203207 $ possibleSplits = static ::$ DATE_SPLITS [mb_strlen ($ token )];
204208 foreach ($ possibleSplits as $ splitPositions ) {
205- $ day = mb_substr ($ token , 0 , $ splitPositions [0 ]);
206- $ month = mb_substr ($ token , $ splitPositions [0 ], $ splitPositions [1 ] - $ splitPositions [0 ]);
207- $ year = mb_substr ($ token , $ splitPositions [1 ]);
209+ $ day = ( int ) mb_substr ($ token , 0 , $ splitPositions [0 ]);
210+ $ month = ( int ) mb_substr ($ token , $ splitPositions [0 ], $ splitPositions [1 ] - $ splitPositions [0 ]);
211+ $ year = ( int ) mb_substr ($ token , $ splitPositions [1 ]);
208212
209213 $ date = static ::checkDate ([$ day , $ month , $ year ]);
210214 if ($ date !== false ) {
@@ -285,21 +289,21 @@ protected static function checkDate(array $ints)
285289 return false ;
286290 }
287291
288- $ invalidYear = count (array_filter ($ ints , function (int $ int ) {
292+ $ invalidYear = count (array_filter ($ ints , function (int $ int ): bool {
289293 return ($ int >= 100 && $ int < static ::MIN_YEAR )
290294 || ($ int > static ::MAX_YEAR );
291295 }));
292296 if ($ invalidYear > 0 ) {
293297 return false ;
294298 }
295299
296- $ over12 = count (array_filter ($ ints , function (int $ int ) {
300+ $ over12 = count (array_filter ($ ints , function (int $ int ): bool {
297301 return $ int > 12 ;
298302 }));
299- $ over31 = count (array_filter ($ ints , function (int $ int ) {
303+ $ over31 = count (array_filter ($ ints , function (int $ int ): bool {
300304 return $ int > 31 ;
301305 }));
302- $ under1 = count (array_filter ($ ints , function (int $ int ) {
306+ $ under1 = count (array_filter ($ ints , function (int $ int ): bool {
303307 return $ int <= 0 ;
304308 }));
305309
@@ -313,7 +317,7 @@ protected static function checkDate(array $ints)
313317 [$ ints [0 ], [$ ints [1 ], $ ints [2 ]]], // year first
314318 ];
315319
316- foreach ($ possibleYearSplits as list ( $ year , $ rest) ) {
320+ foreach ($ possibleYearSplits as [ $ year , $ rest] ) {
317321 if ($ year >= static ::MIN_YEAR && $ year <= static ::MAX_YEAR ) {
318322 if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
319323 return [
@@ -329,7 +333,7 @@ protected static function checkDate(array $ints)
329333 }
330334 }
331335
332- foreach ($ possibleYearSplits as list ( $ year , $ rest) ) {
336+ foreach ($ possibleYearSplits as [ $ year , $ rest] ) {
333337 if ($ dm = static ::mapIntsToDayMonth ($ rest )) {
334338 return [
335339 'year ' => static ::twoToFourDigitYear ($ year ),
@@ -349,7 +353,7 @@ protected static function checkDate(array $ints)
349353 */
350354 protected static function mapIntsToDayMonth (array $ ints )
351355 {
352- foreach ([$ ints , array_reverse ($ ints )] as list ( $ d , $ m) ) {
356+ foreach ([$ ints , array_reverse ($ ints )] as [ $ d , $ m] ) {
353357 if ($ d >= 1 && $ d <= 31 && $ m >= 1 && $ m <= 12 ) {
354358 return [
355359 'day ' => $ d ,
0 commit comments