Completed
Push — master ( affb41...f007be )
by Rafał
09:54
created

UserManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 65
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A createUser() 0 7 1
A findUserByEmail() 0 4 1
A findUserByUsername() 0 4 1
A findUserByUsernameOrEmail() 0 11 3
A findUserByConfirmationToken() 0 4 1
deleteUser() 0 1 ?
findUserBy() 0 1 ?
findUsers() 0 1 ?
A getClass() 0 4 1
updateUser() 0 1 ?
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher User Bundle.
7
 *
8
 * Copyright 2021 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @Copyright 2021 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\UserBundle\Model;
18
19
abstract class UserManager implements UserManagerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function createUser(): UserInterface
25
    {
26
        $class = $this->getClass();
27
        $user = new $class();
28
29
        return $user;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function findUserByEmail($email)
36
    {
37
        return $this->findUserBy(['email' => $email]);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function findUserByUsername($username)
44
    {
45
        return $this->findUserBy(['username' => $username]);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function findUserByUsernameOrEmail($usernameOrEmail)
52
    {
53
        if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) {
54
            $user = $this->findUserByEmail($usernameOrEmail);
55
            if (null !== $user) {
56
                return $user;
57
            }
58
        }
59
60
        return $this->findUserByUsername($usernameOrEmail);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function findUserByConfirmationToken($token)
67
    {
68
        return $this->findUserBy(['confirmationToken' => $token]);
69
    }
70
71
    abstract public function deleteUser(UserInterface $user);
72
73
    abstract public function findUserBy(array $criteria);
74
75
    abstract public function findUsers();
76
77
    public function getClass()
78
    {
79
        return User::class;
80
    }
81
82
    abstract public function updateUser(UserInterface $user, $andFlush = true);
83
}
84