Passed
Push — main ( 25ab27...21c65b )
by Proyecto
08:42
created

User::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ProyectoTAU\TAU\Module\Administration\User\Domain;
4
5
use ProyectoTAU\TAU\Module\Administration\Group\Domain\Group;
6
7
class User
8
{
9
    private $id;
10
    private $name;
11
    private $surname;
12
    private $login;
13
14
    private $belongsto = [];
15
16 29
    public function __construct($id, $name, $surname, $login)
17
    {
18 29
        $this->setId($id);
19 29
        $this->setName($name);
20 29
        $this->setSurname($surname);
21 29
        $this->setLogin($login);
22
23
        // TODO: Raise CreateUserDomainEvent($this)
24 29
    }
25
26 29
    public function setId($id)
27
    {
28 29
        $this->id = $id;
29 29
    }
30
31 36
    public function getId()
32
    {
33 36
        return $this->id;
34
    }
35
36 29
    public function setName($name)
37
    {
38 29
        $this->name = $name;
39 29
    }
40
41 20
    public function getName()
42
    {
43 20
        return $this->name;
44
    }
45
46 29
    public function setSurname($surname)
47
    {
48 29
        $this->surname = $surname;
49 29
    }
50
51 20
    public function getSurname()
52
    {
53 20
        return $this->surname;
54
    }
55
56 29
    public function setLogin($login)
57
    {
58 29
        $this->login = $login;
59 29
    }
60
61 20
    public function getLogin()
62
    {
63 20
        return $this->login;
64
    }
65
66 5
    public function addGroup($group)
67
    {
68 5
        $this->belongsto[$group->getId()] = $group;
69
        // TODO: Raise AddGroupToUserDomainEvent($this, $group)
70
        //$user->addGroup($this); //TODO: this causes an infinite loop
71 5
    }
72
73 3
    public function removeGroup(Group $group)
74
    {
75 3
        unset($this->belongsto[$group->getId()]);
76
        // TODO: Raise RemoveGroupFromUserDomainEvent($role, $this)
77 3
    }
78
79 5
    public function getGroups(): array
80
    {
81 5
        return $this->belongsto;
82
    }
83
84 9
    public function equals($o): bool
85
    {
86 9
        return $this->getid()       == $o->getid()
87 9
            && $this->getName()     == $o->getName()
88 9
            && $this->getSurname()  == $o->getSurname()
89 9
            && $this->getLogin()    == $o->getLogin();
90
    }
91
92 1
    public function __toString()
93
    {
94
        return
95 1
            "id: " . $this->id . "\n" .
96 1
            "name: " . $this->name . "\n" .
97 1
            "surname: " . $this->surname . "\n" .
98 1
            "login: " . $this->login . "\n";
99
    }
100
}
101