Skip to content

Commit c20883d

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent 5e45e33 commit c20883d

11 files changed

Lines changed: 22 additions & 87 deletions

.github/workflows/run-test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.1', '8.2', '8.3']
22+
php-version: ['8.2', '8.3']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:
@@ -35,7 +35,5 @@ jobs:
3535
${{ runner.os }}-php-${{ matrix.php-version }}-
3636
- name: Install Dependencies
3737
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
38-
- name: Run PHP Code Sniffer
39-
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
4038
- name: Run PHPStan
4139
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

Makefile

Lines changed: 0 additions & 3 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.1",
15+
"php": ">=8.2",
1616
"psr/log": ">=1.1",
1717
"ext-openssl": "*"
1818
},
1919
"require-dev": {
2020
"phpstan/phpstan": "^1.5.3",
21-
"squizlabs/php_codesniffer": "^3.5"
21+
"phpstan/phpdoc-parser": "<2"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -27,8 +27,8 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-main": "2.3.x-dev",
31-
"dev-develop": "2.4.x-dev"
30+
"dev-main": "2.5.x-dev",
31+
"dev-develop": "2.6.x-dev"
3232
}
3333
}
3434
}

phpcs.xml.dist

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/PasswordGenerator.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ class PasswordGenerator extends RandomGenerator implements PasswordGeneratorInte
1111
* one uppercase letter, one digit, and one special character. The remaining characters
1212
* in the password are chosen at random from those four sets.
1313
*
14-
* The available characters in each set are user friendly - there are no ambiguous
14+
* The available characters in each set are user-friendly - there are no ambiguous
1515
* characters such as i, l, 1, o, 0, etc.
1616
*
17-
* @param int $length
18-
* @return string
19-
*
2017
* @see https://gist.github.com/tylerhall/521810
2118
*/
22-
public function generatePassword(int $length = 12)
19+
public function generatePassword(int $length = 16): string
2320
{
2421
$sets = [];
2522
$sets[] = 'abcdefghjkmnpqrstuvwxyz';
2623
$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
2724
$sets[] = '23456789';
28-
$sets[] = '!@#$%&*?';
25+
$sets[] = '!@#$%&*?-';
2926

3027
$all = '';
3128
$password = '';
@@ -35,12 +32,10 @@ public function generatePassword(int $length = 12)
3532
}
3633

3734
$all = \mb_str_split($all);
38-
for ($i = 0; $i < $length - count($sets); $i++) {
35+
for ($i = 0; $i < $length - count($sets); ++$i) {
3936
$password .= $all[array_rand($all)];
4037
}
4138

42-
$password = str_shuffle($password);
43-
44-
return $password;
39+
return str_shuffle($password);
4540
}
4641
}

src/PasswordGeneratorInterface.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@
66

77
interface PasswordGeneratorInterface
88
{
9-
/**
10-
* @param int $length
11-
* @return string
12-
*/
13-
public function generatePassword(int $length = 12);
9+
public function generatePassword(int $length = 16): string;
1410
}

src/RandomGenerator.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,22 @@
88

99
class RandomGenerator
1010
{
11-
protected ?LoggerInterface $logger;
12-
protected bool $useOpenSsl;
13-
14-
/**
15-
* @param LoggerInterface|null $logger
16-
*/
17-
public function __construct(LoggerInterface $logger = null)
11+
public function __construct(protected readonly LoggerInterface $logger)
1812
{
19-
$this->logger = $logger;
20-
// determine whether to use OpenSSL
21-
if (defined('PHP_WINDOWS_VERSION_BUILD') && version_compare(PHP_VERSION, '5.3.4', '<')) {
22-
$this->useOpenSsl = false;
23-
} elseif (!function_exists('openssl_random_pseudo_bytes')) {
24-
if (null !== $this->logger) {
25-
$this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
26-
}
27-
$this->useOpenSsl = false;
28-
} else {
29-
$this->useOpenSsl = true;
13+
if (!function_exists('openssl_random_pseudo_bytes')) {
14+
throw new \RuntimeException('You must enable the "openssl" extension for secure random number generation.');
3015
}
3116
}
3217

33-
/**
34-
* @param int $nbBytes
35-
* @return string
36-
*/
3718
public function getRandomNumber(int $nbBytes = 32): string
3819
{
3920
// try OpenSSL
40-
if ($this->useOpenSsl) {
41-
$bytes = \openssl_random_pseudo_bytes($nbBytes, $strong);
42-
43-
if (false !== $bytes && true === $strong) {
44-
return $bytes;
45-
}
21+
$bytes = \openssl_random_pseudo_bytes($nbBytes, $strong);
4622

47-
if (null !== $this->logger) {
48-
$this->logger->info('OpenSSL did not produce a secure random number.');
49-
}
23+
if (false !== $bytes && true === $strong) {
24+
return $bytes;
5025
}
5126

52-
return hash('sha256', uniqid((string) mt_rand(), true), true);
27+
throw new \RuntimeException('Unable to generate a secure random number.');
5328
}
5429
}

src/SaltGenerator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
class SaltGenerator extends RandomGenerator implements SaltGeneratorInterface
88
{
9-
/**
10-
* @return string
11-
*/
12-
public function generateSalt()
9+
public function generateSalt(): string
1310
{
1411
return strtr(base64_encode($this->getRandomNumber(24)), '{}', '-_');
1512
}

src/SaltGeneratorInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface SaltGeneratorInterface
88
{
9-
/**
10-
* @return string
11-
*/
12-
public function generateSalt();
9+
public function generateSalt(): string;
1310
}

src/TokenGenerator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
class TokenGenerator extends RandomGenerator implements TokenGeneratorInterface
88
{
9-
/**
10-
* @return string
11-
*/
12-
public function generateToken()
9+
public function generateToken(): string
1310
{
1411
return rtrim(strtr(base64_encode($this->getRandomNumber()), '+/', '-_'), '=');
1512
}

0 commit comments

Comments
 (0)