Skip to content

Commit 13b505d

Browse files
authored
Merge pull request #50 from bjeavons/php8
PHP compatibility
2 parents f13e90c + 5de0063 commit 13b505d

18 files changed

+69
-66
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- '7.2'
1616
- '7.3'
1717
- '7.4'
18+
- '8.0'
1819
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1920
steps:
2021
- name: Checkout

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^7.2",
15+
"php": "^7.2 | ^8.0",
1616
"symfony/polyfill-mbstring": ">=1.3.1"
1717
},
1818
"require-dev": {

src/Feedback.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ZxcvbnPhp;
44

5-
use ZxcvbnPhp\Matchers\Match;
5+
use ZxcvbnPhp\Matchers\MatchInterface;
66

77
/**
88
* Feedback - gives some user guidance based on the strength
@@ -14,27 +14,27 @@ class Feedback
1414
{
1515
/**
1616
* @param int $score
17-
* @param Match[] $sequence
17+
* @param MatchInterface[] $sequence
1818
* @return array
1919
*/
2020
public function getFeedback($score, array $sequence)
2121
{
2222
// starting feedback
2323
if (count($sequence) === 0) {
2424
return [
25-
'warning' => '',
25+
'warning' => '',
2626
'suggestions' => [
2727
"Use a few words, avoid common phrases",
28-
"No need for symbols, digits, or uppercase letters"
29-
]
28+
"No need for symbols, digits, or uppercase letters",
29+
],
3030
];
3131
}
3232

3333
// no feedback if score is good or great.
3434
if ($score > 2) {
3535
return [
36-
'warning' => '',
37-
'suggestions' => []
36+
'warning' => '',
37+
'suggestions' => [],
3838
];
3939
}
4040

src/Matcher.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ZxcvbnPhp;
44

5-
use ZxcvbnPhp\Matchers\Match;
5+
use ZxcvbnPhp\Matchers\BaseMatch;
66
use ZxcvbnPhp\Matchers\MatchInterface;
77

88
class Matcher
@@ -23,14 +23,14 @@ class Matcher
2323
/**
2424
* Get matches for a password.
2525
*
26-
* @see zxcvbn/src/matching.coffee::omnimatch
27-
*
28-
* @param string $password Password string to match
29-
* @param array $userInputs Array of values related to the user (optional)
26+
* @param string $password Password string to match
27+
* @param array $userInputs Array of values related to the user (optional)
3028
* @code array('Alice Smith')
3129
* @endcode
3230
*
33-
* @return Match[] Array of Match objects.
31+
* @return MatchInterface[] Array of Match objects.
32+
*
33+
* @see zxcvbn/src/matching.coffee::omnimatch
3434
*/
3535
public function getMatches($password, array $userInputs = [])
3636
{
@@ -77,7 +77,7 @@ public static function usortStable(array &$array, callable $value_compare_func)
7777
{
7878
$index = 0;
7979
foreach ($array as &$item) {
80-
$item = array($index++, $item);
80+
$item = [$index++, $item];
8181
}
8282
$result = usort($array, function ($a, $b) use ($value_compare_func) {
8383
$result = $value_compare_func($a[1], $b[1]);
@@ -89,7 +89,7 @@ public static function usortStable(array &$array, callable $value_compare_func)
8989
return $result;
9090
}
9191

92-
public static function compareMatches(Match $a, Match $b)
92+
public static function compareMatches(BaseMatch $a, BaseMatch $b)
9393
{
9494
$beginDiff = $a->begin - $b->begin;
9595
if ($beginDiff) {

src/Matchers/Match.php renamed to src/Matchers/BaseMatch.php

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

55
use ZxcvbnPhp\Scorer;
66

7-
abstract class Match implements MatchInterface
7+
abstract class BaseMatch implements MatchInterface
88
{
99

1010
/**

src/Matchers/Bruteforce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Intentionally not named with Match suffix to prevent autoloading from Matcher.
1212
*/
13-
class Bruteforce extends Match
13+
class Bruteforce extends BaseMatch
1414
{
1515

1616
public const BRUTEFORCE_CARDINALITY = 10;

src/Matchers/DateMatch.php

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

55
use ZxcvbnPhp\Matcher;
66

7-
class DateMatch extends Match
7+
class DateMatch extends BaseMatch
88
{
99
public const NUM_YEARS = 119; // Years match against 1900 - 2019
1010
public const NUM_MONTHS = 12;

src/Matchers/DictionaryMatch.php

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

55
use ZxcvbnPhp\Matcher;
66

7-
class DictionaryMatch extends Match
7+
class DictionaryMatch extends BaseMatch
88
{
99

1010
public $pattern = 'dictionary';

src/Matchers/RepeatMatch.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use ZxcvbnPhp\Matcher;
66
use ZxcvbnPhp\Scorer;
77

8-
class RepeatMatch extends Match
8+
class RepeatMatch extends BaseMatch
99
{
1010
public const GREEDY_MATCH = '/(.+)\1+/u';
1111
public const LAZY_MATCH = '/(.+?)\1+/u';
1212
public const ANCHORED_LAZY_MATCH = '/^(.+?)\1+$/u';
1313

1414
public $pattern = 'repeat';
1515

16-
/** @var Match[] An array of matches for the repeated section itself. */
16+
/** @var MatchInterface[] An array of matches for the repeated section itself. */
1717
public $baseMatches = [];
1818

1919
/** @var int The number of guesses required for the repeated section itself. */
@@ -70,9 +70,9 @@ public static function match($password, array $userInputs = [])
7070
$match[0]['token'],
7171
[
7272
'repeated_char' => $repeatedChar,
73-
'base_guesses' => $baseGuesses,
74-
'base_matches' => $baseMatches,
75-
'repeat_count' => $repeatCount
73+
'base_guesses' => $baseGuesses,
74+
'base_matches' => $baseMatches,
75+
'repeat_count' => $repeatCount,
7676
]
7777
);
7878

@@ -89,10 +89,10 @@ public function getFeedback($isSoleMatch)
8989
: 'Repeats like "abcabcabc" are only slightly harder to guess than "abc"';
9090

9191
return [
92-
'warning' => $warning,
92+
'warning' => $warning,
9393
'suggestions' => [
94-
'Avoid repeated words and characters'
95-
]
94+
'Avoid repeated words and characters',
95+
],
9696
];
9797
}
9898

src/Matchers/SequenceMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ZxcvbnPhp\Matchers;
44

5-
class SequenceMatch extends Match
5+
class SequenceMatch extends BaseMatch
66
{
77
public const MAX_DELTA = 5;
88

0 commit comments

Comments
 (0)