Skip to content

Commit 3ba7987

Browse files
committed
:octocat: mark nullable types explicitly (PHP 8.4 deprecation)
1 parent f76a90b commit 3ba7987

7 files changed

+19
-19
lines changed

src/Authenticator.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Authenticator{
3939
/**
4040
* Authenticator constructor
4141
*/
42-
public function __construct(SettingsContainerInterface $options = null, string $secret = null){
42+
public function __construct(?SettingsContainerInterface $options = null, ?string $secret = null){
4343
// phpcs:ignore
4444
$this->setOptions($options ?? new AuthenticatorOptions);
4545

@@ -95,7 +95,7 @@ public function getSecret():string{
9595
*
9696
* @codeCoverageIgnore
9797
*/
98-
public function createSecret(int $length = null):string{
98+
public function createSecret(?int $length = null):string{
9999
return $this->authenticator->createSecret($length);
100100
}
101101

@@ -108,7 +108,7 @@ public function createSecret(int $length = null):string{
108108
*
109109
* @codeCoverageIgnore
110110
*/
111-
public function code(int $data = null):string{
111+
public function code(?int $data = null):string{
112112
return $this->authenticator->code($data);
113113
}
114114

@@ -121,7 +121,7 @@ public function code(int $data = null):string{
121121
*
122122
* @codeCoverageIgnore
123123
*/
124-
public function verify(string $otp, int $data = null):bool{
124+
public function verify(string $otp, ?int $data = null):bool{
125125
return $this->authenticator->verify($otp, $data);
126126
}
127127

@@ -132,7 +132,7 @@ public function verify(string $otp, int $data = null):bool{
132132
*
133133
* @throws \InvalidArgumentException
134134
*/
135-
public function getUri(string $label, string $issuer, int $hotpCounter = null, bool $omitSettings = null):string{
135+
public function getUri(string $label, string $issuer, ?int $hotpCounter = null, ?bool $omitSettings = null):string{
136136
$label = trim($label);
137137
$issuer = trim($issuer);
138138

src/Authenticators/AuthenticatorAbstract.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class AuthenticatorAbstract implements AuthenticatorInterface{
3636
/**
3737
* AuthenticatorInterface constructor
3838
*/
39-
public function __construct(SettingsContainerInterface $options = null){
39+
public function __construct(?SettingsContainerInterface $options = null){
4040
// phpcs:ignore
4141
$this->setOptions($options ?? new AuthenticatorOptions);
4242
}
@@ -74,7 +74,7 @@ public function getSecret():string{
7474
/**
7575
* @inheritDoc
7676
*/
77-
public function createSecret(int $length = null):string{
77+
public function createSecret(?int $length = null):string{
7878
$length ??= $this->options->secret_length;
7979

8080
if($length < 16){

src/Authenticators/AuthenticatorInterface.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getSecret():string;
6262
*
6363
* @throws \InvalidArgumentException
6464
*/
65-
public function createSecret(int $length = null):string;
65+
public function createSecret(?int $length = null):string;
6666

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

7979
/**
8080
* HMAC hashes the given $data integer with the given secret
@@ -104,7 +104,7 @@ public function getOTP(int $code):string;
104104
* - a UNIX timestamp (TOTP)
105105
* - a counter value (HOTP)
106106
*/
107-
public function code(int $data = null):string;
107+
public function code(?int $data = null):string;
108108

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

118118
}

src/Authenticators/HOTP.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class HOTP extends AuthenticatorAbstract{
2929
/**
3030
* @inheritDoc
3131
*/
32-
public function getCounter(int $data = null):int{
32+
public function getCounter(?int $data = null):int{
3333
return ($data ?? 0);
3434
}
3535

@@ -76,7 +76,7 @@ public function getOTP(int $code):string{
7676
/**
7777
* @inheritDoc
7878
*/
79-
public function code(int $data = null):string{
79+
public function code(?int $data = null):string{
8080
$hmac = $this->getHMAC($this->getCounter($data));
8181

8282
return $this->getOTP($this->getCode($hmac));
@@ -85,7 +85,7 @@ public function code(int $data = null):string{
8585
/**
8686
* @inheritDoc
8787
*/
88-
public function verify(string $otp, int $data = null):bool{
88+
public function verify(string $otp, ?int $data = null):bool{
8989
return hash_equals($this->code($data), $otp);
9090
}
9191

src/Authenticators/SteamGuard.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public function getSecret():string{
6767
* @inheritDoc
6868
* @codeCoverageIgnore
6969
*/
70-
public function createSecret(int $length = null):string{
70+
public function createSecret(?int $length = null):string{
7171
throw new RuntimeException('Not implemented');
7272
}
7373

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

src/Authenticators/TOTP.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TOTP extends HOTP{
2323
/**
2424
* @inheritDoc
2525
*/
26-
public function getCounter(int $data = null):int{
26+
public function getCounter(?int $data = null):int{
2727
$data ??= time();
2828

2929
if($this->options->useLocalTime === false){
@@ -36,7 +36,7 @@ public function getCounter(int $data = null):int{
3636
/**
3737
* @inheritDoc
3838
*/
39-
public function verify(string $otp, int $data = null):bool{
39+
public function verify(string $otp, ?int $data = null):bool{
4040
$limit = $this->options->adjacent;
4141

4242
if($limit === 0){

tests/AuthenticatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp():void{
3232
}
3333

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

3737
$this::assertSame(self::secret, $this->authenticator->getSecret());
3838
}

0 commit comments

Comments
 (0)