Skip to content

Commit 27cd1e1

Browse files
authored
Merge pull request #97 from NicolasCARPi/php8
Move to PHP 8.1 minimum version, add typing
2 parents 0159e77 + 30248a8 commit 27cd1e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+552
-856
lines changed

.github/workflows/test-bacon.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
13+
php-version: ['8.1', '8.2']
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717

1818
- uses: shivammathur/setup-php@v2
1919
with:
@@ -22,9 +22,9 @@ jobs:
2222
coverage: xdebug
2323
ini-values: error_reporting=E_ALL
2424

25-
- uses: ramsey/composer-install@v1
25+
- uses: ramsey/composer-install@v2
2626

2727
- run: composer require bacon/bacon-qr-code
2828

29-
- run: composer lint
29+
- run: composer lint-ci
3030
- run: composer test testsDependency/BaconQRCodeTest.php

.github/workflows/test-endroid.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,11 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
php-version: ['8.0', '8.1']
13+
php-version: ['8.1', '8.2']
1414
endroid-version: ["^4"]
15-
include:
16-
- php-version: 5.6
17-
# earliest supported version
18-
endroid-version: 2.2.1
19-
- php-version: 7.0
20-
endroid-version: 2.5.1
21-
- php-version: 7.1
22-
# this version is 7.1+
23-
endroid-version: 3.0.0
24-
- php-version: 7.2
25-
# all later versions are 7.3+
26-
endroid-version: 3.5.9
27-
- php-version: 7.3
28-
endroid-version: 3.9.7
29-
- php-version: 7.4
30-
endroid-version: 4.0.0
3115

3216
steps:
33-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
3418

3519
- uses: shivammathur/setup-php@v2
3620
with:
@@ -39,8 +23,9 @@ jobs:
3923
coverage: xdebug
4024
ini-values: error_reporting=E_ALL
4125

42-
- uses: ramsey/composer-install@v1
26+
- uses: ramsey/composer-install@v2
4327

4428
- run: composer require endroid/qrcode:${{ matrix.endroid-version }}
4529

30+
- run: composer lint-ci
4631
- run: composer test testsDependency/EndroidQRCodeTest.php

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
13+
php-version: ['8.1', '8.2']
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717

1818
- uses: shivammathur/setup-php@v2
1919
with:
@@ -22,7 +22,8 @@ jobs:
2222
coverage: xdebug
2323
ini-values: error_reporting=E_ALL
2424

25-
- uses: ramsey/composer-install@v1
25+
- uses: ramsey/composer-install@v2
2626

27-
- run: composer lint
27+
- run: composer lint-ci
28+
- run: composer phpstan
2829
- run: composer test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ composer.lock
190190
.vs/
191191

