Completed
Push — master ( 2fef72...ca35b8 )
by Łukasz
23:27
created

UserPasswordValidationException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Base\Exceptions;
10
11
use Exception;
12
use eZ\Publish\Core\FieldType\ValidationError;
13
14
class UserPasswordValidationException extends InvalidArgumentException
15
{
16
    /**
17
     * Generates: "Argument '{$argumentName}' is invalid: Password doesn't match the following rules: {X}, {Y}, {Z}".
18
     *
19
     * @param string $argumentName
20
     * @param array $errors
21
     * @param Exception|null $previous
22
     */
23
    public function __construct(string $argumentName, array $errors, Exception $previous = null)
24
    {
25
        $rules = array_map(function (ValidationError $error) {
26
            return (string) $error->getTranslatableMessage();
27
        }, $errors);
28
29
        parent::__construct($argumentName, "Password doesn't match the following rules: " . implode(', ', $rules), $previous);
30
    }
31
}
32