Completed
Push — master ( 57fac9...43d856 )
by Valentyn
02:37
created

WatchedMovie   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 70
ccs 13
cts 18
cp 0.7221
rs 10
c 0
b 0
f 0

6 Methods

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