Skip to content

Commit

Permalink
:octocat: mark nullable types explicitly (PHP 8.4 deprecation)
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jul 17, 2024
1 parent f76a90b commit 3ba7987
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Authenticator{
/**
* Authenticator constructor
*/
public function __construct(SettingsContainerInterface $options = null, string $secret = null){
public function __construct(?SettingsContainerInterface $options = null, ?string $secret = null){
// phpcs:ignore
$this->setOptions($options ?? new AuthenticatorOptions);

Expand Down Expand Up @@ -95,7 +95,7 @@ public function getSecret():string{
*
* @codeCoverageIgnore
*/
public function createSecret(int $length = null):string{
public function createSecret(?int $length = null):string{
return $this->authenticator->createSecret($length);
}

Expand All @@ -108,7 +108,7 @@ public function createSecret(int $length = null):string{
*
* @codeCoverageIgnore
*/
public function code(int $data = null):string{
public function code(?int $data = null):string{
return $this->authenticator->code($data);
}

Expand All @@ -121,7 +121,7 @@ public function code(int $data = null):string{
*
* @codeCoverageIgnore
*/
public function verify(string $otp, int $data = null):bool{
public function verify(string $otp, ?int $data = null):bool{
return $this->authenticator->verify($otp, $data);
}

Expand All @@ -132,7 +132,7 @@ public function verify(string $otp, int $data = null):bool{
*
* @throws \InvalidArgumentException
*/
public function getUri(string $label, string $issuer, int $hotpCounter = null, bool $omitSettings = null):string{
public function getUri(string $label, string $issuer, ?int $hotpCounter = null, ?bool $omitSettings = null):string{
$label = trim($label);
$issuer = trim($issuer);

Expand Down
4 changes: 2 additions & 2 deletions src/Authenticators/AuthenticatorAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AuthenticatorAbstract implements AuthenticatorInterface{
/**
* AuthenticatorInterface constructor
*/
public function __construct(SettingsContainerInterface $options = null){
public function __construct(?SettingsContainerInterface $options = null){
// phpcs:ignore
$this->setOptions($options ?? new AuthenticatorOptions);
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getSecret():string{
/**
* @inheritDoc
*/
public function createSecret(int $length = null):string{
public function createSecret(?int $length = null):string{
$length ??= $this->options->secret_length;

if($length < 16){
Expand Down
8 changes: 4 additions & 4 deletions src/Authenticators/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getSecret():string;
*
* @throws \InvalidArgumentException
*/
public function createSecret(int $length = null):string;
public function createSecret(?int $length = null):string;

/**
* Returns the current server time as UNIX timestamp for the given application (or `time()` if not applicable)
Expand All @@ -74,7 +74,7 @@ public function getServertime():int;
*
* @internal
*/
public function getCounter(int $data = null):int;
public function getCounter(?int $data = null):int;

/**
* HMAC hashes the given $data integer with the given secret
Expand Down Expand Up @@ -104,7 +104,7 @@ public function getOTP(int $code):string;
* - a UNIX timestamp (TOTP)
* - a counter value (HOTP)
*/
public function code(int $data = null):string;
public function code(?int $data = null):string;

/**
* Checks the given $code against the secret
Expand All @@ -113,6 +113,6 @@ public function code(int $data = null):string;
* - a UNIX timestamp (TOTP)
* - a counter value (HOTP)
*/
public function verify(string $otp, int $data = null):bool;
public function verify(string $otp, ?int $data = null):bool;

}
6 changes: 3 additions & 3 deletions src/Authenticators/HOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HOTP extends AuthenticatorAbstract{
/**
* @inheritDoc
*/
public function getCounter(int $data = null):int{
public function getCounter(?int $data = null):int{
return ($data ?? 0);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public function getOTP(int $code):string{
/**
* @inheritDoc
*/
public function code(int $data = null):string{
public function code(?int $data = null):string{
$hmac = $this->getHMAC($this->getCounter($data));

return $this->getOTP($this->getCode($hmac));
Expand All @@ -85,7 +85,7 @@ public function code(int $data = null):string{
/**
* @inheritDoc
*/
public function verify(string $otp, int $data = null):bool{
public function verify(string $otp, ?int $data = null):bool{
return hash_equals($this->code($data), $otp);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Authenticators/SteamGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public function getSecret():string{
* @inheritDoc
* @codeCoverageIgnore
*/
public function createSecret(int $length = null):string{
public function createSecret(?int $length = null):string{
throw new RuntimeException('Not implemented');
}

/**
* @inheritDoc
*/
public function getCounter(int $data = null):int{
public function getCounter(?int $data = null):int{
// the period is fixed to 30 seconds for Steam Guard
$this->options->period = 30;

Expand Down
4 changes: 2 additions & 2 deletions src/Authenticators/TOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TOTP extends HOTP{
/**
* @inheritDoc
*/
public function getCounter(int $data = null):int{
public function getCounter(?int $data = null):int{
$data ??= time();

if($this->options->useLocalTime === false){
Expand All @@ -36,7 +36,7 @@ public function getCounter(int $data = null):int{
/**
* @inheritDoc
*/
public function verify(string $otp, int $data = null):bool{
public function verify(string $otp, ?int $data = null):bool{
$limit = $this->options->adjacent;

if($limit === 0){
Expand Down
2 changes: 1 addition & 1 deletion tests/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp():void{
}

public function testSetSecretViaConstruct():void{
$this->authenticator = new Authenticator(null, self::secret);
$this->authenticator = new Authenticator($this->options, self::secret);

$this::assertSame(self::secret, $this->authenticator->getSecret());
}
Expand Down

0 comments on commit 3ba7987

Please sign in to comment.