Skip to content

Commit 00e1b26

Browse files
committed
getGuesses is documented to return an int, which requires updating getRawGuesses and a few tests
1 parent ace3c64 commit 00e1b26

File tree

13 files changed

+23
-34
lines changed

13 files changed

+23
-34
lines changed

src/Matchers/BaseMatch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ public static function binom(int $n, int $k): int
139139
return $res;
140140
}
141141

142-
abstract protected function getRawGuesses(): float;
142+
abstract protected function getRawGuesses(): int;
143143

144-
public function getGuesses(): float
144+
public function getGuesses(): int
145145
{
146146
return max($this->getRawGuesses(), $this->getMinimumGuesses());
147147
}

src/Matchers/Bruteforce.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public function getFeedback(bool $isSoleMatch): array
3939
];
4040
}
4141

42-
public function getRawGuesses(): float
42+
public function getRawGuesses(): int
4343
{
4444
$guesses = pow(self::BRUTEFORCE_CARDINALITY, mb_strlen($this->token));
4545
if ($guesses === INF) {
46-
return defined('PHP_FLOAT_MAX') ? PHP_FLOAT_MAX : 1e308;
46+
// use 32bit max int if for some reason PHP_INT_MAX isn't defined
47+
return defined('PHP_INT_MAX') ? PHP_INT_MAX : 2147483647;
4748
}
4849

4950
// small detail: make bruteforce matches at minimum one guess bigger than smallest allowed
@@ -54,6 +55,6 @@ public function getRawGuesses(): float
5455
$minGuesses = Scorer::MIN_SUBMATCH_GUESSES_MULTI_CHAR + 1;
5556
}
5657

57-
return max($guesses, $minGuesses);
58+
return (int)max($guesses, $minGuesses);
5859
}
5960
}

src/Matchers/DateMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ protected static function removeRedundantMatches(array $matches): array
408408
});
409409
}
410410

411-
protected function getRawGuesses(): float
411+
protected function getRawGuesses(): int
412412
{
413413
// base guesses: (year distance from REFERENCE_YEAR) * num_days * num_years
414414
$yearSpace = max(abs($this->year - static::getReferenceYear()), static::MIN_YEAR_SPACE);

src/Matchers/DictionaryMatch.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ protected static function getRankedDictionaries(): array
191191
return self::$rankedDictionaries;
192192
}
193193

194-
/**
195-
* @return integer
196-
*/
197-
protected function getRawGuesses(): float
194+
protected function getRawGuesses(): int
198195
{
199196
$guesses = $this->rank;
200197
$guesses *= $this->getUppercaseVariations();

src/Matchers/L33tMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected static function substitutionTableHelper(array $table, array $keys, arr
202202
return self::substitutionTableHelper($table, $otherKeys, $nextSubs);
203203
}
204204

205-
protected function getRawGuesses(): float
205+
protected function getRawGuesses(): int
206206
{
207207
return parent::getRawGuesses() * $this->getL33tVariations();
208208
}

src/Matchers/MatchInterface.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ interface MatchInterface
1616
*/
1717
public static function match(string $password, array $userInputs = []): array;
1818

19-
/**
20-
* @return integer
21-
*/
22-
public function getGuesses(): float;
19+
public function getGuesses(): int;
2320

24-
/**
25-
* @return float
26-
*/
2721
public function getGuessesLog10(): float;
2822
}

src/Matchers/RepeatMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __construct(string $password, int $begin, int $end, string $toke
114114
}
115115
}
116116

117-
protected function getRawGuesses(): float
117+
protected function getRawGuesses(): int
118118
{
119119
return $this->baseGuesses * $this->repeatCount;
120120
}

src/Matchers/ReverseDictionaryMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function match(string $password, array $userInputs = [], array $ra
3434
return $matches;
3535
}
3636

37-
protected function getRawGuesses(): float
37+
protected function getRawGuesses(): int
3838
{
3939
return parent::getRawGuesses() * 2;
4040
}

src/Matchers/SequenceMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function __construct(string $password, int $begin, int $end, string $toke
110110
}
111111
}
112112

113-
protected function getRawGuesses(): float
113+
protected function getRawGuesses(): int
114114
{
115115
$firstCharacter = mb_substr($this->token, 0, 1);
116116
$guesses = 0;

src/Matchers/SpatialMatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static function getAdjacencyGraphs(): array
214214
return self::$adjacencyGraphs;
215215
}
216216

217-
protected function getRawGuesses(): float
217+
protected function getRawGuesses(): int
218218
{
219219
if ($this->graph === 'qwerty' || $this->graph === 'dvorak') {
220220
$startingPosition = self::KEYBOARD_STARTING_POSITION;

0 commit comments

Comments
 (0)