Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.88% covered (warning)
87.88%
58 / 66
91.84% covered (success)
91.84%
45 / 49
CRAP
0.00% covered (danger)
0.00%
0 / 1
SolvEvent
87.88% covered (warning)
87.88%
58 / 66
91.84% covered (success)
91.84%
45 / 49
58.00
0.00% covered (danger)
0.00%
0 / 1
 getSolvUid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSolvUid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDuration
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDuration
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getKind
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setKind
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDayNight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDayNight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNational
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNational
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRegion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRegion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getClub
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setClub
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLocation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLocation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCoordX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCoordX
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCoordY
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCoordY
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDeadline
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDeadline
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEntryportal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEntryportal
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStartLink
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setStartLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRankLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRankLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLastModification
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLastModification
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFieldValue
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setFieldValue
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 testOnlyGetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdFieldNameForSearch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdForSearch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitleForSearch
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCriteriaForFilter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCriteriaForQuery
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 parseSearchDateRange
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Olz\Entity;
4
5use Doctrine\Common\Collections\Criteria;
6use Doctrine\Common\Collections\Expr\Expression;
7use Doctrine\ORM\Mapping as ORM;
8use Olz\Common\Utils\DateUtils;
9use Olz\Common\Utils\WithUtilsCache;
10use Olz\Entity\Common\SearchableInterface;
11use Olz\Entity\Common\TestableInterface;
12use Olz\Repository\SolvEventRepository;
13
14#[ORM\Table(name: 'solv_events')]
15#[ORM\Index(name: 'date_index', columns: ['date'])]
16#[ORM\Entity(repositoryClass: SolvEventRepository::class)]
17class SolvEvent implements SearchableInterface, TestableInterface {
18    #[ORM\Id]
19    #[ORM\Column(type: 'integer', nullable: false)]
20    private int $solv_uid;
21
22    #[ORM\Column(type: 'date', nullable: false)]
23    private \DateTime $date;
24
25    #[ORM\Column(type: 'integer', nullable: false)]
26    private int $duration;
27
28    #[ORM\Column(type: 'text', nullable: false)]
29    private string $kind;
30
31    #[ORM\Column(type: 'text', nullable: false)]
32    private string $day_night;
33
34    #[ORM\Column(type: 'integer', nullable: false)]
35    private int $national;
36
37    #[ORM\Column(type: 'text', nullable: false)]
38    private string $region;
39
40    #[ORM\Column(type: 'text', nullable: false)]
41    private string $type;
42
43    #[ORM\Column(type: 'text', nullable: false)]
44    private string $name;
45
46    #[ORM\Column(type: 'text', nullable: false)]
47    private string $link;
48
49    #[ORM\Column(type: 'text', nullable: false)]
50    private string $club;
51
52    #[ORM\Column(type: 'text', nullable: false)]
53    private string $map;
54
55    #[ORM\Column(type: 'text', nullable: false)]
56    private string $location;
57
58    #[ORM\Column(type: 'integer', nullable: false)]
59    private int $coord_x;
60
61    #[ORM\Column(type: 'integer', nullable: false)]
62    private int $coord_y;
63
64    #[ORM\Column(type: 'date', nullable: true)]
65    private ?\DateTime $deadline;
66
67    #[ORM\Column(type: 'integer', nullable: false)]
68    private int $entryportal;
69
70    #[ORM\Column(type: 'text', nullable: true)]
71    private ?string $start_link;
72
73    #[ORM\Column(type: 'text', nullable: true)]
74    private ?string $rank_link;
75
76    #[ORM\Column(type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP'])]
77    private \DateTime $last_modification;
78
79    /** @var array<string, true> */
80    private array $valid_field_names = [
81        'solv_uid' => true,
82        'date' => true,
83        'duration' => true,
84        'kind' => true,
85        'day_night' => true,
86        'national' => true,
87        'region' => true,
88        'type' => true,
89        'name' => true,
90        'link' => true,
91        'club' => true,
92        'map' => true,
93        'location' => true,
94        'coord_x' => true,
95        'coord_y' => true,
96        'deadline' => true,
97        'entryportal' => true,
98        'start_link' => true,
99        'rank_link' => true,
100        'last_modification' => true,
101    ];
102    // PRIMARY KEY (`solv_uid`)
103
104    public function getSolvUid(): int {
105        return $this->solv_uid;
106    }
107
108    public function setSolvUid(int $new_value): void {
109        $this->solv_uid = $new_value;
110    }
111
112    public function getDate(): \DateTime {
113        return $this->date;
114    }
115
116    public function setDate(\DateTime $new_value): void {
117        $this->date = $new_value;
118    }
119
120    public function getDuration(): int {
121        return $this->duration;
122    }
123
124    public function setDuration(int $new_value): void {
125        $this->duration = $new_value;
126    }
127
128    public function getKind(): string {
129        return $this->kind;
130    }
131
132    public function setKind(string $new_value): void {
133        $this->kind = $new_value;
134    }
135
136    public function getDayNight(): string {
137        return $this->day_night;
138    }
139
140    public function setDayNight(string $new_value): void {
141        $this->day_night = $new_value;
142    }
143
144    public function getNational(): int {
145        return $this->national;
146    }
147
148    public function setNational(int $new_value): void {
149        $this->national = $new_value;
150    }
151
152    public function getRegion(): string {
153        return $this->region;
154    }
155
156    public function setRegion(string $new_value): void {
157        $this->region = $new_value;
158    }
159
160    public function getType(): string {
161        return $this->type;
162    }
163
164    public function setType(string $new_value): void {
165        $this->type = $new_value;
166    }
167
168    public function getName(): string {
169        return $this->name;
170    }
171
172    public function setName(string $new_value): void {
173        $this->name = $new_value;
174    }
175
176    public function getLink(): string {
177        return $this->link;
178    }
179
180    public function setLink(string $new_value): void {
181        $this->link = $new_value;
182    }
183
184    public function getClub(): string {
185        return $this->club;
186    }
187
188    public function setClub(string $new_value): void {
189        $this->club = $new_value;
190    }
191
192    public function getMap(): string {
193        return $this->map;
194    }
195
196    public function setMap(string $new_value): void {
197        $this->map = $new_value;
198    }
199
200    public function getLocation(): string {
201        return $this->location;
202    }
203
204    public function setLocation(string $new_value): void {
205        $this->location = $new_value;
206    }
207
208    public function getCoordX(): int {
209        return $this->coord_x;
210    }
211
212    public function setCoordX(int $new_value): void {
213        $this->coord_x = $new_value;
214    }
215
216    public function getCoordY(): int {
217        return $this->coord_y;
218    }
219
220    public function setCoordY(int $new_value): void {
221        $this->coord_y = $new_value;
222    }
223
224    public function getDeadline(): ?\DateTime {
225        return $this->deadline;
226    }
227
228    public function setDeadline(?\DateTime $new_value): void {
229        $this->deadline = $new_value;
230    }
231
232    public function getEntryportal(): int {
233        return $this->entryportal;
234    }
235
236    public function setEntryportal(int $new_value): void {
237        $this->entryportal = $new_value;
238    }
239
240    public function getStartLink(): ?string {
241        return $this->start_link;
242    }
243
244    public function setStartLink(?string $new_value): void {
245        $this->start_link = $new_value;
246    }
247
248    public function getRankLink(): ?string {
249        return $this->rank_link;
250    }
251
252    public function setRankLink(?string $new_value): void {
253        $this->rank_link = $new_value;
254    }
255
256    public function getLastModification(): \DateTime {
257        return $this->last_modification;
258    }
259
260    public function setLastModification(\DateTime $new_value): void {
261        $this->last_modification = $new_value;
262    }
263
264    public function getFieldValue(string $field_name): mixed {
265        if (!isset($this->valid_field_names[$field_name])) {
266            throw new \Exception("getFieldValue: Invalid field name: {$field_name}", 1);
267        }
268        return $this->{$field_name};
269    }
270
271    public function setFieldValue(string $field_name, mixed $new_value): void {
272        if (!isset($this->valid_field_names[$field_name])) {
273            throw new \Exception("setFieldValue: Invalid field name: {$field_name}", 1);
274        }
275        $this->{$field_name} = $new_value;
276    }
277
278    // ---
279
280    public function testOnlyGetField(string $field_name): mixed {
281        return $this->{$field_name};
282    }
283
284    public static function getIdFieldNameForSearch(): string {
285        return 'solv_uid';
286    }
287
288    public function getIdForSearch(): int {
289        return $this->getSolvUid();
290    }
291
292    public function getTitleForSearch(): string {
293        $pretty_date = $this->getDate()->format('Y-m-d');
294        return "{$pretty_date}: {$this->getName()}";
295    }
296
297    public static function getCriteriaForFilter(string $key, string $value): Expression {
298        throw new \Exception("No such SolvEvent filter: {$key}");
299    }
300
301    public static function getCriteriaForQuery(string $query): Expression {
302        $range = self::parseSearchDateRange($query);
303        if (!$range) {
304            return Criteria::expr()->contains('name', $query);
305        }
306        return Criteria::expr()->orX(
307            Criteria::expr()->andX(
308                Criteria::expr()->gte('date', $range['start']),
309                Criteria::expr()->lt('date', $range['end']),
310            ),
311            Criteria::expr()->contains('name', $query),
312        );
313    }
314
315    /**
316     * Entities are not services, so `DateUtils` can never be injected into
317     * `SolvEvent`. It is therefore read from the global `WithUtilsCache`, and
318     * this fails loudly if no service has warmed that cache yet.
319     *
320     * @return ?array{start:\DateTime, end:\DateTime}
321     */
322    private static function parseSearchDateRange(string $query): ?array {
323        $date_utils = WithUtilsCache::get('dateUtils');
324        if (!$date_utils instanceof DateUtils) {
325            throw new \RuntimeException('SolvEvent::getCriteriaForQuery() requires a warmed WithUtilsCache.');
326        }
327        return $date_utils->parseDateTimeRange($query);
328    }
329}