Completed
Push — master ( 4407aa...f0730d )
by ANTHONIUS
22s queued 14s
created

CanonicalFieldsUpdater   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCanonicalFields() 0 4 1
A __construct() 0 4 1
A canonicalizeUsername() 0 3 1
A canonicalizeEmail() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\Util;
15
16
use Doyo\UserBundle\Model\UserInterface;
17
18
class CanonicalFieldsUpdater implements CanonicalFieldsUpdaterInterface
19
{
20
    /**
21
     * @var CanonicalizerInterface
22
     */
23
    private $usernameCanonicalizer;
24
25
    /**
26
     * @var CanonicalizerInterface
27
     */
28
    private $emailCanonicalizer;
29
30
    /**
31
     * CanonicalFieldsUpdater constructor.
32
     */
33 16
    public function __construct(CanonicalizerInterface $usernameCanonicalizer, CanonicalizerInterface $emailCanonicalizer)
34
    {
35 16
        $this->usernameCanonicalizer = $usernameCanonicalizer;
36 16
        $this->emailCanonicalizer    = $emailCanonicalizer;
37
    }
38
39 12
    public function updateCanonicalFields(UserInterface $user)
40
    {
41 12
        $user->setUsernameCanonical($this->usernameCanonicalizer->canonicalize($user->getUsername()));
42 12
        $user->setEmailCanonical($this->emailCanonicalizer->canonicalize($user->getEmail()));
43
    }
44
45
    /**
46
     * Canonicalizes an email.
47
     *
48
     * @param string|null $email
49
     *
50
     * @return string|null
51
     */
52 3
    public function canonicalizeEmail($email)
53
    {
54 3
        return $this->emailCanonicalizer->canonicalize($email);
55
    }
56
57
    /**
58
     * Canonicalizes a username.
59
     *
60
     * @param string|null $username
61
     *
62
     * @return string|null
63
     */
64 15
    public function canonicalizeUsername($username)
65
    {
66 15
        return $this->usernameCanonicalizer->canonicalize($username);
67
    }
68
}
69