ZxcvbnTranslation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A passwordStrength() 0 5 1
A __construct() 0 5 1
A translatePasswordStrengthResults() 0 9 2
A translate() 0 4 1
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