Completed
Push — master ( 59ed7d...9fb967 )
by Valentyn
02:51
created

Actor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Actors\Entity;
6
7
use App\Translation\TranslatableInterface;
8
use App\Translation\TranslatableTrait;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\ORM\Mapping as ORM;
11
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
12
use Symfony\Component\Serializer\Annotation\Groups;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
/**
16
 * @ORM\Entity(repositoryClass="App\Actors\Repository\ActorRepository")
17
 * @ORM\Table(name="actors")
18
 *
19
 * @method ActorTranslations getTranslation(string $locale, bool $useFallbackLocale = true)
20
 * @UniqueEntity("tmdb.id")
21
 */
22
class Actor implements TranslatableInterface
23
{
24
    use TranslatableTrait;
25
26
    const GENDER_MALE = 2;
27
    const GENDER_FEMALE = 1;
28
29
    /**
30
     * @ORM\Id()
31
     * @ORM\GeneratedValue()
32
     * @ORM\Column(type="integer")
33
     * @Groups({"list", "view"})
34
     */
35
    private $id;
36
37
    /**
38
     * @var ActorTranslations[]|ArrayCollection
39
     * @ORM\OneToMany(targetEntity="App\Actors\Entity\ActorTranslations", mappedBy="actor", cascade={"persist", "remove"})
40
     * @Assert\Valid(traverse=true)
41
     * @Groups({"list", "view"})
42
     */
43
    private $translations;
44
45
    /**
46
     * @var ActorContacts[]|ArrayCollection
47
     * @ORM\OneToMany(targetEntity="App\Actors\Entity\ActorContacts", mappedBy="profile", cascade={"persist", "remove"})
48
     * @ORM\JoinColumn(nullable=true)
49
     * @Groups({"view"})
50
     */
51
    private $contacts;
52
53
    /**
54
     * @Groups({"list", "view"})
55
     * @ORM\Column(type="string", length=100)
56
     */
57
    private $originalName;
58
59
    /**
60
     * @Groups({"list", "view"})
61
     * @ORM\Column(type="string", length=255, nullable=true)
62
     */
63
    private $photo;
64
65
    /**
66
     * @ORM\Embedded(class="App\Actors\Entity\ActorTMDB", columnPrefix="tmdb_")
67
     * @Assert\Valid(traverse=true)
68
     * @Groups({"list", "view"})
69
     */
70
    private $tmdb;
71
72
    /**
73
     * @ORM\Column(type="string", length=20, nullable=true)
74
     * @Groups({"view"})
75
     */
76
    private $imdbId;
77
78
    /**
79
     * @Groups({"list", "view"})
80
     * @ORM\Column(type="date", nullable=true)
81
     */
82
    private $birthday;
83
84
    /**
85
     * @Groups({"list", "view"})
86
     * @ORM\Column(type="integer", length=1, nullable=false)
87
     */
88
    private $gender;
89
90
    public function __construct(string $originalName, ActorTMDB $actorTMDB)
91
    {
92
        $this->translations = new ArrayCollection();
93
        $this->contacts = new ArrayCollection();
94
95
        $this->originalName = $originalName;
96
        $this->tmdb = $actorTMDB;
97
    }
98
99
    public function getId(): int
100
    {
101
        return $this->id;
102
    }
103
104
    public function getOriginalName(): string
105
    {
106
        return $this->originalName;
107
    }
108
109
    public function setOriginalName(string $originalName): void
110
    {
111
        $this->originalName = $originalName;
112
    }
113
114
    public function getPhoto(): string
115
    {
116
        return $this->photo;
117
    }
118
119
    public function setPhoto(string $photo): void
120
    {
121
        $this->photo = $photo;
122
    }
123
124
    public function getTmdb(): ActorTMDB
125
    {
126
        return $this->tmdb;
127
    }
128
129
    public function setTmdb(ActorTMDB $tmdb): void
130
    {
131
        $this->tmdb = $tmdb;
132
    }
133
134
    public function getImdbId(): string
135
    {
136
        return $this->imdbId;
137
    }
138
139
    public function setImdbId(string $imdbId): void
140
    {
141
        $this->imdbId = $imdbId;
142
    }
143
144
    public function getBirthday()
145
    {
146
        return $this->birthday;
147
    }
148
149
    public function setBirthday(\DateTimeInterface $birthday): void
150
    {
151
        $this->birthday = $birthday;
152
    }
153
154
    public function getGender()
155
    {
156
        return $this->gender;
157
    }
158
159
    /**
160
     * @param int $gender
161
     * @throws \InvalidArgumentException
162
     */
163
    public function setGender(int $gender): void
164
    {
165
        if (false === in_array($gender, [self::GENDER_FEMALE, self::GENDER_MALE])) {
166
            throw new \InvalidArgumentException('Invalid gender value');
167
        }
168
        $this->gender = $gender;
169
    }
170
}
171