Completed
Push — master ( 71eba9...1e1a94 )
by Valentyn
04:31
created

MovieReview::setLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Movies\Entity;
4
5
use App\Users\Entity\User;
6
use App\Users\Entity\UserWatchedMovie;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
/**
12
 * @ORM\Entity(repositoryClass="App\Movies\Repository\MovieReviewRepository")
13
 */
14
class MovieReview
15
{
16
    /**
17
     * Important note here - this property (userWatchedMovie) MUST be first,
18
     * because otherwise Doctrine will fill (override) user_id and movie_id with values from UserWatchedMovie
19
     * which usually just nulls.
20
     *
21
     * @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie")
22
     * @ORM\JoinColumns({
23
     *     @ORM\JoinColumn(name="user_id", referencedColumnName="user_id"),
24
     *     @ORM\JoinColumn(name="movie_id", referencedColumnName="movie_id")
25
     *   })
26
     * @Groups({"list", "view"})
27
     */
28
    private $userWatchedMovie;
29
30
    /**
31
     * @ORM\Id()
32
     * @ORM\GeneratedValue()
33
     * @ORM\Column(type="integer")
34
     * @Groups({"list", "view"})
35
     */
36
    private $id;
37
38
    /**
39
     * @ORM\Column(type="text")
40
     * @Groups({"list", "view"})
41
     */
42
    private $text;
43
44
    /**
45
     * @ORM\Column(type="string", length=2)
46
     */
47
    private $locale;
48
49
    /**
50
     * @ORM\Column(type="boolean")
51
     */
52
    private $isReview;
53
54
    /**
55
     * @ORM\ManyToOne(targetEntity="MovieReview")
56
     */
57
    private $answerTo;
58
59
    /**
60
     * @ORM\OneToMany(targetEntity="MovieReview", mappedBy="answerTo", cascade={"persist"})
61
     */
62
    private $answers;
63
64
    /**
65
     * @ORM\ManyToOne(targetEntity="App\Movies\Entity\Movie")
66
     */
67
    private $movie;
68
69
    /**
70
     * @ORM\ManyToOne(targetEntity="App\Users\Entity\User")
71
     * @Groups({"list", "view"})
72
     */
73
    private $user;
74
75 1
    public function __construct(Movie $movie, User $user, string $locale, string $text)
76
    {
77 1
        $this->answers = new ArrayCollection();
78 1
        $this->movie = $movie;
79 1
        $this->user = $user;
80 1
        $this->locale = $locale;
81 1
        $this->text = $text;
82 1
        $this->isReview = true;
83 1
    }
84
85 1
    public function getId()
86
    {
87 1
        return $this->id;
88
    }
89
90
    public function setText($text): void
91
    {
92
        $this->text = $text;
93
    }
94
95 1
    public function getText()
96
    {
97 1
        return $this->text;
98
    }
99
100
    public function getLocale()
101
    {
102
        return $this->locale;
103
    }
104
105
    public function setLocale($locale): void
106
    {
107
        $this->locale = $locale;
108
    }
109
110
    public function setMovie(Movie $movie): void
111
    {
112
        $this->movie = $movie;
113
    }
114
115
    public function setUser(User $user): void
116
    {
117
        $this->user = $user;
118
    }
119
120
    public function getMovie(): Movie
121
    {
122
        return $this->movie;
123
    }
124
125 1
    public function getUser(): User
126
    {
127 1
        return $this->user;
128
    }
129
130
    public function getAnswers()
131
    {
132
        return $this->answers;
133
    }
134
135
    public function setAnswerTo(MovieReview $movieReview)
136
    {
137
        $this->isReview = false;
138
        $this->answerTo = $movieReview;
139
    }
140
141 1
    public function getUserWatchedMovie()
142
    {
143 1
        return $this->userWatchedMovie;
144
    }
145
}
146