192192
.phpunit.result.cache
193+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* PHP-CS-Fixer config for RobThree/TwoFactorAuth
5+
*/
6+
$finder = PhpCsFixer\Finder::create()
7+
->name('/\.php|\.php.dist$/')
8+
->exclude('build')
9+
->exclude('demo')
10+
->exclude('docs')
11+
->in(['lib', 'tests', 'testsDependency'])
12+
;
13+
14+
$config = new PhpCsFixer\Config();
15+
16+
return $config->setRules(array(
17+
'@PSR2' => true,
18+
'@PSR12' => true,
19+
'@PHP82Migration' => true,
20+
'array_syntax' => ['syntax' => 'long'],
21+
'class_attributes_separation' => true,
22+
'declare_strict_types' => true,
23+
'dir_constant' => true,
24+
'is_null' => true,
25+
'no_homoglyph_names' => true,
26+
'no_null_property_initialization' => true,
27+
'no_php4_constructor' => true,
28+
'no_unused_imports' => true,
29+
'no_useless_else' => true,
30+
'non_printable_character' => true,
31+
'ordered_imports' => true,
32+
'ordered_class_elements' => true,
33+
'php_unit_construct' => true,
34+
'pow_to_exponentiation' => true,
35+
'psr_autoloading' => true,
36+
'random_api_migration' => true,
37+
'return_assignment' => true,
38+
'self_accessor' => true,
39+
'semicolon_after_instruction' => true,
40+
'short_scalar_cast' => true,
41+
'simplified_null_return' => true,
42+
'single_blank_line_before_namespace' => true,
43+
'single_class_element_per_statement' => true,
44+
'single_line_comment_style' => true,
45+
'single_quote' => true,
46+
'space_after_semicolon' => true,
47+
'standardize_not_equals' => true,
48+
'strict_param' => true,
49+
'ternary_operator_spaces' => true,
50+
'trailing_comma_in_multiline' => true,
51+
'trim_array_spaces' => true,
52+
'unary_operator_spaces' => true,
53+
'global_namespace_import' => [
54+
'import_classes' => true,
55+
'import_functions' => true,
56+
'import_constants' => true,
57+
],
58+
))
59+
->setFinder($finder)
60+
->setRiskyAllowed(true)
61+
;

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RobThree\TwoFactorAuth changelog
2+
3+
# Version 2.x
4+
5+
## Breaking changes
6+
7+
### PHP Version
8+
9+
Version 2.x requires at least PHP 8.1.
10+
11+
### Constructor signature
12+
13+
With version 2.x, the `algorithm` parameter of `RobThree\Auth\TwoFactorAuth` constructor is now an `enum`.
14+
15+
On version 1.x:
16+
17+
~~~php
18+
use RobThree\Auth\TwoFactorAuth;
19+
20+
$lib = new TwoFactorAuth('issuer-name', 6, 30, 'sha1');
21+
~~~
22+
23+
On version 2.x, simple change the algorithm from a `string` to the correct `enum`:
24+
25+
~~~php
26+
use RobThree\Auth\TwoFactorAuth;
27+
use RobThree\Auth\Algorithm;
28+
29+
$lib = new TwoFactorAuth('issuer-name', 6, 30, Algorithm::Sha1);
30+
~~~
31+
32+
See the [Algorithm.php](./lib/Algorithm.php) file to see available algorithms.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedi
1010

1111
## Requirements
1212

