Passed
Push — dev ( 45bf8d...5b8f46 )
by Janko
10:07
created

Anomaly::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
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\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\Table;
18
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Stu\Orm\Repository\AnomalyRepository;
21
22
#[Table(name: 'stu_anomaly')]
23
#[Index(name: 'anomaly_to_type_idx', columns: ['anomaly_type_id'])]
24
#[Index(name: 'anomaly_remaining_idx', columns: ['remaining_ticks'])]
25
#[Entity(repositoryClass: AnomalyRepository::class)]
26
class Anomaly implements AnomalyInterface
27
{
28
    #[Id]
29
    #[Column(type: 'integer')]
30
    #[GeneratedValue(strategy: 'IDENTITY')]
31
    private int $id;
32
33
    #[Column(type: 'integer')]
34
    private int $remaining_ticks;
35
36
    #[Column(type: 'integer')]
37
    private int $anomaly_type_id;
0 ignored issues
show
introduced by
The private property $anomaly_type_id is not used, and could be removed.
Loading history...
38
39
    #[Column(type: 'integer', nullable: true)]
40
    private ?int $location_id = null;
0 ignored issues
show
introduced by
The private property $location_id is not used, and could be removed.
Loading history...
41
42
    #[Column(type: 'integer', nullable: true)]
43
    private ?int $parent_id = null;
0 ignored issues
show
introduced by
The private property $parent_id is not used, and could be removed.
Loading history...
44
45
    #[Column(type: 'text', nullable: true)]
46
    private ?string $data = null;
47
48
    #[ManyToOne(targetEntity: 'AnomalyType')]
49
    #[JoinColumn(name: 'anomaly_type_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
50
    private AnomalyTypeInterface $anomalyType;
51
52
    #[ManyToOne(targetEntity: 'Location')]
53
    #[JoinColumn(name: 'location_id', referencedColumnName: 'id')]
54
    private ?LocationInterface $location;
55
56
    #[ManyToOne(targetEntity: 'Anomaly')]
57
    #[JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
58
    private ?AnomalyInterface $parent;
59
60
    /**
61
     * @var ArrayCollection<int, AnomalyInterface>
62
     */
63
    #[OneToMany(targetEntity: 'Anomaly', mappedBy: 'parent', indexBy: 'location_id')]
64
    private Collection $children;
65
66
    public function __construct()
67
    {
68
        $this->children = new ArrayCollection();
69
    }
70
71
    #[Override]
72
    public function getId(): int
73
    {
74
        return $this->id;
75
    }
76
77
    #[Override]
78
    public function getRemainingTicks(): int
79
    {
80
        return $this->remaining_ticks;
81
    }
82
83
    #[Override]
84
    public function setRemainingTicks(int $remainingTicks): AnomalyInterface
85
    {
86
        $this->remaining_ticks = $remainingTicks;
87
88
        return $this;
89
    }
90
91
    #[Override]
92
    public function changeRemainingTicks(int $amount): AnomalyInterface
93
    {
94
        $this->remaining_ticks += $amount;
95
96
        return $this;
97
    }
98
99
    #[Override]
100
    public function isActive(): bool
101
    {
102
        return $this->getRemainingTicks() > 0;
103
    }
104
105
    #[Override]
106
    public function getAnomalyType(): AnomalyTypeInterface
107
    {
108
        return $this->anomalyType;
109
    }
110
111
    #[Override]
112
    public function setAnomalyType(AnomalyTypeInterface $anomalyType): AnomalyInterface
113
    {
114
        $this->anomalyType = $anomalyType;
115
116
        return $this;
117
    }
118
119
    #[Override]
120
    public function getLocation(): ?LocationInterface
121
    {
122
        return $this->location;
123
    }
124
125
    #[Override]
126
    public function setLocation(?LocationInterface $location): AnomalyInterface
127
    {
128
        $this->location = $location;
129
130
        return $this;
131
    }
132
133
    #[Override]
134
    public function getParent(): ?AnomalyInterface
135
    {
136
        return $this->parent;
137
    }
138
139
    #[Override]
140
    public function setParent(?AnomalyInterface $anomaly): AnomalyInterface
141
    {
142
        $this->parent = $anomaly;
143
144
        return $this;
145
    }
146
147
    #[Override]
148
    public function getData(): ?string
149
    {
150
        return $this->data;
151
    }
152
153
    #[Override]
154
    public function setData(string $data): AnomalyInterface
155
    {
156
        $this->data = $data;
157
        return $this;
158
    }
159
160
    #[Override]
161
    public function getRoot(): AnomalyInterface
162
    {
163
        $parent = $this->getParent();
164
165
        return $parent === null ? $this : $parent->getRoot();
166
    }
167
168
    #[Override]
169
    public function getChildren(): Collection
170
    {
171
        return $this->children;
172
    }
173
174
    #[Override]
175
    public function hasChildren(): bool
176
    {
177
        return !$this->getChildren()->isEmpty();
178
    }
179
180
    #[Override]
181
    public function getUserId(): int
182
    {
183
        return UserEnum::USER_NOONE;
184
    }
185
186
    #[Override]
187
    public function getName(): string
188
    {
189
        return $this->getAnomalyType()->getName();
190
    }
191
}
192