VideoComment   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 35
c 1
b 0
f 0
dl 0
loc 72
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getVideo() 0 3 1
A setId() 0 3 1
A setVideo() 0 3 1
A __toString() 0 3 1
A getId() 0 3 1
A setContent() 0 3 1
A getContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Entity;
6
7
use ApiPlatform\Metadata\ApiResource;
8
use ApiPlatform\Metadata\Get;
9
use ApiPlatform\Metadata\GetCollection;
10
use ApiPlatform\Metadata\Link;
11
use ApiPlatform\Metadata\Post;
12
use Doctrine\ORM\Mapping as ORM;
13
use Gedmo\Timestampable\Traits\TimestampableEntity;
14
use Symfony\Component\Validator\Constraints as Assert;
15
use VideoGamesRecords\CoreBundle\Repository\VideoCommentRepository;
16
use VideoGamesRecords\CoreBundle\Traits\Entity\Player\PlayerTrait;
17
18
#[ORM\Table(name:'vgr_video_comment')]
19
#[ORM\Entity(repositoryClass: VideoCommentRepository::class)]
20
#[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\VideoCommentListener"])]
21
#[ApiResource(
22
    operations: [
23
        new GetCollection(),
24
        new Get(),
25
        new Post(
26
            denormalizationContext: ['groups' => ['video-comment:insert']],
27
            security: 'is_granted("ROLE_PLAYER")'
28
        ),
29
    ],
30
    normalizationContext: ['groups' => ['video-comment:read', 'video-comment:player', 'player:read']]
31
)]
32
#[ApiResource(
33
    uriTemplate: '/videos/{id}/comments',
34
    uriVariables: [
35
        'id' => new Link(fromClass: Video::class, toProperty: 'video'),
36
    ],
37
    operations: [ new GetCollection() ],
38
    normalizationContext: ['groups' => ['video-comment:read', 'video-comment:player', 'player:read']],
39
)]
40
class VideoComment
41
{
42
    use TimestampableEntity;
43
    use PlayerTrait;
44
45
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
46
    private ?int $id = null;
47
48
    #[ORM\ManyToOne(targetEntity: Video::class, inversedBy: 'comments')]
49
    #[ORM\JoinColumn(name:'video_id', referencedColumnName:'id', nullable:false, onDelete: 'CASCADE')]
50
    private Video $video;
51
52
    #[Assert\NotBlank]
53
    #[ORM\Column(type: 'text', nullable: false)]
54
    private string $content;
55
56
    public function __toString()
57
    {
58
        return sprintf('comment [%s]', $this->id);
59
    }
60
61
    public function setId(int $id): void
62
    {
63
        $this->id = $id;
64
    }
65
66
    public function getId(): ?int
67
    {
68
        return $this->id;
69
    }
70
71
    public function getVideo(): Video
72
    {
73
        return $this->video;
74
    }
75
76
    public function setVideo(Video $video): void
77
    {
78
        $this->video = $video;
79
    }
80
81
82
    public function setContent(string $content): void
83
    {
84
        $this->content = $content;
85
    }
86
87
    public function getContent(): string
88
    {
89
        return $this->content;
90
    }
91
}
92