Skip to content

Commit 5e1c909

Browse files
author
roadiz-ci
committed
Merge branch hotfix/v2.6.22
1 parent 4e88a1c commit 5e1c909

12 files changed

Lines changed: 26 additions & 88 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.3', '8.4']
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

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2024 Ambroise Maupate
3+
Copyright © 2025 Ambroise Maupate
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

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.3",
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.6.x-dev",
31+
"dev-develop": "2.7.x-dev"
3232
}
3333
}
3434
}

phpcs.xml.dist

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

src/PasswordGenerator.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ 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+
#[\Override]
20+
public function generatePassword(int $length = 16): string
2321
{
2422
$sets = [];
2523
$sets[] = 'abcdefghjkmnpqrstuvwxyz';
2624
$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
2725
$sets[] = '23456789';
28-
$sets[] = '!@#$%&*?';
26+
$sets[] = '!@#$%&*?-';
2927

3028
$all = '';
3129
$password = '';
@@ -35,12 +33,10 @@ public function generatePassword(int $length = 12)
3533
}
3634

3735
$all = \mb_str_split($all);
38-
for ($i = 0; $i < $length - count($sets); $i++) {
36+
for ($i = 0; $i < $length - count($sets); ++$i) {
3937
$password .= $all[array_rand($all)];
4038
}
4139

42-
$password = str_shuffle($password);
43-
44-
return $password;
40+
return str_shuffle($password);
4541
}
4642
}

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
class SaltGenerator extends RandomGenerator implements SaltGeneratorInterface
88
{
9-
/**
10-
* @return string
11-
*/
12-
public function generateSalt()
9+
#[\Override]
10+
public function generateSalt(): string
1311
{
1412
return strtr(base64_encode($this->getRandomNumber(24)), '{}', '-_');
1513
}

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
}

0 commit comments

Comments
 (0)