Passed
Push — develop ( 99478d...3bc85b )
by BENARD
02:21
created

Channel::setIsCommunity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\TwitchBundle\Entity;
6
7
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
8
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
9
use ApiPlatform\Metadata\ApiFilter;
10
use ApiPlatform\Metadata\ApiResource;
11
use ApiPlatform\Metadata\Get;
12
use ApiPlatform\Metadata\GetCollection;
13
use Doctrine\ORM\Mapping as ORM;
14
use ProjetNormandie\TwitchBundle\Controller\Channel\GetStream;
15
use ProjetNormandie\TwitchBundle\Repository\ChannelRepository;
16
use Symfony\Component\Serializer\Annotation\Groups;
17
use Symfony\Component\Validator\Constraints as Assert;
18
19
#[ORM\Table(name:'pnt_channel')]
20
#[ORM\Entity(repositoryClass: ChannelRepository::class)]
21
#[ApiResource(
22
    order: ['name' => 'ASC'],
23
    routePrefix: '/twitch',
24
    operations: [
25
        new GetCollection(),
26
        new Get(),
27
        new Get(
28
            uriTemplate: '/channels/{id}/get-stream',
29
            controller: GetStream::class,
30
        ),
31
    ],
32
    normalizationContext: ['groups' => ['twitch:read']
33
    ]
34
)]
35
#[ApiFilter(
36
    SearchFilter::class,
37
    properties: [
38
        'id' => 'exact',
39
        'isCommunity' => 'exact',
40
    ]
41
)]
42
#[ApiFilter(
43
    OrderFilter::class,
44
    properties: [
45
        'id' => 'ASC',
46
        'name' => 'ASC',
47
    ]
48
)]
49
class Channel
50
{
51
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
52
    private int $id;
53
54
    #[Groups(['twitch:read'])]
55
    #[Assert\Length(max: 255)]
56
    #[ORM\Column(length: 255, nullable: false)]
57
    private string $name;
58
59
    #[Groups(['twitch:read'])]
60
    #[Assert\Length(max: 255)]
61
    #[ORM\Column(length: 255, nullable: false)]
62
    private string $username;
63
64
    #[Groups(['twitch:read'])]
65
    #[ORM\Column]
66
    private bool $isCommunity = false;
67
68
    public function getId(): int
69
    {
70
        return $this->id;
71
    }
72
73
    public function setId(int $id): void
74
    {
75
        $this->id = $id;
76
    }
77
78
    public function getName(): string
79
    {
80
        return $this->name;
81
    }
82
83
    public function setName(string $name): void
84
    {
85
        $this->name = $name;
86
    }
87
88
    public function getUsername(): string
89
    {
90
        return $this->username;
91
    }
92
93
    public function setUsername(string $username): void
94
    {
95
        $this->username = $username;
96
    }
97
98
    #[Groups(['twitch:read'])]
99
    public function getInitial(): string
100
    {
101
        return substr($this->name, 0, 1);
102
    }
103
104
    public function isCommunity(): bool
105
    {
106
        return $this->isCommunity;
107
    }
108
109
    public function setIsCommunity(bool $isCommunity): void
110
    {
111
        $this->isCommunity = $isCommunity;
112
    }
113
114
    public function __toString()
115
    {
116
        return $this->getName();
117
    }
118
}
119