Completed
Push — 1.4 ( ec73d9...094b7b )
by Rafał
14:01 queued 04:41
created

User   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setId() 0 4 1
A addRole() 0 13 3
A getRoles() 0 11 2
A getSubscriberId() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2016 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 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Model;
18
19
use SWP\Bundle\UserBundle\Model\User as BaseUser;
20
use SWP\Component\MultiTenancy\Model\OrganizationAwareTrait;
21
22
class User extends BaseUser implements UserInterface
23
{
24
    use OrganizationAwareTrait;
25
26
    public function setId(string $id): void
27
    {
28
        $this->id = $id;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function addRole($role)
35
    {
36
        $role = strtoupper($role);
37
        if ($role === static::ROLE_READER) {
38
            return $this;
39
        }
40
41
        if (!in_array($role, $this->roles, true)) {
42
            $this->roles[] = $role;
43
        }
44
45
        return $this;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getRoles()
52
    {
53
        $roles = $this->roles;
54
        foreach ($this->getGroups() as $group) {
55
            $roles = array_merge($roles, $group->getRoles());
56
        }
57
        // we need to make sure to have at least one role
58
        $roles[] = static::ROLE_READER;
59
60
        return array_unique($roles);
61
    }
62
63
    public function getSubscriberId(): string
64
    {
65
        return $this->email;
66
    }
67
}
68