Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
fix: add typehints to UndisclosedPassword
Browse files Browse the repository at this point in the history
On all internal methods.
  • Loading branch information
weierophinney committed Dec 28, 2019
1 parent 89a6646 commit 46393e9
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/UndisclosedPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ final class UndisclosedPassword extends AbstractValidator

/**
* PasswordBreach constructor.
*
* @param ClientInterface $httpClient
* @param RequestFactoryInterface $makeHttpRequest
* @param ResponseFactoryInterface $makeHttpResponse
*/
public function __construct(
ClientInterface $httpClient,
Expand Down Expand Up @@ -80,7 +76,7 @@ public function isValid($value)
return true;
}

private function isPwnedPassword($password)
private function isPwnedPassword(string $password) : bool
{
$sha1Hash = $this->hashPassword($password);
$rangeHash = $this->getRangeHash($sha1Hash);
Expand All @@ -95,7 +91,7 @@ private function isPwnedPassword($password)
* @param string $password
* @return string
*/
private function hashPassword($password)
private function hashPassword(string $password) : string
{
$hashedPassword = \sha1($password);
return strtoupper($hashedPassword);
Expand All @@ -109,7 +105,7 @@ private function hashPassword($password)
* @return string
* @see https://www.troyhunt.com/enhancing-pwned-passwords-privacy-by-exclusively-supporting-anonymity/
*/
private function getRangeHash($passwordHash)
private function getRangeHash(string $passwordHash) : string
{
return substr($passwordHash, self::HIBP_K_ANONYMITY_HASH_RANGE_BASE, self::HIBP_K_ANONYMITY_HASH_RANGE_LENGTH);
}
Expand All @@ -123,7 +119,7 @@ private function getRangeHash($passwordHash)
* @return string
* @throws ClientExceptionInterface
*/
private function retrieveHashList($passwordRange)
private function retrieveHashList(string $passwordRange) : string
{
$request = $this->makeHttpRequest->createRequest(
'GET',
Expand All @@ -141,7 +137,7 @@ private function retrieveHashList($passwordRange)
* @param string $resultStream
* @return bool
*/
private function hashInResponse($sha1Hash, $resultStream)
private function hashInResponse(string $sha1Hash, string $resultStream) : bool
{
$data = explode("\r\n", $resultStream);
$hashes = array_filter($data, function ($value) use ($sha1Hash) {
Expand Down

0 comments on commit 46393e9

Please sign in to comment.