Skip to content

Commit ae0d567

Browse files
Merge branch '4.4' into 5.1
* 4.4: Enable "native_constant_invocation" CS rule Make AbstractPhpFileCacheWarmer public
2 parents 0b965da + 637ba4c commit ae0d567

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Encoder/EncoderFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function getEncoderConfigFromAlgorithm(array $config): array
153153

154154
case 'bcrypt':
155155
$config['algorithm'] = 'native';
156-
$config['native_algorithm'] = PASSWORD_BCRYPT;
156+
$config['native_algorithm'] = \PASSWORD_BCRYPT;
157157

158158
return $this->getEncoderConfigFromAlgorithm($config);
159159

@@ -181,7 +181,7 @@ private function getEncoderConfigFromAlgorithm(array $config): array
181181
$config['algorithm'] = 'sodium';
182182
} elseif (\defined('PASSWORD_ARGON2I')) {
183183
$config['algorithm'] = 'native';
184-
$config['native_algorithm'] = PASSWORD_ARGON2I;
184+
$config['native_algorithm'] = \PASSWORD_ARGON2I;
185185
} else {
186186
throw new LogicException(sprintf('Algorithm "argon2i" is not available. Either use %s"auto" or upgrade to PHP 7.2+ instead.', \defined('SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13') ? '"argon2id", ' : ''));
187187
}
@@ -193,7 +193,7 @@ private function getEncoderConfigFromAlgorithm(array $config): array
193193
$config['algorithm'] = 'sodium';
194194
} elseif (\defined('PASSWORD_ARGON2ID')) {
195195
$config['algorithm'] = 'native';
196-
$config['native_algorithm'] = PASSWORD_ARGON2ID;
196+
$config['native_algorithm'] = \PASSWORD_ARGON2ID;
197197
} else {
198198
throw new LogicException(sprintf('Algorithm "argon2id" is not available. Either use %s"auto", upgrade to PHP 7.3+ or use libsodium 1.0.15+ instead.', \defined('PASSWORD_ARGON2I') || $hasSodium ? '"argon2i", ' : ''));
199199
}

