Completed
Push — master ( bb86ee...4db16d )
by Loïc
02:12 queued 12s
created

Customer::getUser()   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 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\Customer;
13
14
use App\Entity\User\AppUserInterface;
15
use Doctrine\ORM\Mapping as ORM;
16
use Sylius\Component\Customer\Model\Customer as BaseCustomer;
17
use Sylius\Component\User\Model\UserInterface;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * @ORM\Entity
22
 * @ORM\Table(name="sylius_customer")
23
 */
24
class Customer extends BaseCustomer implements CustomerInterface
25
{
26
    /**
27
     * @var AppUserInterface|UserInterface
28
     *
29
     * @ORM\OneToOne(targetEntity="App\Entity\User\AppUser", mappedBy="customer", cascade={"persist"})
30
     *
31
     * @Assert\Valid
32
     */
33
    private $user;
34
35
    /**
36
     * @return AppUserInterface|UserInterface
37
     */
38
    public function getUser(): ?UserInterface
39
    {
40
        return $this->user;
41
    }
42
43
    /**
44
     * @param AppUserInterface|UserInterface|null $user
45
     */
46
    public function setUser(?UserInterface $user): void
47
    {
48
        if ($this->user === $user) {
49
            return;
50
        }
51
52
        \Webmozart\Assert\Assert::nullOrIsInstanceOf($user, AppUserInterface::class);
53
54
        $previousUser = $this->user;
55
        $this->user = $user;
56
57
        if ($previousUser instanceof AppUserInterface) {
58
            $previousUser->setCustomer(null);
59
        }
60
61
        if ($user instanceof AppUserInterface) {
62
            $user->setCustomer($this);
63
        }
64
    }
65
}
66