Skip to content

Commit 409782a

Browse files
committed
:octocat: added type hints for class constants
1 parent 9194706 commit 409782a

14 files changed

Lines changed: 31 additions & 33 deletions

src/Authenticators/AuthenticatorAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
abstract class AuthenticatorAbstract implements AuthenticatorInterface{
3030

31-
protected const userAgent = 'chillerlanAuthenticator/5.0 +https://github.com/chillerlan/php-authenticator';
31+
protected const string userAgent = 'chillerlanAuthenticator/5.0 +https://github.com/chillerlan/php-authenticator';
3232

3333
protected SettingsContainerInterface|AuthenticatorOptions $options;
3434
protected string|null $secret = null;

src/Authenticators/AuthenticatorInterface.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,30 @@
1616

1717
interface AuthenticatorInterface{
1818

19-
public const TOTP = 'totp';
20-
public const HOTP = 'hotp';
21-
public const STEAM_GUARD = 'steam';
19+
public const string TOTP = 'totp';
20+
public const string HOTP = 'hotp';
21+
public const string STEAM_GUARD = 'steam';
2222

23-
public const ALGO_SHA1 = 'SHA1';
24-
public const ALGO_SHA256 = 'SHA256';
25-
public const ALGO_SHA512 = 'SHA512';
23+
public const string ALGO_SHA1 = 'SHA1';
24+
public const string ALGO_SHA256 = 'SHA256';
25+
public const string ALGO_SHA512 = 'SHA512';
2626

27-
public const MODES = [
27+
public const array MODES = [
2828
self::HOTP => HOTP::class,
2929
self::TOTP => TOTP::class,
3030
self::STEAM_GUARD => SteamGuard::class,
3131
];
3232

33-
public const HASH_ALGOS = [
33+
public const array HASH_ALGOS = [
3434
self::ALGO_SHA1,
3535
self::ALGO_SHA256,
3636
self::ALGO_SHA512,
3737
];
3838

3939
/**
4040
* Mode identifier. Do not call this constant from the interface, but rather from an authenticator instance.
41-
*
42-
* @var string
4341
*/
44-
public const MODE = '';
42+
public const string MODE = '';
4543

4644
/**
4745
* Sets the options

src/Authenticators/HOTP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class HOTP extends AuthenticatorAbstract{
3030

31-
public const MODE = self::HOTP;
31+
public const string MODE = self::HOTP;
3232

3333
public function getCounter(int|null $data = null):int{
3434
return ($data ?? 0);

src/Authenticators/SteamGuard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
*/
4040
final class SteamGuard extends TOTP{
4141

42-
public const MODE = self::STEAM_GUARD;
42+
public const string MODE = self::STEAM_GUARD;
4343

44-
private const steamCodeChars = '23456789BCDFGHJKMNPQRTVWXY';
45-
private const steamTimeURL = 'https://api.steampowered.com/ITwoFactorService/QueryTime/v0001';
44+
private const string steamCodeChars = '23456789BCDFGHJKMNPQRTVWXY';
45+
private const string steamTimeURL = 'https://api.steampowered.com/ITwoFactorService/QueryTime/v0001';
4646

4747
public function setSecret(#[SensitiveParameter] string $encodedSecret):static{
4848
$this->secret = Base64::decode($this->checkEncodedSecret($encodedSecret));

src/Authenticators/TOTP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class TOTP extends HOTP{
2424

25-
public const MODE = self::TOTP;
25+
public const string MODE = self::TOTP;
2626

2727
public function getCounter(int|null $data = null):int{
2828
$data ??= time();

src/Common/Base32.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class Base32 implements EncoderInterface{
2727
* @see https://datatracker.ietf.org/doc/html/rfc3548#section-5
2828
* @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
2929
*/
30-
public const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
30+
public const string CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
3131

3232
/**
3333
* Encode a string to Base32

src/Common/Base64.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Base64 implements EncoderInterface{
2727
* @see https://datatracker.ietf.org/doc/html/rfc3548#section-3
2828
* @see https://datatracker.ietf.org/doc/html/rfc4648#section-4
2929
*/
30-
public const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
30+
public const string CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3131

3232
/**
3333
* Encode a string to Base64

src/Common/EncoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface EncoderInterface{
2323
*
2424
* @var string
2525
*/
26-
public const CHARSET = '';
26+
public const string CHARSET = '';
2727

2828
/**
2929
* Encode a string

src/Common/Hex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class Hex implements EncoderInterface{
2525

26-
public const CHARSET = '1234567890ABCDEFabcdef';
26+
public const string CHARSET = '1234567890ABCDEFabcdef';
2727

2828
/**
2929
* Encode a string to hexadecimal

tests/AuthenticatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
class AuthenticatorTest extends TestCase{
2020

21-
protected const secret = 'SECRETTEST234567';
22-
protected const label = 'some test-label';
23-
protected const issuer = 'chillerlan.net';
21+
protected const string secret = 'SECRETTEST234567';
22+
protected const string label = 'some test-label';
23+
protected const string issuer = 'chillerlan.net';
2424

2525
protected Authenticator $authenticator;
2626
protected AuthenticatorOptions $options;

0 commit comments

Comments
 (0)