ZxcvbnTranslation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Createnl\ZxcvbnBundle;
5
6
use Symfony\Contracts\Translation\TranslatorInterface;
7
use ZxcvbnPhp\Zxcvbn;
8
9
class ZxcvbnTranslation extends ZxcvbnDecorator
10
{
11
    /**
12
     * @var TranslatorInterface
13
     */
14
    private $translator;
15
16 2
    public function __construct(Zxcvbn $inner, TranslatorInterface $translator)
17
    {
18 2
        $this->translator = $translator;
19
20 2
        parent::__construct($inner);
21 2
    }
22
23 1
    public function passwordStrength($password, array $userInputs = [])
24
    {
25 1
        $passwordStrength = parent::passwordStrength($password, $userInputs);
26
27 1
        return $this->translatePasswordStrengthResults($passwordStrength);
28
    }
29
30 1
    private function translatePasswordStrengthResults(array $passwordStrength): array
31
    {
32 1
        $passwordStrength['feedback']['warning'] = $this->translate($passwordStrength['feedback']['warning']);
33
34 1
        foreach ($passwordStrength['feedback']['suggestions'] as $index => $suggestion) {
35 1
            $passwordStrength['feedback']['suggestions'][$index] = $this->translate($suggestion);
36
        }
37
38 1
        return $passwordStrength;
39
    }
40
41 1
    private function translate(string $string): string
42
    {
43 1
        return $this->translator->trans(
44 1
            $string,
45
        );
46
    }
47
}
48