Rule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
11
use Gedmo\Timestampable\Traits\TimestampableEntity;
12
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
13
use Symfony\Component\Validator\Constraints as Assert;
14
use VideoGamesRecords\CoreBundle\Repository\RuleRepository;
15
16
#[ORM\Table(name:'vgr_rule')]
17
#[ORM\Entity(repositoryClass: RuleRepository::class)]
18
#[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\RuleListener"])]
19
class Rule implements TranslatableInterface
20
{
21
    use TranslatableTrait;
22
    use TimestampableEntity;
23
24
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
25
    private ?int $id = null;
26
27
    #[Assert\Length(min:3, max: 100)]
28
    #[ORM\Column(length: 100, nullable: false, unique: true)]
29
    private string $name;
30
31
    #[ORM\ManyToOne(targetEntity: Player::class)]
32
    #[ORM\JoinColumn(name:'player_id', referencedColumnName:'id', nullable:true)]
33
    private ?Player $player;
34
35
    /**
36
     * @var Collection<int, Game>
37
     */
38
    #[Orm\ManyToMany(targetEntity: Game::class, mappedBy: 'rules')]
39
    private Collection $games;
40
41
    public function __construct()
42
    {
43
        $this->games = new ArrayCollection();
44
    }
45
46
    public function __toString()
47
    {
48
        return sprintf('%s [%s]', $this->getName(), $this->id);
49
    }
50
51
    public function setId(int $id): void
52
    {
53
        $this->id = $id;
54
    }
55
56
    public function getId(): ?int
57
    {
58
        return $this->id;
59
    }
60
61
    public function setName(string $name): void
62
    {
63
        $this->name = $name;
64
    }
65
66
    public function getName(): ?string
67
    {
68
        return $this->name;
69
    }
70
71
    public function setPlayer(Player $player): void
72
    {
73
        $this->player = $player;
74
    }
75
76
    public function getPlayer(): ?Player
77
    {
78
        return $this->player;
79
    }
80
81
    public function setText(string $text): void
82
    {
83
        $this->translate(null, false)->setText($text);
0 ignored issues
show
Bug introduced by
The method setText() does not exist on Knp\DoctrineBehaviors\Co...ty\TranslationInterface. It seems like you code against a sub-type of Knp\DoctrineBehaviors\Co...ty\TranslationInterface such as VideoGamesRecords\CoreBu...\Entity\RuleTranslation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        $this->translate(null, false)->/** @scrutinizer ignore-call */ setText($text);
Loading history...
84
    }
85
86
    public function getText(): ?string
87
    {
88
        return $this->translate(null, false)->getText();
0 ignored issues
show
Bug introduced by
The method getText() does not exist on Knp\DoctrineBehaviors\Co...ty\TranslationInterface. It seems like you code against a sub-type of Knp\DoctrineBehaviors\Co...ty\TranslationInterface such as VideoGamesRecords\CoreBu...\Entity\RuleTranslation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
        return $this->translate(null, false)->/** @scrutinizer ignore-call */ getText();
Loading history...
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getDefaultText(): string
95
    {
96
        return $this->translate('en', false)->getText();
97
    }
98
99
    /**
100
     * @return Collection
101
     */
102
    public function getGames(): Collection
103
    {
104
        return $this->games;
105
    }
106
}
107