Skip to content

Commit 2761732

Browse files
committed
Fix phpstan error for new static without preventing subclassing
https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static#add-%40phpstan-consistent-constructor-to-the-class For some reason the annotation isn't working for `Bruteforce` and `YearMatch` so I left those classes as final, at least for now
1 parent 6851e13 commit 2761732

File tree

8 files changed

+9
-20
lines changed

8 files changed

+9
-20
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 7 deletions
This file was deleted.

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
52
level: 0
63
paths:

src/Matchers/Bruteforce.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
use ZxcvbnPhp\Scorer;
88

9-
/**
10-
* Class Bruteforce
11-
* @package ZxcvbnPhp\Matchers
12-
*
13-
* Intentionally not named with Match suffix to prevent autoloading from Matcher.
14-
*/
159
final class Bruteforce extends BaseMatch
1610
{
1711
public const BRUTEFORCE_CARDINALITY = 10;

src/Matchers/DateMatch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
use ZxcvbnPhp\Matcher;
88

9-
final class DateMatch extends BaseMatch
9+
/** @phpstan-consistent-constructor */
10+
class DateMatch extends BaseMatch
1011
{
1112
public const NUM_YEARS = 119; // Years match against 1900 - 2019
1213
public const NUM_MONTHS = 12;

src/Matchers/DictionaryMatch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ZxcvbnPhp\Matcher;
88
use ZxcvbnPhp\Math\Binomial;
99

10+
/** @phpstan-consistent-constructor */
1011
class DictionaryMatch extends BaseMatch
1112
{
1213
public $pattern = 'dictionary';

src/Matchers/RepeatMatch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use ZxcvbnPhp\Matcher;
88
use ZxcvbnPhp\Scorer;
99

10-
final class RepeatMatch extends BaseMatch
10+
/** @phpstan-consistent-constructor */
11+
class RepeatMatch extends BaseMatch
1112
{
1213
public const GREEDY_MATCH = '/(.+)\1+/u';
1314
public const LAZY_MATCH = '/(.+?)\1+/u';

src/Matchers/SequenceMatch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace ZxcvbnPhp\Matchers;
66

7-
final class SequenceMatch extends BaseMatch
7+
/** @phpstan-consistent-constructor */
8+
class SequenceMatch extends BaseMatch
89
{
910
public const MAX_DELTA = 5;
1011

src/Matchers/SpatialMatch.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use ZxcvbnPhp\Matcher;
88
use ZxcvbnPhp\Math\Binomial;
99

10-
final class SpatialMatch extends BaseMatch
10+
/** @phpstan-consistent-constructor */
11+
class SpatialMatch extends BaseMatch
1112
{
1213
public const SHIFTED_CHARACTERS = '~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?';
1314

0 commit comments

Comments
 (0)