Skip to content

Commit

Permalink
Add some more types
Browse files Browse the repository at this point in the history
  • Loading branch information
j3j5 committed Apr 17, 2024
1 parent 1755926 commit fd53419
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/HmacBcryptHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ class HmacBcryptHasher extends AbstractHasher implements HasherContract
*
* @var bool
*/
protected $verifyAlgorithm = false;
protected bool $verifyAlgorithm = false;

/**
* The default cost factor.
*
* @var int
*/
protected $rounds = 13;
protected int $rounds = 13;

/**
* The pepper to be applied on the hmac steps
* @var string
*/
protected $pepper;
protected string $pepper;

/**
* Create a new hasher instance.
Expand All @@ -59,7 +59,7 @@ public function __construct(array $options = [])
$this->rounds = $options['rounds'] ?? $this->rounds;

$this->pepper = $options['pepper'] ?? '';
if ($this->pepper === '' || !is_string($this->pepper)) {
if ($this->pepper === '') {
throw new RuntimeException("HMAC-Bcrypt can't work without pepper and is currently empty.");
}
}
Expand All @@ -70,7 +70,7 @@ public function __construct(array $options = [])
* @param string $hashedValue
* @return array{algo:null|int|string, algoName:string, options:array{cost?:int, salt?: string, memory_cost?: int, time_cost?: int, threads?: int}}
*/
public function info($hashedValue)
public function info($hashedValue) : array
{
// Try first the parent
/** @var array{algo:null|int|string, algoName:string, options:array{cost?:int, salt?: string, memory_cost?: int, time_cost?: int, threads?: int}} $info */
Expand Down Expand Up @@ -124,7 +124,7 @@ public function info($hashedValue)
* @return string
*
*/
public function make($value, array $options = [])
public function make($value, array $options = []) : string
{
// Make sure no salt is passed ever on make()
// Ignore phpstan error so it's not documented that salt could be passed
Expand All @@ -142,7 +142,7 @@ public function make($value, array $options = [])
* @return string
*
*/
private function hash($value, array $options = [])
private function hash($value, array $options = []) : string
{
$settings = sprintf(
'$%2s$%02d$%s',
Expand Down Expand Up @@ -194,7 +194,7 @@ private function hash($value, array $options = [])
* @return bool
*
*/
public function check($value, $hashedValue, array $options = [])
public function check($value, $hashedValue, array $options = []) : bool
{
$algoName = $this->info($hashedValue)['algoName'];
if ($algoName !== self::ALGO_NAME) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public function check($value, $hashedValue, array $options = [])
* @param array{rounds?: int, salt?: string, pepper?: string} $options $options
* @return bool
*/
public function needsRehash($hashedValue, array $options = [])
public function needsRehash($hashedValue, array $options = []) : bool
{
$info = $this->info($hashedValue);

Expand Down

0 comments on commit fd53419

Please sign in to comment.