Skip to content

Commit 69bb0d1

Browse files
committed
Add PHPStan, fix phpstan errors
1 parent 1ed4432 commit 69bb0d1

File tree

13 files changed

+43
-38
lines changed

13 files changed

+43
-38
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"require-dev": {
2020
"phpunit/phpunit": "^8.5",
2121
"php-coveralls/php-coveralls": "*",
22-
"squizlabs/php_codesniffer": "3.*"
22+
"squizlabs/php_codesniffer": "3.*",
23+
"phpstan/phpstan": "^2.0"
2324
},
2425
"suggest": {
2526
"ext-gmp": "Required for optimized binomial calculations (also requires PHP >= 7.3)"

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 0
3+
paths:
4+
- src
5+
- test

src/Matchers/BaseMatch.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Math\Binomial;
98
use ZxcvbnPhp\Scorer;
109

@@ -48,10 +47,8 @@ public function __construct(string $password, int $begin, int $end, string $toke
4847
*
4948
* @param bool $isSoleMatch
5049
* Whether this is the only match in the password
51-
* @return array
52-
* Associative array with warning (string) and suggestions (array of strings)
50+
* @return array{'warning': string, "suggestions": string[]}
5351
*/
54-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
5552
abstract public function getFeedback(bool $isSoleMatch): array;
5653

5754
/**

src/Matchers/Bruteforce.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Scorer;
98

109
/**
@@ -13,7 +12,7 @@
1312
*
1413
* Intentionally not named with Match suffix to prevent autoloading from Matcher.
1514
*/
16-
class Bruteforce extends BaseMatch
15+
final class Bruteforce extends BaseMatch
1716
{
1817
public const BRUTEFORCE_CARDINALITY = 10;
1918

@@ -32,7 +31,9 @@ public static function match(string $password, array $userInputs = []): array
3231
}
3332

3433

35-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
34+
/**
35+
* @return array{'warning': string, "suggestions": string[]}
36+
*/
3637
public function getFeedback(bool $isSoleMatch): array
3738
{
3839
return [

src/Matchers/DateMatch.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Matcher;
98

10-
class DateMatch extends BaseMatch
9+
final class DateMatch extends BaseMatch
1110
{
1211
public const NUM_YEARS = 119; // Years match against 1900 - 2019
1312
public const NUM_MONTHS = 12;
@@ -108,7 +107,9 @@ public static function match(string $password, array $userInputs = []): array
108107
return $matches;
109108
}
110109

111-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
110+
/**
111+
* @return array{'warning': string, "suggestions": string[]}
112+
*/
112113
public function getFeedback(bool $isSoleMatch): array
113114
{
114115
return [

src/Matchers/DictionaryMatch.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Matcher;
98
use ZxcvbnPhp\Math\Binomial;
109

@@ -63,7 +62,7 @@ public static function match(string $password, array $userInputs = [], array $ra
6362
$results = static::dictionaryMatch($password, $dict);
6463
foreach ($results as $result) {
6564
$result['dictionary_name'] = $name;
66-
$matches[] = new static($password, $result['begin'], $result['end'], $result['token'], $result);
65+
$matches[] = new DictionaryMatch($password, $result['begin'], $result['end'], $result['token'], $result);
6766
}
6867
}
6968
Matcher::usortStable($matches, [Matcher::class, 'compareMatches']);
@@ -88,10 +87,8 @@ public function __construct(string $password, int $begin, int $end, string $toke
8887
}
8988

9089
/**
91-
* @param bool $isSoleMatch
92-
* @return array
90+
* @return array{'warning': string, "suggestions": string[]}
9391
*/
94-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
9592
public function getFeedback(bool $isSoleMatch): array
9693
{
9794
$startUpper = '/^[A-Z][^A-Z]+$/u';

src/Matchers/L33tMatch.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Matcher;
98
use ZxcvbnPhp\Math\Binomial;
109

@@ -98,7 +97,9 @@ public function __construct(string $password, int $begin, int $end, string $toke
9897
}
9998
}
10099

101-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
100+
/**
101+
* @return array{'warning': string, "suggestions": string[]}
102+
*/
102103
public function getFeedback(bool $isSoleMatch): array
103104
{
104105
$feedback = parent::getFeedback($isSoleMatch);

src/Matchers/RepeatMatch.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Matcher;
98
use ZxcvbnPhp\Scorer;
109

11-
class RepeatMatch extends BaseMatch
10+
final class RepeatMatch extends BaseMatch
1211
{
1312
public const GREEDY_MATCH = '/(.+)\1+/u';
1413
public const LAZY_MATCH = '/(.+?)\1+/u';
@@ -85,7 +84,9 @@ public static function match(string $password, array $userInputs = []): array
8584
return $matches;
8685
}
8786

88-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
87+
/**
88+
* @return array{'warning': string, "suggestions": string[]}
89+
*/
8990
public function getFeedback(bool $isSoleMatch): array
9091
{
9192
$warning = mb_strlen($this->repeatedChar) == 1

src/Matchers/ReverseDictionaryMatch.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
87
use ZxcvbnPhp\Matcher;
98

109
class ReverseDictionaryMatch extends DictionaryMatch
@@ -42,7 +41,9 @@ protected function getRawGuesses(): float
4241
return parent::getRawGuesses() * 2;
4342
}
4443

45-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
44+
/**
45+
* @return array{'warning': string, "suggestions": string[]}
46+
*/
4647
public function getFeedback(bool $isSoleMatch): array
4748
{
4849
$feedback = parent::getFeedback($isSoleMatch);

src/Matchers/SequenceMatch.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
use JetBrains\PhpStorm\ArrayShape;
8-
9-
class SequenceMatch extends BaseMatch
7+
final class SequenceMatch extends BaseMatch
108
{
119
public const MAX_DELTA = 5;
1210

@@ -87,7 +85,9 @@ public static function findSequenceMatch(string $password, int $begin, int $end,
8785
}
8886
}
8987

90-
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
88+
/**
89+
* @return array{'warning': string, "suggestions": string[]}
90+
*/
9191
public function getFeedback(bool $isSoleMatch): array
9292
{
9393
return [

0 commit comments

Comments
 (0)