Skip to content

Commit 0556c5c

Browse files
committed
✨ v4
1 parent 58b838d commit 0556c5c

14 files changed

+48
-93
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222
fail-fast: true
2323
matrix:
2424
php-version:
25-
- "7.2"
26-
- "7.3"
2725
- "7.4"
2826
- "8.0"
2927
- "8.1"
@@ -65,8 +63,6 @@ jobs:
6563
- ubuntu-latest
6664
- windows-latest
6765
php-version:
68-
- "7.2"
69-
- "7.3"
7066
- "7.4"
7167
- "8.0"
7268
- "8.1"
@@ -81,7 +77,7 @@ jobs:
8177
uses: shivammathur/setup-php@v2
8278
with:
8379
php-version: ${{ matrix.php-version }}
84-
coverage: xdebug
80+
coverage: pcov
8581
extensions: curl, gmp, json, sodium
8682

8783
- name: "Install dependencies with composer"

.phan/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// that functions removed in php 7.0 exist.
1616
// (See `backward_compatibility_checks` for additional options)
1717
'target_php_version' => null,
18-
'minimum_target_php_version' => '7.2',
18+
'minimum_target_php_version' => '7.4',
1919

2020
// A list of directories that should be parsed for class and
2121
// method information. After excluding the directories

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A generator for counter based ([RFC 4226](https://tools.ietf.org/html/rfc4226))
1818

1919
# Documentation
2020
## Requirements
21-
- PHP 7.2+
21+
- PHP 7.4+
2222
- [`ext-curl`](https://www.php.net/manual/book.curl) for Battle.net and Steam Guard server time synchronization
2323
- [`ext-gmp`](https://www.php.net/manual/book.gmp) for Battle.net authenticator secret retrieval (RSA encryption)
2424
- [`ext-sodium`](https://www.php.net/manual/book.sodium) for constant time implementations of base64 encode/decode and hex2bin/bin2hex
@@ -29,11 +29,11 @@ A generator for counter based ([RFC 4226](https://tools.ietf.org/html/rfc4226))
2929

3030
via terminal: `composer require chillerlan/php-authenticator`
3131

32-
*composer.json* (note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^3.1` - see [releases](https://github.com/chillerlan/php-authenticator/releases) for valid versions)
32+
*composer.json* (note: replace `dev-main` with a [version constraint](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints), e.g. `^4.1` - see [releases](https://github.com/chillerlan/php-authenticator/releases) for valid versions)
3333
```json
3434
{
3535
"require": {
36-
"php": "^7.2 || ^8.0",
36+
"php": "^7.4 || ^8.0",
3737
"chillerlan/php-authenticator": "dev-main"
3838
}
3939
}

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chillerlan/php-authenticator",
3-
"description": "A generator for counter- and time based 2-factor authentication codes (Google Authenticator). PHP 7.2+",
3+
"description": "A generator for counter- and time based 2-factor authentication codes (Google Authenticator). PHP 7.4+",
44
"homepage": "https://github.com/chillerlan/php-authenticator",
55
"license": "MIT",
66
"type": "library",
@@ -21,8 +21,8 @@
2121
"minimum-stability": "stable",
2222
"prefer-stable": true,
2323
"require": {
24-
"php": "^7.2 || ^8.0",
25-
"chillerlan/php-settings-container": "^1.2.2 || ^2.1.4 || ^3.0",
24+
"php": "^7.4 || ^8.0",
25+
"chillerlan/php-settings-container": "^2.1.4 || ^3.0",
2626
"paragonie/constant_time_encoding": "^2.6"
2727
},
2828
"require-dev": {
@@ -32,7 +32,7 @@
3232
"ext-sodium": "*",
3333
"phan/phan": "^5.4",
3434
"phpmd/phpmd": "^2.13",
35-
"phpunit/phpunit": "^8.5 || ^9.6",
35+
"phpunit/phpunit": "^9.6",
3636
"squizlabs/php_codesniffer": "^3.7"
3737
},
3838
"suggest": {
@@ -50,7 +50,7 @@
5050
},
5151
"scripts": {
5252
"phpunit": "@php vendor/bin/phpunit",
53-
"phan": "@php vendor/bin/phan --allow-polyfill-parser"
53+
"phan": "@php vendor/bin/phan"
5454
},
5555
"config": {
5656
"lock": false,

phpunit.xml.dist

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
cacheResultFile=".build/phpunit.result.cache"
66
colors="true"
@@ -11,12 +11,13 @@
1111
<directory suffix=".php">./tests</directory>
1212
</testsuite>
1313
</testsuites>
14-
<filter>
15-
<whitelist processUncoveredFilesFromWhitelist="true">
14+
<coverage processUncoveredFiles="true">
15+
<include>
1616
<directory suffix=".php">./src</directory>
17-
</whitelist>
18-
</filter>
19-
<logging>
20-
<log type="coverage-clover" target=".build/coverage/clover.xml"/>
21-
</logging>
17+
</include>
18+
<report>
19+
<clover outputFile=".build/coverage/clover.xml"/>
20+
<xml outputDirectory=".build/coverage/coverage-xml"/>
21+
</report>
22+
</coverage>
2223
</phpunit>

src/Authenticator.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@
3030
*/
3131
class Authenticator{
3232

33-
/** @var \chillerlan\Authenticator\Authenticators\AuthenticatorInterface */
34-
protected $authenticator;
35-
3633
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\Authenticator\AuthenticatorOptions */
37-
protected $options;
38-
39-
/** @var string */
40-
protected $mode = AuthenticatorInterface::TOTP;
34+
protected SettingsContainerInterface $options;
35+
protected AuthenticatorInterface $authenticator;
36+
protected string $mode = AuthenticatorInterface::TOTP;
4137

4238
/**
4339
* Authenticator constructor

src/AuthenticatorOptionsTrait.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,82 +20,64 @@ trait AuthenticatorOptionsTrait{
2020

2121
/**
2222
* Code length: either 6 or 8
23-
*
24-
* @var int
2523
*/
26-
protected $digits = 6;
24+
protected int $digits = 6;
2725

2826
/**
2927
* Validation period (seconds): 15 - 60
30-
*
31-
* @var int
3228
*/
33-
protected $period = 30;
29+
protected int $period = 30;
3430

3531
/**
3632
* Length of the secret phrase (bytes, unencoded binary)
3733
*
3834
* @see \random_bytes()
39-
*
40-
* @var int
4135
*/
42-
protected $secret_length = 20;
36+
protected int $secret_length = 20;
4337

4438
/**
4539
* Hash algorithm:
4640
*
4741
* - `AuthenticatorInterface::ALGO_SHA1`
4842
* - `AuthenticatorInterface::ALGO_SHA256`
4943
* - `AuthenticatorInterface::ALGO_SHA512`
50-
*
51-
* @var string
5244
*/
53-
protected $algorithm = AuthenticatorInterface::ALGO_SHA1;
45+
protected string $algorithm = AuthenticatorInterface::ALGO_SHA1;
5446

5547
/**
5648
* Authenticator mode:
5749
*
5850
* - `AuthenticatorInterface::HOTP` = counter based
5951
* - `AuthenticatorInterface::TOTP` = time based
6052
* - `AuthenticatorInterface::STEAM` = time based (Steam Guard)
61-
*
62-
* @var string
6353
*/
64-
protected $mode = AuthenticatorInterface::TOTP;
54+
protected string $mode = AuthenticatorInterface::TOTP;
6555

6656
/**
6757
* Number of allowed adjacent codes
68-
*
69-
* @var int
7058
*/
71-
protected $adjacent = 1;
59+
protected int $adjacent = 1;
7260

7361
/**
7462
* A fixed time offset that will be added to the current time value
7563
*
7664
* @see \chillerlan\Authenticator\Authenticators\AuthenticatorInterface::getCounter()
77-
*
78-
* @var int
7965
*/
80-
protected $time_offset = 0;
66+
protected int $time_offset = 0;
8167

8268
/**
8369
* Whether to use local time or request server time from the API
8470
*
8571
* This can be useful when the device time sync is unreliable.
8672
*
8773
* note: API requests needs ext-curl installed
88-
*
89-
* @var bool
9074
*/
91-
protected $useLocalTime = true;
75+
protected bool $useLocalTime = true;
9276

9377
/**
9478
* Whether to force refreshing server time on each call or use the time returned from the last request
95-
*
96-
* @var bool
9779
*/
98-
protected $forceTimeRefresh = false;
80+
protected bool $forceTimeRefresh = false;
9981

10082
/**
10183
* Sets the code length to either 6 or 8

src/Authenticators/AuthenticatorAbstract.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ abstract class AuthenticatorAbstract implements AuthenticatorInterface{
2727
protected const userAgent = 'chillerlanAuthenticator/5.0 +https://github.com/chillerlan/php-authenticator';
2828

2929
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\Authenticator\AuthenticatorOptions */
30-
protected $options;
31-
32-
/** @var string|null */
33-
protected $secret = null;
34-
35-
/** @var int */
36-
protected $serverTime = 0;
37-
38-
/** @var int */
39-
protected $lastRequestTime = 0;
30+
protected SettingsContainerInterface $options;
31+
protected ?string $secret = null;
32+
protected int $serverTime = 0;
33+
protected int $lastRequestTime = 0;
4034

4135
/**
4236
* AuthenticatorInterface constructor
@@ -80,10 +74,7 @@ public function getSecret():string{
8074
* @inheritDoc
8175
*/
8276
public function createSecret(int $length = null):string{
83-
84-
if($length === null){
85-
$length = $this->options->secret_length;
86-
}
77+
$length ??= $this->options->secret_length;
8778

8879
if($length < 16){
8980
throw new InvalidArgumentException('Invalid secret length: '.$length);

src/Authenticators/BattleNet.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ final class BattleNet extends TOTP{
101101
# '19a250fa4cc1278d12855b5b25818d162c6e6ee2ab4a350d401d78f6ddb99711'.
102102
# 'e72626b48bd8b5b0b7f3acf9ea3c9e0005fee59e19136cdb7c83f2ab8b0a2a99';
103103

104-
/** @var array */
105-
private $curlInfo = [];
104+
private array $curlInfo = [];
106105

107106
/**
108107
* @inheritDoc

src/Authenticators/TOTP.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ class TOTP extends HOTP{
2323
* @inheritDoc
2424
*/
2525
public function getCounter(int $data = null):int{
26-
27-
if($data === null){
28-
$data = time();
29-
}
26+
$data ??= time();
3027

3128
if($this->options->useLocalTime === false){
3229
$data = $this->getServerTime();

0 commit comments

Comments
 (0)