Skip to content

Commit

Permalink
Fix phpstan error for new static without preventing subclassing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkopinsky committed Nov 21, 2024
1 parent 6851e13 commit 2761732
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 20 deletions.
7 changes: 0 additions & 7 deletions phpstan-baseline.neon

This file was deleted.

3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- phpstan-baseline.neon

parameters:
level: 0
paths:
Expand Down
6 changes: 0 additions & 6 deletions src/Matchers/Bruteforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

use ZxcvbnPhp\Scorer;

/**
* Class Bruteforce
* @package ZxcvbnPhp\Matchers
*
* Intentionally not named with Match suffix to prevent autoloading from Matcher.
*/
final class Bruteforce extends BaseMatch
{
public const BRUTEFORCE_CARDINALITY = 10;
Expand Down
3 changes: 2 additions & 1 deletion src/Matchers/DateMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use ZxcvbnPhp\Matcher;

final class DateMatch extends BaseMatch
/** @phpstan-consistent-constructor */
class DateMatch extends BaseMatch
{
public const NUM_YEARS = 119; // Years match against 1900 - 2019
public const NUM_MONTHS = 12;
Expand Down
1 change: 1 addition & 0 deletions src/Matchers/DictionaryMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Math\Binomial;

/** @phpstan-consistent-constructor */
class DictionaryMatch extends BaseMatch
{
public $pattern = 'dictionary';
Expand Down
3 changes: 2 additions & 1 deletion src/Matchers/RepeatMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Scorer;

final class RepeatMatch extends BaseMatch
/** @phpstan-consistent-constructor */
class RepeatMatch extends BaseMatch
{
public const GREEDY_MATCH = '/(.+)\1+/u';
public const LAZY_MATCH = '/(.+?)\1+/u';
Expand Down
3 changes: 2 additions & 1 deletion src/Matchers/SequenceMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace ZxcvbnPhp\Matchers;

final class SequenceMatch extends BaseMatch
/** @phpstan-consistent-constructor */
class SequenceMatch extends BaseMatch
{
public const MAX_DELTA = 5;

Expand Down
3 changes: 2 additions & 1 deletion src/Matchers/SpatialMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Math\Binomial;

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

Expand Down

0 comments on commit 2761732

Please sign in to comment.