Completed
Push — master ( bbd2b1...f08c3b )
by Kamil
31:47 queued 09:37
created

ShopUser::getEncoderName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
declare(strict_types=1);
13
14
namespace Sylius\Component\Core\Model;
15
16
use Sylius\Component\Customer\Model\CustomerInterface as BaseCustomerInterface;
17
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
18
use Sylius\Component\User\Model\User as BaseUser;
19
20
class ShopUser extends BaseUser implements ShopUserInterface
21
{
22
    /** @var BaseCustomerInterface|null */
23
    protected $customer;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getCustomer(): ?BaseCustomerInterface
29
    {
30
        return $this->customer;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function setCustomer(?BaseCustomerInterface $customer): void
37
    {
38
        if ($this->customer === $customer) {
39
            return;
40
        }
41
42
        $previousCustomer = $this->customer;
43
        $this->customer = $customer;
44
45
        if ($previousCustomer instanceof CustomerInterface) {
46
            $previousCustomer->setUser(null);
47
        }
48
49
        if ($customer instanceof CustomerInterface) {
50
            $customer->setUser($this);
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getEmail(): ?string
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
58
    {
59
        if (null === $this->customer) {
60
            return null;
61
        }
62
63
        return $this->customer->getEmail();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function setEmail(?string $email): void
70
    {
71
        if (null === $this->customer) {
72
            throw new UnexpectedTypeException($this->customer, BaseCustomerInterface::class);
73
        }
74
75
        $this->customer->setEmail($email);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getEmailCanonical(): ?string
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
82
    {
83
        if (null === $this->customer) {
84
            return null;
85
        }
86
87
        return $this->customer->getEmailCanonical();
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function setEmailCanonical(?string $emailCanonical): void
94
    {
95
        if (null === $this->customer) {
96
            throw new UnexpectedTypeException($this->customer, BaseCustomerInterface::class);
97
        }
98
99
        $this->customer->setEmailCanonical($emailCanonical);
100
    }
101
}
102