Completed
Pull Request — example/managing-articles (#134)
by Loïc
02:30
created

AppUser::getEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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
namespace App\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Sylius\Component\Customer\Model\CustomerInterface;
16
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
17
use Sylius\Component\User\Model\User as BaseUser;
18
19
/**
20
 * @ORM\Entity
21
 * @ORM\Table(name="sylius_app_user")
22
 */
23
class AppUser extends BaseUser
24
{
25
    /**
26
     * @var CustomerInterface
27
     *
28
     * @ORM\OneToOne(targetEntity="Sylius\Component\Customer\Model\CustomerInterface", inversedBy="user", cascade={"persist"})
29
     * @ORM\JoinColumn(nullable=false)
30
     */
31
    protected $customer;
32
33
    /**
34
     * @return CustomerInterface
35
     */
36
    public function getCustomer()
37
    {
38
        return $this->customer;
39
    }
40
41
    /**
42
     * @param CustomerInterface $customer
43
     *
44
     * @return $this
45
     */
46
    public function setCustomer($customer)
47
    {
48
        $this->customer = $customer;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return string|null
55
     */
56
    public function getEmail(): ?string
57
    {
58
        if (null === $this->customer) {
59
            return null;
60
        }
61
62
        return $this->customer->getEmail();
63
    }
64
65
    /**
66
     * @param string|null $email
67
     */
68
    public function setEmail(?string $email): void
69
    {
70
        if (null === $this->customer) {
71
            throw new UnexpectedTypeException($this->customer, CustomerInterface::class);
72
        }
73
74
        $this->customer->setEmail($email);
75
    }
76
77
    /**
78
     * @return string|null
79
     */
80
    public function getEmailCanonical(): ?string
81
    {
82
        if (null === $this->customer) {
83
            return null;
84
        }
85
86
        return $this->customer->getEmailCanonical();
87
    }
88
89
    /**
90
     * @param string|null $emailCanonical
91
     */
92
    public function setEmailCanonical(?string $emailCanonical): void
93
    {
94
        if (null === $this->customer) {
95
            throw new UnexpectedTypeException($this->customer, CustomerInterface::class);
96
        }
97
98
        $this->customer->setEmailCanonical($emailCanonical);
99
    }
100
101
    /**
102
     * @param Customer $customer
103
     */
104
    protected function assignUser(Customer $customer = null)
105
    {
106
        if (null !== $customer) {
107
            $customer->setUser($this);
108
        }
109
    }
110
}
111