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\User\Model\User as BaseUser; |
18
|
|
|
use Webmozart\Assert\Assert; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
* @author Michał Marcinkowski <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ShopUser extends BaseUser implements ShopUserInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var CustomerInterface |
28
|
|
|
*/ |
29
|
|
|
protected $customer; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function getCustomer(): ?BaseCustomerInterface |
35
|
|
|
{ |
36
|
|
|
return $this->customer; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function setCustomer(?BaseCustomerInterface $customer): void |
43
|
|
|
{ |
44
|
|
|
if ($this->customer === $customer) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$previousCustomer = $this->customer; |
49
|
|
|
$this->customer = $customer; |
|
|
|
|
50
|
|
|
|
51
|
|
|
if ($previousCustomer instanceof CustomerInterface) { |
52
|
|
|
$previousCustomer->setUser(null); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($customer instanceof CustomerInterface) { |
56
|
|
|
$customer->setUser($this); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function getEmail(): ?string |
64
|
|
|
{ |
65
|
|
|
return $this->customer->getEmail(); |
66
|
|
|
} |
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function setEmail(?string $email): void |
71
|
|
|
{ |
72
|
|
|
$this->customer->setEmail($email); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getEmailCanonical(): ?string |
79
|
|
|
{ |
80
|
|
|
return $this->customer->getEmailCanonical(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function setEmailCanonical(?string $emailCanonical): void |
87
|
|
|
{ |
88
|
|
|
$this->customer->setEmailCanonical($emailCanonical); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.