Passed
Pull Request — master (#2295)
by Nico
05:09
created

AllianceRelation::hasText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\JoinColumn;
13
use Doctrine\ORM\Mapping\ManyToOne;
14
use Doctrine\ORM\Mapping\Table;
15
use Stu\Component\Alliance\Enum\AllianceRelationTypeEnum;
16
use Stu\Orm\Attribute\TruncateOnGameReset;
17
use Stu\Orm\Repository\AllianceRelationRepository;
18
19
#[Table(name: 'stu_alliances_relations')]
20
#[Index(name: 'alliance_relation_idx', columns: ['alliance_id', 'recipient'])]
21
#[Entity(repositoryClass: AllianceRelationRepository::class)]
22
#[TruncateOnGameReset]
23
class AllianceRelation
24
{
25
    #[Id]
26
    #[Column(type: 'integer')]
27
    #[GeneratedValue(strategy: 'IDENTITY')]
28
    private int $id;
29
30
    #[Column(type: 'smallint', enumType: AllianceRelationTypeEnum::class)]
31
    private AllianceRelationTypeEnum $type = AllianceRelationTypeEnum::FRIENDS;
32
33
    #[Column(type: 'integer')]
34
    private int $alliance_id = 0;
35
36
    #[Column(type: 'integer')]
37
    private int $recipient = 0;
38
39
    #[Column(type: 'integer')]
40
    private int $date = 0;
41
42
    #[Column(type: 'text', nullable: true)]
43
    private ?string $text = null;
44
45
    #[Column(type: 'integer', nullable: true)]
46
    private ?int $last_edited = null;
47
48
    #[ManyToOne(targetEntity: Alliance::class)]
49
    #[JoinColumn(name: 'alliance_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
50
    private Alliance $alliance;
51
52
    #[ManyToOne(targetEntity: Alliance::class)]
53
    #[JoinColumn(name: 'recipient', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
54
    private Alliance $opponent;
55
56
    public function getId(): int
57
    {
58
        return $this->id;
59
    }
60
61
    public function getType(): AllianceRelationTypeEnum
62
    {
63
        return $this->type;
64
    }
65
66
    public function setType(AllianceRelationTypeEnum $type): AllianceRelation
67
    {
68
        $this->type = $type;
69
        return $this;
70
    }
71
72
    public function getAllianceId(): int
73
    {
74
        return $this->alliance_id;
75
    }
76
77
    public function getOpponentId(): int
78
    {
79
        return $this->recipient;
80
    }
81
82
    public function getDate(): int
83
    {
84
        return $this->date;
85
    }
86
87
    public function setDate(int $date): AllianceRelation
88
    {
89
        $this->date = $date;
90
        return $this;
91
    }
92
93
    public function isPending(): bool
94
    {
95
        return $this->getDate() === 0;
96
    }
97
98
    public function isWar(): bool
99
    {
100
        return $this->getType() === AllianceRelationTypeEnum::WAR;
101
    }
102
103
    public function getAlliance(): Alliance
104
    {
105
        return $this->alliance;
106
    }
107
108
    public function setAlliance(Alliance $alliance): AllianceRelation
109
    {
110
        $this->alliance = $alliance;
111
112
        return $this;
113
    }
114
115
    public function getOpponent(): Alliance
116
    {
117
        return $this->opponent;
118
    }
119
120
    public function setOpponent(Alliance $opponent): AllianceRelation
121
    {
122
        $this->opponent = $opponent;
123
124
        return $this;
125
    }
126
127
    public function getText(): ?string
128
    {
129
        return $this->text;
130
    }
131
132
    public function setText(?string $text): AllianceRelation
133
    {
134
        $this->text = $text;
135
        return $this;
136
    }
137
138
    public function getLastEdited(): ?int
139
    {
140
        return $this->last_edited;
141
    }
142
143
    public function setLastEdited(?int $lastEdited): AllianceRelation
144
    {
145
        $this->last_edited = $lastEdited;
146
        return $this;
147
    }
148
149
    public function hasText(): bool
150
    {
151
        return $this->text !== null && trim($this->text) !== '';
152
    }
153
}
154