Completed
Push — master ( ceb81d...34dbeb )
by Beñat
07:47
created

User::username()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\IdentityAccess\Domain\Model\User;
16
17
use BenGorUser\User\Domain\Model\User as BaseUser;
18
use BenGorUser\User\Domain\Model\UserEmail;
19
use BenGorUser\User\Domain\Model\UserId;
20
use BenGorUser\User\Domain\Model\UserPassword;
21
22
class User extends BaseUser
23
{
24
    private $fullName;
25
    private $username;
26
27
    protected function __construct(UserId $id, UserEmail $email, array $userRoles, UserPassword $password)
28
    {
29
        parent::__construct($id, $email, $userRoles, $password);
30
        $this->username = Username::fromEmail($email);
31
    }
32
33
    public function editProfile(UserEmail $email, Username $username, FullName $fullName)
34
    {
35
        $this->email = $email;
36
        $this->username = $username;
37
        $this->fullName = $fullName;
38
        $this->updatedOn = new \DateTimeImmutable();
39
40
        $this->publish(
41
            new UserProfileEdited(
42
                $this->id(),
43
                $this->email()
44
            )
45
        );
46
    }
47
48
    public function username() : Username
49
    {
50
        return $this->username;
51
    }
52
53
    public function fullName()
54
    {
55
        // This ternary is a hack that avoids the
56
        // DoctrineORM limitation with nullable embeddables
57
        return $this->fullName instanceof FullName
58
        && !$this->fullName->fullName()
59
            ? null
60
            : $this->fullName;
61
    }
62
}
63