13-
* Tested on PHP 5.6 up to 8.0
13+
* Requires PHP version >=8.1
1414
* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `QRServerProvider` (default), `ImageChartsQRCodeProvider` or `QRicketProvider` but you can also provide your own QR-code provider.
15-
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [MCrypt](http://php.net/manual/en/book.mcrypt.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.
15+
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.
1616

1717
Optionally, you may need:
1818

@@ -38,6 +38,6 @@ If you need more in-depth information about the configuration available then you
3838

3939
## License
4040

41-
Licensed under MIT license. See [LICENSE](https://raw.githubusercontent.com/RobThree/TwoFactorAuth/master/LICENSE) for details.
41+
Licensed under MIT license. See [LICENSE](./LICENSE) for details.
4242

4343
[Logo / icon](http://www.iconmay.com/Simple/Travel_and_Tourism_Part_2/luggage_lock_safety_baggage_keys_cylinder_lock_hotel_travel_tourism_luggage_lock_icon_465) under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication ([Archived page](http://riii.nl/tm7ap))

TwoFactorAuth.phpproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PHPDevHostName>localhost</PHPDevHostName>
1616
<IISProjectUrl>http://localhost:41315/</IISProjectUrl>
1717
<Runtime>PHP</Runtime>
18-
<RuntimeVersion>7.0</RuntimeVersion>
18+
<RuntimeVersion>8.1</RuntimeVersion>
1919
</PropertyGroup>
2020
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
2121
<IncludeDebugInformation>true</IncludeDebugInformation>
@@ -34,7 +34,6 @@
3434
<Compile Include="lib\Providers\Qr\QRServerProvider.php" />
3535
<Compile Include="lib\Providers\Rng\CSRNGProvider.php" />
3636
<Compile Include="lib\Providers\Rng\IRNGProvider.php" />
37-
<Compile Include="lib\Providers\Rng\MCryptRNGProvider.php" />
3837
<Compile Include="lib\Providers\Rng\OpenSSLRNGProvider.php" />
3938
<Compile Include="lib\Providers\Rng\HashRNGProvider.php" />
4039
<Compile Include="lib\Providers\Rng\RNGException.php" />
@@ -67,4 +66,4 @@
6766
<Content Include="LICENSE" />
6867
<Content Include="phpunit.xml" />
6968
</ItemGroup>
70-
</Project>
69+
</Project>

composer.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@
1010
"name": "Rob Janssen",
1111
"homepage": "http://robiii.me",
1212
"role": "Developer"
13+
},
14+
{
15+
"name": "Nicolas CARPi",
16+
"homepage": "https://github.com/NicolasCARPi",
17+
"role": "Developer"
18+
},
19+
{
20+
"name": "Will Power",
21+
"homepage": "https://github.com/willpower232",
22+
"role": "Developer"
1323
}
1424
],
1525
"support": {
1626
"issues": "https://github.com/RobThree/TwoFactorAuth/issues",
1727
"source": "https://github.com/RobThree/TwoFactorAuth"
1828
},
1929
"require": {
20-
"php": ">=5.6.0"
30+
"php": ">=8.1.0"
2131
},
2232
"require-dev": {
23-
"phpunit/phpunit": "@stable",
24-
"php-parallel-lint/php-parallel-lint": "^1.2"
33+
"phpunit/phpunit": "^9",
34+
"friendsofphp/php-cs-fixer": "^3.13",
35+
"phpstan/phpstan": "^1.9"
2536
},
2637
"suggest": {
2738
"bacon/bacon-qr-code": "Needed for BaconQrCodeProvider provider",
@@ -38,8 +49,14 @@
3849
}
3950
},
4051
"scripts": {
52+
"phpstan": [
53+
"phpstan analyze --xdebug lib tests testsDependency"
54+
],
4155
"lint": [
42-
"parallel-lint --exclude vendor ."
56+
"php-cs-fixer fix -v"
57+
],
58+
"lint-ci": [
59+
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --dry-run --stop-on-violation"
4360
],
4461
"test": [
4562
"XDEBUG_MODE=coverage phpunit"

docs/optional-configuration.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ Argument | Default value | Use
2424
This library also comes with some [Random Number Generator (RNG)](https://en.wikipedia.org/wiki/Random_number_generation) providers. The RNG provider generates a number of random bytes and returns these bytes as a string. These values are then used to create the secret. By default (no RNG provider specified) TwoFactorAuth will try to determine the best available RNG provider to use in this order.
2525

2626
1. [CSRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/CSRNGProvider.php) for PHP7+
27-
2. [MCryptRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/MCryptRNGProvider.php) where mcrypt is available
28-
3. [OpenSSLRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/OpenSSLRNGProvider.php) where openssl is available
29-
4. [HashRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/HashRNGProvider.php) **non-cryptographically secure** fallback
27+
2. [OpenSSLRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/OpenSSLRNGProvider.php) where openssl is available
28+
3. [HashRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/HashRNGProvider.php) **non-cryptographically secure** fallback
3029

3130
Each of these RNG providers have some constructor arguments that allow you to tweak some of the settings to use when creating the random bytes.
3231

lib/Algorithm.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RobThree\Auth;
6+
7+
/**
8+
* List of supported cryptographic algorithms
9+
*/
10+
enum Algorithm: string
11+
{
12+
case Md5 = 'md5';
13+
case Sha1 = 'sha1';
14+
case Sha256 = 'sha256';
15+
case Sha512 = 'sha512';
16+
}

0 commit comments

Comments
 (0)