Completed
Push — master ( d44c39...321b0a )
by Valentyn
04:27
created

WatchedMovie   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 74.07%

Importance

Changes 0
Metric Value
wmc 11
lcom 3
cbo 0
dl 0
loc 86
ccs 20
cts 27
cp 0.7407
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A updateMovie() 0 4 1
A changeVote() 0 12 4
A changeWatchedAt() 0 4 1
A getMovie() 0 4 1
A getVote() 0 4 1
A getWatchedAt() 0 4 1
A getAddedAt() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Movies\Entity;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Doctrine\ORM\Mapping\MappedSuperclass;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
/** @MappedSuperclass */
12
class WatchedMovie
13
{
14
    /**
15
     * @ORM\ManyToOne(targetEntity="App\Movies\Entity\Movie")
16
     * @ORM\JoinColumn(nullable=false)
17
     */
18
    protected $movie;
19
20
    /**
21
     * @Groups({"list", "view"})
22
     * @ORM\Column(type="decimal", nullable=true)
23
     */
24
    protected $vote;
25
26
    /**
27
     * @Groups({"list", "view"})
28
     * @ORM\Column(type="datetime", nullable=false)
29
     */
30
    protected $addedAt;
31
32
    /**
33
     * @Groups({"list", "view"})
34
     * @ORM\Column(type="date", nullable=true)
35
     */
36
    protected $watchedAt;
37
38
    /**
39
     * WatchedMovie constructor.
40
     *
41
     * @param Movie                   $movie
42
     * @param float|null              $vote
43
     * @param \DateTimeInterface|null $watchedAt
44
     *
45
     * @throws \Exception
46
     */
47 10
    public function __construct(Movie $movie, ?float $vote, ?\DateTimeInterface $watchedAt)
48
    {
49 10
        $this->movie = $movie;
50 10
        $this->addedAt = new \DateTimeImmutable();
51 10
        $this->watchedAt = $watchedAt;
52 10
        $this->changeVote($vote);
53 10
    }
54
55
    public function updateMovie(Movie $movie)
56
    {
57
        $this->movie = $movie;
58
    }
59
60 10
    public function changeVote(?float $vote)
61
    {
62 10
        if ($vote === null) {
63
            $this->vote = $vote;
64
        }
65
66 10
        if ($vote < 0.0 || $vote > 10.0) {
67
            throw new \InvalidArgumentException('Vote can\'t be less than 0 or greater than 10');
68
        }
69
70 10
        $this->vote = (float) $vote;
71 10
    }
72
73 2
    public function changeWatchedAt(?\DateTimeInterface $watchedAt)
74
    {
75 2
        $this->watchedAt = $watchedAt;
76 2
    }
77
78 10
    public function getMovie(): ?Movie
79
    {
80 10
        return $this->movie;
81
    }
82
83 1
    public function getVote(): ?float
84
    {
85 1
        return (float) $this->vote;
86
    }
87
88
    public function getAddedAt(): ?\DateTimeInterface
89
    {
90
        return $this->addedAt;
91
    }
92
93 1
    public function getWatchedAt(): ?\DateTimeInterface
94
    {
95 1
        return $this->watchedAt;
96
    }
97
}
98