Passed
Pull Request — master (#213)
by Kevin
03:16
created

Role::setUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * @ORM\Entity
9
 * @ORM\Table(name="roles")
10
 */
11
class Role
12
{
13
    /**
14
     * @ORM\Id
15
     * @ORM\GeneratedValue
16
     * @ORM\Column(type="integer")
17
     */
18
    private $id;
19
20
    /**
21
     * @ORM\Column(type="string")
22
     */
23
    private $name;
24
25
    /**
26
     * @ORM\OneToOne(targetEntity=User::class, inversedBy="role")
27
     * @ORM\JoinColumn(nullable=false)
28
     */
29
    private $user;
30
31
    public function getId()
32
    {
33
        return $this->id;
34
    }
35
36
    public function getName()
37
    {
38
        return $this->name;
39
    }
40
41
    public function setName($name)
42
    {
43
        $this->name = $name;
44
    }
45
46
    public function getUser()
47
    {
48
        return $this->user;
49
    }
50
51
    public function setUser(User $user)
52
    {
53
        $this->user = $user;
54
55
        if ($user->getRole() !== $this) {
56
            $user->setRole($this);
57
        }
58
    }
59
}
60