Game::setLastStreamAt()   A
last analyzed

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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\TwitchBundle\Entity;
6
7
8
use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter;
9
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
10
use ApiPlatform\Metadata\ApiFilter;
11
use ApiPlatform\Metadata\ApiProperty;
12
use ApiPlatform\Metadata\ApiResource;
13
use ApiPlatform\Metadata\Get;
14
use ApiPlatform\Metadata\GetCollection;
15
use DateTime;
16
use Doctrine\ORM\Mapping as ORM;
17
use ProjetNormandie\TwitchBundle\Repository\GameRepository;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
20
#[ORM\Table(name:'pnt_game')]
21
#[ORM\Entity(repositoryClass: GameRepository::class)]
22
#[ApiResource(
23
    routePrefix: '/twitch',
24
    operations: [
25
        new GetCollection(),
26
        new Get()
27
    ],
28
    normalizationContext: ['groups' => ['game:read']]
29
)]
30
#[ApiFilter(
31
    OrderFilter::class,
32
    properties: [
33
        'lastStreamAt' => 'DESC',
34
    ]
35
)]
36
#[ApiFilter(ExistsFilter::class, properties: ['picture'])]
37
class Game
38
{
39
    #[ApiProperty(identifier: true)]
40
    #[Groups(['game:read'])]
41
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
42
    protected ?int $id = null;
43
44
    #[ORM\Column(length: 20, unique: true)]
45
    protected string $externalId;
46
47
    #[Groups(['game:read'])]
48
    #[ORM\Column(length: 255, nullable: false)]
49
    private string $name = '';
50
51
    #[Groups(['game:read'])]
52
    #[ORM\Column(length: 255, nullable: true)]
53
    private ?string $picture = null;
54
55
    #[Groups(['game:read'])]
56
    #[ORM\Column(length: 255, nullable: true)]
57
    private ?string $url = null;
58
59
    #[Groups(['game:read'])]
60
    #[ORM\Column(nullable: false)]
61
    private DateTime $lastStreamAt;
62
63
    public function getId(): ?int
64
    {
65
        return $this->id;
66
    }
67
68
    public function setId(?int $id): void
69
    {
70
        $this->id = $id;
71
    }
72
73
    public function getExternalId(): string
74
    {
75
        return $this->externalId;
76
    }
77
78
    public function setExternalId(string $externalId): void
79
    {
80
        $this->externalId = $externalId;
81
    }
82
83
    public function getName(): string
84
    {
85
        return $this->name;
86
    }
87
88
    public function setName(string $name): void
89
    {
90
        $this->name = $name;
91
    }
92
93
    public function getPicture(): ?string
94
    {
95
        return $this->picture;
96
    }
97
98
    public function setPicture(?string $picture): void
99
    {
100
        $this->picture = $picture;
101
    }
102
103
    public function getUrl(): ?string
104
    {
105
        return $this->url;
106
    }
107
108
    public function setUrl(?string $url): void
109
    {
110
        $this->url = $url;
111
    }
112
113
    public function getLastStreamAt(): DateTime
114
    {
115
        return $this->lastStreamAt;
116
    }
117
118
    public function setLastStreamAt(DateTime $lastStreamAt): void
119
    {
120
        $this->lastStreamAt = $lastStreamAt;
121
    }
122
123
    public function __toString()
124
    {
125
        return sprintf('%s (%d)', $this->getName(), $this->getId());
126
    }
127
}
128