AbstractUserManager::findUserByConfirmationToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Manager;
15
16
use Doyo\UserBundle\Model\UserInterface;
17
use Doyo\UserBundle\Util\CanonicalFieldsUpdaterInterface;
18
use Doyo\UserBundle\Util\PasswordUpdaterInterface;
19
20
/**
21
 * Abstract User Manager implementation which can be used as base class for your
22
 * concrete manager.
23
 *
24
 * This class is taken from friendsofsymfony/user-bundle
25
 *
26
 * @author Johannes M. Schmitt <[email protected]>
27
 * @author Anthonius Munthi <[email protected]>
28
 */
29
abstract class AbstractUserManager implements UserManagerInterface
30
{
31
    private $passwordUpdater;
32
    private $canonicalFieldsUpdater;
33
34 13
    public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater)
35
    {
36 13
        $this->passwordUpdater        = $passwordUpdater;
37 13
        $this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 6
    public function createUser()
44
    {
45 6
        $class = $this->getClass();
46
47 6
        return new $class();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 2
    public function findUserByEmail($email)
54
    {
55 2
        return $this->findUserBy(['emailCanonical' => $this->canonicalFieldsUpdater->canonicalizeEmail($email)]);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 17
    public function findUserByUsername($username)
62
    {
63 17
        return $this->findUserBy(['usernameCanonical' => $this->canonicalFieldsUpdater->canonicalizeUsername($username)]);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 1
    public function findUserByUsernameOrEmail($usernameOrEmail)
70
    {
71 1
        if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) {
72 1
            $user = $this->findUserByEmail($usernameOrEmail);
73 1
            if (null !== $user) {
74 1
                return $user;
75
            }
76
        }
77
78 1
        return $this->findUserByUsername($usernameOrEmail);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function findUserByConfirmationToken($token)
85
    {
86 1
        return $this->findUserBy(['confirmationToken' => $token]);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 13
    public function updateCanonicalFields(UserInterface $user)
93
    {
94 13
        $this->canonicalFieldsUpdater->updateCanonicalFields($user);
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 13
    public function updatePassword(UserInterface $user)
101
    {
102 13
        $this->passwordUpdater->hashPassword($user);
103
    }
104
}
105