diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f917cea..93d3cc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout diff --git a/src/GoogleAuthenticator.php b/src/GoogleAuthenticator.php index a07df85..4d5752d 100644 --- a/src/GoogleAuthenticator.php +++ b/src/GoogleAuthenticator.php @@ -25,8 +25,6 @@ class GoogleAuthenticator * Create new secret. * 16 characters, randomly chosen from the allowed base32 characters. * - * @param int $secretLength - * @return string * @throws Exception */ public function createSecret(int $secretLength = 16) : string @@ -53,12 +51,9 @@ public function createSecret(int $secretLength = 16) : string /** * Calculate the code, with given secret and point in time * - * @param string $secret - * @param int|null $timeSlice - * @return string * @throws Exception */ - public function getCode(string $secret, int $timeSlice = null) : string + public function getCode(string $secret, ?int $timeSlice = null) : string { if ($timeSlice === null) { $timeSlice = floor(time() / 30); @@ -78,7 +73,7 @@ public function getCode(string $secret, int $timeSlice = null) : string // grab 4 bytes of the result $hashpart = substr($hm, $offset, 4); - // Unpak binary value + // Unpack binary value $value = unpack('N', $hashpart); $value = $value[1]; // Only 32 bits @@ -110,8 +105,6 @@ public function getQRCodeUrl(string $account, string $secret, ?string $issuer = /** * Build an OTP URI using the builder pattern - * - * @return UriBuilder */ public function getUriBuilder(): UriBuilder { @@ -143,10 +136,7 @@ protected function getQRCodeDataUri(string $uri) : string /** * Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now * - * @param string $secret - * @param string $code * @param int $discrepancy This is the allowed time drift in 30 second units (8 means 4 minutes before or after) - * @return bool */ public function verifyCode(string $secret, string $code, int $discrepancy = 1) : bool { @@ -173,9 +163,6 @@ public function verifyCode(string $secret, string $code, int $discrepancy = 1) : /** * Set the code length, should be >=6 - * - * @param int $length - * @return self */ public function setCodeLength(int $length) : self { diff --git a/src/OtpAuth/Base32.php b/src/OtpAuth/Base32.php index fbc9ab7..fcc4d71 100644 --- a/src/OtpAuth/Base32.php +++ b/src/OtpAuth/Base32.php @@ -14,12 +14,8 @@ class Base32 /** * Helper method to encode base32 - * - * @param string $data - * @param $length - * @return string */ - public static function encode(string $data, $length = null): string + public static function encode(string $data, ?int $length = null): string { $length ??= strlen($data); $encoded = ''; @@ -31,14 +27,11 @@ public static function encode(string $data, $length = null): string /** * Helper method to decode base32 - * - * @param string $data - * @return ?string The decoded string, or null on error */ public static function decode(string $data): ?string { if (empty($data)) { - return ''; + return null; } $base32charsFlipped = array_flip(self::CHARS); @@ -77,4 +70,4 @@ public static function decode(string $data): ?string return $binaryString; } -} \ No newline at end of file +} diff --git a/src/OtpAuth/Paramters/Algorithm.php b/src/OtpAuth/Parameters/Algorithm.php similarity index 73% rename from src/OtpAuth/Paramters/Algorithm.php rename to src/OtpAuth/Parameters/Algorithm.php index 5991719..cd092a6 100644 --- a/src/OtpAuth/Paramters/Algorithm.php +++ b/src/OtpAuth/Parameters/Algorithm.php @@ -1,6 +1,6 @@ digits = $digits; return $this; @@ -83,7 +85,7 @@ public function digits(int $digits): self public function counter(int $counter): self { if ($counter < 0) { - throw new \InvalidArgumentException("Counter must be an integer greater than or equal to zero"); + throw new InvalidArgumentException("Counter must be an integer greater than or equal to zero"); } $this->counter = $counter; return $this; @@ -92,7 +94,7 @@ public function counter(int $counter): self public function period(int $period): self { if ($period < 1) { - throw new \InvalidArgumentException("Period must be an integer greater than zero"); + throw new InvalidArgumentException("Period must be an integer greater than zero"); } $this->period = $period; return $this; @@ -101,19 +103,19 @@ public function period(int $period): self public function getUri(): string { if (!isset($this->secret)) { - throw new \DomainException("Secret is required for OTP URIs"); + throw new DomainException("Secret is required for OTP URIs"); } if ($this->type === Type::HOTP && !isset($this->counter)) { - throw new \DomainException("Counter is a required HOTP parameter"); + throw new DomainException("Counter is a required HOTP parameter"); } if ($this->type === Type::TOTP && isset($this->counter)) { - throw new \DomainException("Counter parameter does not apply to TOTP"); + throw new DomainException("Counter parameter does not apply to TOTP"); } if ($this->type === Type::HOTP && isset($this->period)) { - throw new \DomainException("Period parameter does not apply to HOTP"); + throw new DomainException("Period parameter does not apply to HOTP"); } $params = array_filter([ @@ -149,4 +151,4 @@ public function getQRCodeDataUri(): string ->build() ->getDataUri(); } -} \ No newline at end of file +} diff --git a/tests/GoogleAuthenticatorTest.php b/tests/GoogleAuthenticatorTest.php index 2a93516..d8f522f 100644 --- a/tests/GoogleAuthenticatorTest.php +++ b/tests/GoogleAuthenticatorTest.php @@ -5,7 +5,7 @@ use Exception; use PHPUnit\Framework\TestCase; use Vectorface\GoogleAuthenticator; -use Vectorface\OtpAuth\Paramters\Algorithm; +use Vectorface\OtpAuth\Parameters\Algorithm; class GoogleAuthenticatorTest extends TestCase { diff --git a/tests/OtpAuth/UriBuilderTest.php b/tests/OtpAuth/UriBuilderTest.php index f6e79c8..2b6a2fa 100644 --- a/tests/OtpAuth/UriBuilderTest.php +++ b/tests/OtpAuth/UriBuilderTest.php @@ -3,9 +3,9 @@ namespace Tests\Vectorface\OtpAuth; use PHPUnit\Framework\TestCase; -use Vectorface\OtpAuth\Paramters\Type; +use Vectorface\OtpAuth\Parameters\Type; use Vectorface\OtpAuth\UriBuilder; -use Vectorface\OtpAuth\Paramters\Algorithm; +use Vectorface\OtpAuth\Parameters\Algorithm; class UriBuilderTest extends TestCase { @@ -113,4 +113,4 @@ public function invalidArgumentsProvider() "Period must be positive" => ["Period must be an integer greater than zero", 6, 0, 0], ]; } -} \ No newline at end of file +}