8000 fabot patches applied · symfony/symfony@c6500cb · GitHub
[go: up one dir, main page]

Skip to content

Commit c6500cb

Browse files
committed
fabot patches applied
1 parent d6ce8ae commit c6500cb

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/Symfony/Component/Validator/Constraints/PasswordStrength.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?php
22

3-
declare(strict_types=1);
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
411

512
namespace Symfony\Component\Validator\Constraints;
613

@@ -11,6 +18,7 @@
1118

1219
/**
1320
* @Annotation
21+
*
1422
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1523
*
1624
* @author Florent Morselli <florent.morselli@spomky-labs.com>
@@ -45,22 +53,21 @@ public function __construct(mixed $options = null, array $groups = null, mixed $
4553
throw new LogicException(sprintf('The "%s" class requires the "bjeavons/zxcvbn-php" library. Try running "composer require bjeavons/zxcvbn-php".', self::class));
4654
}
4755

48-
if (isset($options['scoreThreshold']) && (!is_int($options['scoreThreshold']) || $options['scoreThreshold'] < 1 || $options['scoreThreshold'] >4)) {
56+
if (isset($options['scoreThreshold']) && (!\is_int($options['scoreThreshold']) || $options['scoreThreshold'] < 1 || $options['scoreThreshold'] > 4)) {
4957
throw new ConstraintDefinitionException(sprintf('The parameter "scoreThreshold" of the "%s" constraint must be an integer between 1 and 4.', static::class));
5058
}
5159

52-
if (isset($options['maxRestrictedData']) && (!is_int($options['maxRestrictedData']) || $options['maxRestrictedData'] < 0)) {
60+
if (isset($options['maxRestrictedData']) && (!\is_int($options['maxRestrictedData']) || $options['maxRestrictedData'] < 0)) {
5361
throw new ConstraintDefinitionException(sprintf('The parameter "maxRestrictedData" of the "%s" constraint must be a positive integer or zero.', static::class));
5462
}
5563

5664
if (isset($options['restrictedData'])) {
5765
array_walk($options['restrictedData'], static function (mixed $value): void {
58-
if (!is_string($value)) {
66+
if (!\is_string($value)) {
5967
throw new ConstraintDefinitionException(sprintf('The parameter "restrictedData" of the "%s" constraint must be a list of strings.', static::class));
6068
}
6169
});
6270
}
6371
parent::__construct($options, $groups, $payload);
6472
}
65-
6673
}

src/Symfony/Component/Validator/Constraints/PasswordStrengthValidator.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
22

3-
declare(strict_types=1);
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
411

512
namespace Symfony\Component\Validator\Constraints;
613

7-
use Attribute;
8-
use function is_string;
914
use Symfony\Component\Validator\Constraint;
1015
use Symfony\Component\Validator\ConstraintValidator;
1116
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@@ -18,15 +23,15 @@ final class PasswordStrengthValidator extends ConstraintValidator
1823
{
1924
public function validate(#[\SensitiveParameter] mixed $value, Constraint $constraint): void
2025
{
21-
if (! $constraint instanceof PasswordStrength) {
26+
if (!$constraint instanceof PasswordStrength) {
2227
throw new UnexpectedTypeException($constraint, PasswordStrength::class);
2328
}
2429

25-
if ($value === null) {
30+
if (null === $value) {
2631
return;
2732
}
2833

29-
if (! is_string($value)) {
34+
if (!\is_string($value)) {
3035
throw new UnexpectedValueException($value, 'string');
3136
}
3237

@@ -39,7 +44,7 @@ public function validate(#[\SensitiveParameter] mixed $value, Constraint $constr
3944
->addViolation();
4045
}
4146
$wordList = $this->findRestrictedUserInputs($strength['sequence'] ?? []);
42-
if (count($wordList) > $constraint->maxRestrictedData) {
47+
if (\count($wordList) > $constraint->maxRestrictedData) {
4348
$this->context->buildViolation($constraint->restrictedDataMessage, [
4449
'{{ limit }}' => $constraint->maxRestrictedData,
4550
'{{ wordList }}' => implode(', ', $wordList),
@@ -59,10 +64,10 @@ private function findRestrictedUserInputs(array $sequence): array
5964
$found = [];
6065

6166
foreach ($sequence as $item) {
62-
if (! $item instanceof DictionaryMatch) {
67+
if (!$item instanceof DictionaryMatch) {
6368
continue;
6469
}
65-
if ($item->dictionaryName === 'user_inputs') {
70+
if ('user_inputs' === $item->dictionaryName) {
6671
$found[] = $item->token;
6772
}
6873
}

src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function createValidator(): PasswordStrengthValidator
2525
/**
2626
* @dataProvider getValidValues
2727
*/
28-
public function testValidValues(string $value): void
28+
public function testValidValues(string $value)
2929
{
3030
$this->validator->validate($value, new PasswordStrength());
3131

@@ -40,7 +40,7 @@ public static function getValidValues(): iterable
4040
/**
4141
* @dataProvider provideInvalidConstraints
4242
*/
43-
public function testThePasswordIsWeak(PasswordStrength $constraint, string $password, string $expectedMessage, string $expectedCode, array $parameters = []): void
43+
public function testThePasswordIsWeak(PasswordStrength $constraint, string $password, string $expectedMessage, string $expectedCode, array $parameters = [])
4444
{
4545
$this->validator->validate($password, $constraint);
4646

@@ -56,28 +56,27 @@ public static function provideInvalidConstraints(): iterable
5656
new PasswordStrength(),
5757
'password',
5858
'The password strength is too low. Please use a stronger password.',
59-
PasswordStrength::PASSWORD_STRENGTH_ERROR
59+
PasswordStrength::PASSWORD_STRENGTH_ERROR,
6060
];
6161
yield [
6262
new PasswordStrength([
63-
'scoreThreshold' => 4
63+
'scoreThreshold' => 4,
6464
]),
6565
'Good password?',
6666
'The password strength is too low. Please use a stronger password.',
67-
PasswordStrength::PASSWORD_STRENGTH_ERROR
67+
PasswordStrength::PASSWORD_STRENGTH_ERROR,
6868
];
6969
yield [
7070
new PasswordStrength([
71-
'restrictedData' => ['symfony']
71+
'restrictedData' => ['symfony'],
7272
]),
7373
'SyMfONY-framework-john',
7474
'The password contains more than {{ limit }} restricted data: {{ wordList }}.',
7575
PasswordStrength::RESTRICTED_USER_INPUT_ERROR,
7676
[
7777
'{{ limit }}' => 0,
7878
'{{ wordList }}' => 'SyMfONY',
79-
80-
]
79+
],
8180
];
8281
}
8382
}

0 commit comments

Comments
 (0)
0