| Total Complexity | 5 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class ConditionalRule implements Rule |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var Rule Rule to test conditionally. |
||
| 16 | */ |
||
| 17 | private $rule; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var callable(Password|string): bool Condition function. |
||
| 21 | */ |
||
| 22 | private $condition; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param Rule $rule Rule to test if the condition is true. |
||
| 26 | * @param callable(Password|string): bool $condition Condition function. |
||
| 27 | */ |
||
| 28 | 4 | public function __construct(Rule $rule, callable $condition) |
|
| 32 | 4 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @inheritDoc |
||
| 36 | */ |
||
| 37 | 2 | public function test($password, ?int $weight = null): bool |
|
| 38 | { |
||
| 39 | 2 | if (($this->condition)($password)) { |
|
| 40 | 1 | return $this->rule->test($password, $weight); |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | return true; |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @inheritDoc |
||
| 48 | */ |
||
| 49 | 2 | public function validate($password, TranslatorInterface $translator): ?ValidationError |
|
| 56 | } |
||
| 57 | } |
||
| 58 |