Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8.4 to CI and make it compatible #81

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ jobs:
# - windows-latest # Disabled - apparently checkouts have \r\n which breaks phpcs
- macos-latest
php-versions:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
Expand All @@ -39,3 +40,6 @@ jobs:

- name: Unit tests
run: ./vendor/bin/phpunit

- name: PHPStan
run: ./vendor/bin/phpstan analyze
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"require-dev": {
"phpunit/phpunit": "^8.5",
"php-coveralls/php-coveralls": "*",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"phpstan/phpstan": "^2.0"
},
"suggest": {
"ext-gmp": "Required for optimized binomial calculations (also requires PHP >= 7.3)"
Expand Down
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: src/Matchers/DictionaryMatch.php
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 0
paths:
- src
- test
5 changes: 1 addition & 4 deletions src/Matchers/BaseMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Math\Binomial;
use ZxcvbnPhp\Scorer;

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

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Matchers/Bruteforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Scorer;

/**
Expand All @@ -13,7 +12,7 @@
*
* Intentionally not named with Match suffix to prevent autoloading from Matcher.
*/
class Bruteforce extends BaseMatch
final class Bruteforce extends BaseMatch
{
public const BRUTEFORCE_CARDINALITY = 10;

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


#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
return [
Expand Down
7 changes: 4 additions & 3 deletions src/Matchers/DateMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;

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

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
return [
Expand Down
5 changes: 1 addition & 4 deletions src/Matchers/DictionaryMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Math\Binomial;

Expand Down Expand Up @@ -88,10 +87,8 @@ public function __construct(string $password, int $begin, int $end, string $toke
}

/**
* @param bool $isSoleMatch
* @return array
* @return array{'warning': string, "suggestions": string[]}
*/
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
public function getFeedback(bool $isSoleMatch): array
{
$startUpper = '/^[A-Z][^A-Z]+$/u';
Expand Down
5 changes: 3 additions & 2 deletions src/Matchers/L33tMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Math\Binomial;

Expand Down Expand Up @@ -98,7 +97,9 @@ public function __construct(string $password, int $begin, int $end, string $toke
}
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
$feedback = parent::getFeedback($isSoleMatch);
Expand Down
7 changes: 4 additions & 3 deletions src/Matchers/RepeatMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Scorer;

class RepeatMatch extends BaseMatch
final class RepeatMatch extends BaseMatch
{
public const GREEDY_MATCH = '/(.+)\1+/u';
public const LAZY_MATCH = '/(.+?)\1+/u';
Expand Down Expand Up @@ -85,7 +84,9 @@ public static function match(string $password, array $userInputs = []): array
return $matches;
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
$warning = mb_strlen($this->repeatedChar) == 1
Expand Down
7 changes: 4 additions & 3 deletions src/Matchers/ReverseDictionaryMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;

class ReverseDictionaryMatch extends DictionaryMatch
Expand Down Expand Up @@ -42,7 +41,9 @@ protected function getRawGuesses(): float
return parent::getRawGuesses() * 2;
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
$feedback = parent::getFeedback($isSoleMatch);
Expand All @@ -54,7 +55,7 @@ public function getFeedback(bool $isSoleMatch): array
return $feedback;
}

public static function mbStrRev(string $string, string $encoding = null): string
public static function mbStrRev(string $string, ?string $encoding = null): string
{
if ($encoding === null) {
$encoding = mb_detect_encoding($string) ?: 'UTF-8';
Expand Down
8 changes: 4 additions & 4 deletions src/Matchers/SequenceMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;

class SequenceMatch extends BaseMatch
final class SequenceMatch extends BaseMatch
{
public const MAX_DELTA = 5;

Expand Down Expand Up @@ -87,7 +85,9 @@ public static function findSequenceMatch(string $password, int $begin, int $end,
}
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
return [
Expand Down
9 changes: 5 additions & 4 deletions src/Matchers/SpatialMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;
use ZxcvbnPhp\Math\Binomial;

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

Expand Down Expand Up @@ -58,7 +57,9 @@ public static function match(string $password, array $userInputs = [], array $gr
return $matches;
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
$warning = $this->turns == 1
Expand Down Expand Up @@ -93,7 +94,7 @@ public function __construct(string $password, int $begin, int $end, string $toke
/**
* Match spatial patterns in a adjacency graph.
* @param string $password
* @param array $graph
* @param array $graph
* @param string $graphName
* @return array
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Matchers/YearMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace ZxcvbnPhp\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matcher;

class YearMatch extends BaseMatch
final class YearMatch extends BaseMatch
{
public const NUM_YEARS = 119;

Expand All @@ -32,7 +31,10 @@ public static function match(string $password, array $userInputs = []): array
return $matches;
}

#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]

/**
* @return array{'warning': string, "suggestions": string[]}
*/
public function getFeedback(bool $isSoleMatch): array
{
return [
Expand Down
51 changes: 0 additions & 51 deletions test/Matchers/MatchTest.php

This file was deleted.

5 changes: 1 addition & 4 deletions test/Matchers/MockMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace ZxcvbnPhp\Test\Matchers;

use JetBrains\PhpStorm\ArrayShape;
use ZxcvbnPhp\Matchers\BaseMatch;

class MockMatch extends BaseMatch
Expand All @@ -22,10 +21,8 @@ public function __construct(int $begin, int $end, float $guesses)
* Get feedback to a user based on the match.
* @param bool $isSoleMatch
* Whether this is the only match in the password
* @return array
* Associative array with warning (string) and suggestions (array of strings)
* @return array{'warning': string, "suggestions": string[]}
*/
#[ArrayShape(['warning' => 'string', 'suggestions' => 'string[]'])]
public function getFeedback(bool $isSoleMatch): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion test/ZxcvbnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function sanityCheckDataProvider()
['fortitude22', 2, ['dictionary', 'repeat',], '2 minutes', 1140700],
['absoluteadnap', 2, ['dictionary', 'dictionary',], '25 minutes', 15187504],
['knifeandspoon', 3, ['dictionary', 'dictionary', 'dictionary'], '1 day', 1108057600],
['h1dden_26191', 3, ['dictionary', 'bruteforce', 'date'], '3 days', 2730628000],
['h1dden_26191', 3, ['dictionary', 'bruteforce', 'date'], '3 days', 2993690800],
['4rfv1236yhn!', 4, ['spatial', 'sequence', 'bruteforce'], '1 month', 38980000000],
['BVidSNqe3oXVyE1996', 4, ['bruteforce', 'regex',], 'centuries', 10000000000010000],
];
Expand Down
Loading