Encoder/NativePasswordEncoder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class NativePasswordEncoder implements PasswordEncoderInterface, SelfSalti
2424
{
2525
private const MAX_PASSWORD_LENGTH = 4096;
2626

27-
private $algo = PASSWORD_BCRYPT;
27+
private $algo = \PASSWORD_BCRYPT;
2828
private $options;
2929

3030
/**
@@ -33,8 +33,8 @@ final class NativePasswordEncoder implements PasswordEncoderInterface, SelfSalti
3333
public function __construct(int $opsLimit = null, int $memLimit = null, int $cost = null, string $algo = null)
3434
{
3535
$cost = $cost ?? 13;
36-
$opsLimit = $opsLimit ?? max(4, \defined('SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE') ? SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE : 4);
37-
$memLimit = $memLimit ?? max(64 * 1024 * 1024, \defined('SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE') ? SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE : 64 * 1024 * 1024);
36+
$opsLimit = $opsLimit ?? max(4, \defined('SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE') ? \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE : 4);
37+
$memLimit = $memLimit ?? max(64 * 1024 * 1024, \defined('SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE') ? \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE : 64 * 1024 * 1024);
3838

3939
if (3 > $opsLimit) {
4040
throw new \InvalidArgumentException('$opsLimit must be 3 or greater.');
@@ -48,14 +48,14 @@ public function __construct(int $opsLimit = null, int $memLimit = null, int $cos
4848
throw new \InvalidArgumentException('$cost must be in the range of 4-31.');
4949
}
5050

51-
$algos = [1 => PASSWORD_BCRYPT, '2y' => PASSWORD_BCRYPT];
51+
$algos = [1 => \PASSWORD_BCRYPT, '2y' => \PASSWORD_BCRYPT];
5252

5353
if (\defined('PASSWORD_ARGON2I')) {
54-
$this->algo = $algos[2] = $algos['argon2i'] = (string) PASSWORD_ARGON2I;
54+
$this->algo = $algos[2] = $algos['argon2i'] = (string) \PASSWORD_ARGON2I;
5555
}
5656

5757
if (\defined('PASSWORD_ARGON2ID')) {
58-
$this->algo = $algos[3] = $algos['argon2id'] = (string) PASSWORD_ARGON2ID;
58+
$this->algo = $algos[3] = $algos['argon2id'] = (string) \PASSWORD_ARGON2ID;
5959
}
6060

6161
if (null !== $algo) {
@@ -75,7 +75,7 @@ public function __construct(int $opsLimit = null, int $memLimit = null, int $cos
7575
*/
7676
public function encodePassword(string $raw, ?string $salt): string
7777
{
78-
if (\strlen($raw) > self::MAX_PASSWORD_LENGTH || ((string) PASSWORD_BCRYPT === $this->algo && 72 < \strlen($raw))) {
78+
if (\strlen($raw) > self::MAX_PASSWORD_LENGTH || ((string) \PASSWORD_BCRYPT === $this->algo && 72 < \strlen($raw))) {
7979
throw new BadCredentialsException('Invalid password.');
8080
}
8181

@@ -102,7 +102,7 @@ public function isPasswordValid(string $encoded, string $raw, ?string $salt): bo
102102
return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded);
103103
}
104104

105-
if (\extension_loaded('sodium') && version_compare(SODIUM_LIBRARY_VERSION, '1.0.14', '>=')) {
105+
if (\extension_loaded('sodium') && version_compare(\SODIUM_LIBRARY_VERSION, '1.0.14', '>=')) {
106106
return sodium_crypto_pwhash_str_verify($encoded, $raw);
107107
}
108108

Encoder/SodiumPasswordEncoder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function __construct(int $opsLimit = null, int $memLimit = null)
3434
throw new LogicException('Libsodium is not available. You should either install the sodium extension, upgrade to PHP 7.2+ or use a different encoder.');
3535
}
3636

37-
$this->opsLimit = $opsLimit ?? max(4, \defined('SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE') ? SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE : 4);
38-
$this->memLimit = $memLimit ?? max(64 * 1024 * 1024, \defined('SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE') ? SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE : 64 * 1024 * 1024);
37+
$this->opsLimit = $opsLimit ?? max(4, \defined('SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE') ? \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE : 4);
38+
$this->memLimit = $memLimit ?? max(64 * 1024 * 1024, \defined('SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE') ? \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE : 64 * 1024 * 1024);
3939

4040
if (3 > $this->opsLimit) {
4141
throw new \InvalidArgumentException('$opsLimit must be 3 or greater.');
@@ -48,7 +48,7 @@ public function __construct(int $opsLimit = null, int $memLimit = null)
4848

4949
public static function isSupported(): bool
5050
{
51-
return version_compare(\extension_loaded('sodium') ? SODIUM_LIBRARY_VERSION : phpversion('libsodium'), '1.0.14', '>=');
51+
return version_compare(\extension_loaded('sodium') ? \SODIUM_LIBRARY_VERSION : phpversion('libsodium'), '1.0.14', '>=');
5252
}
5353

5454
/**

Tests/Encoder/EncoderFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public function testMigrateFrom()
150150
$this->assertInstanceOf(MigratingPasswordEncoder::class, $encoder);
151151

152152
$this->assertTrue($encoder->isPasswordValid((new SodiumPasswordEncoder())->encodePassword('foo', null), 'foo', null));
153-
$this->assertTrue($encoder->isPasswordValid((new NativePasswordEncoder(null, null, null, PASSWORD_BCRYPT))->encodePassword('foo', null), 'foo', null));
153+
$this->assertTrue($encoder->isPasswordValid((new NativePasswordEncoder(null, null, null, \PASSWORD_BCRYPT))->encodePassword('foo', null), 'foo', null));
154154
$this->assertTrue($encoder->isPasswordValid($digest->encodePassword('foo', null), 'foo', null));
155-
$this->assertStringStartsWith(SODIUM_CRYPTO_PWHASH_STRPREFIX, $encoder->encodePassword('foo', null));
155+
$this->assertStringStartsWith(\SODIUM_CRYPTO_PWHASH_STRPREFIX, $encoder->encodePassword('foo', null));
156156
}
157157

158158
public function testDefaultMigratingEncoders()

Tests/Encoder/NativePasswordEncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testNonArgonValidation()
6767

6868
public function testConfiguredAlgorithm()
6969
{
70-
$encoder = new NativePasswordEncoder(null, null, null, PASSWORD_BCRYPT);
70+
$encoder = new NativePasswordEncoder(null, null, null, \PASSWORD_BCRYPT);
7171
$result = $encoder->encodePassword('password', null);
7272
$this->assertTrue($encoder->isPasswordValid($result, 'password', null));
7373
$this->assertStringStartsWith('$2', $result);
@@ -84,7 +84,7 @@ public function testConfiguredAlgorithmWithLegacyConstValue()
8484
public function testCheckPasswordLength()
8585
{
8686
$encoder = new NativePasswordEncoder(null, null, 4);
87-
$result = password_hash(str_repeat('a', 72), PASSWORD_BCRYPT, ['cost' => 4]);
87+
$result = password_hash(str_repeat('a', 72), \PASSWORD_BCRYPT, ['cost' => 4]);
8888

8989
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
9090
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));

0 commit comments

Comments
 (0)