Completed
Push — master ( a97beb...5a8c67 )
by Tim
02:01
created

Index   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 365
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
wmc 33
lcom 3
cbo 5
dl 0
loc 365
rs 9.76
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
A getOriginalObject() 0 12 3
A getConfiguration() 0 10 3
A getStartDateComplete() 0 11 3
A getEndDateComplete() 0 11 3
A setForeignUid() 0 4 1
A getForeignUid() 0 4 1
A setUniqueRegisterKey() 0 4 1
A getUniqueRegisterKey() 0 4 1
A setForeignTable() 0 4 1
A getForeignTable() 0 4 1
A setAllDay() 0 4 1
A isAllDay() 0 4 1
A setEndDate() 0 4 1
A getEndDate() 0 4 1
A setEndTime() 0 4 1
A getEndTime() 0 4 1
A setStartDate() 0 4 1
A getStartDate() 0 4 1
A setStartTime() 0 4 1
A getStartTime() 0 4 1
A getState() 0 4 1
A setState() 0 4 1
A getSysLanguageUid() 0 4 1
A isOpenEndTime() 0 4 1
A setOpenEndTime() 0 4 1
1
<?php
2
3
/**
4
 * Index information.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Domain\Model;
9
10
use HDNET\Calendarize\Exception;
11
use HDNET\Calendarize\Register;
12
use HDNET\Calendarize\Utility\DateTimeUtility;
13
use HDNET\Calendarize\Utility\EventUtility;
14
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
15
16
/**
17
 * Index information.
18
 *
19
 * @db
20
 * @smartExclude Workspaces
21
 */
22
class Index extends AbstractModel
23
{
24
    /**
25
     * The unique register key of the used table/model configuration.
26
     *
27
     * @var string
28
     * @db varchar(150) DEFAULT '' NOT NULL
29
     */
30
    protected $uniqueRegisterKey;
31
32
    /**
33
     * TableName.
34
     *
35
     * @var string
36
     * @db varchar(150) DEFAULT '' NOT NULL
37
     */
38
    protected $foreignTable;
39
40
    /**
41
     * The Id of the foreign element.
42
     *
43
     * @var int
44
     * @db
45
     */
46
    protected $foreignUid;
47
48
    /**
49
     * Start date.
50
     *
51
     * @var \DateTime
52
     * @db
53
     */
54
    protected $startDate;
55
56
    /**
57
     * End date.
58
     *
59
     * @var \DateTime
60
     * @db
61
     */
62
    protected $endDate;
63
64
    /**
65
     * Start time.
66
     *
67
     * @var int
68
     * @db
69
     */
70
    protected $startTime;
71
72
    /**
73
     * End time.
74
     *
75
     * @var int
76
     * @db
77
     */
78
    protected $endTime;
79
80
    /**
81
     * AllDay.
82
     *
83
     * @var bool
84
     * @db
85
     */
86
    protected $allDay;
87
88
    /**
89
     * OpenEndTime.
90
     *
91
     * @var bool
92
     * @db
93
     */
94
    protected $openEndTime;
95
96
    /**
97
     * State.
98
     *
99
     * @var string
100
     * @db
101
     */
102
    protected $state;
103
104
    /**
105
     * The original object.
106
     *
107
     * @var AbstractEntity
108
     */
109
    protected $originalObject;
110
111
    /**
112
     * Get the original record for the current index.
113
     *
114
     * @throws Exception
115
     *
116
     * @return AbstractEntity
117
     */
118
    public function getOriginalObject()
119
    {
120
        if (null === $this->originalObject) {
121
            $configuration = $this->getConfiguration();
122
            if (empty($configuration)) {
123
                throw new Exception('No valid configuration for the current index: ' . $this->getUniqueRegisterKey(), 123678123);
124
            }
125
            $this->originalObject = EventUtility::getOriginalRecordByConfiguration($configuration, (int) $this->getForeignUid());
126
        }
127
128
        return $this->originalObject;
129
    }
130
131
    /**
132
     * Get the current configuration.
133
     *
134
     * @return array
135
     */
136
    public function getConfiguration(): array
137
    {
138
        foreach (Register::getRegister() as $key => $configuration) {
139
            if ($this->getUniqueRegisterKey() === $key) {
140
                return $configuration;
141
            }
142
        }
143
144
        return [];
145
    }
146
147
    /**
148
     * Get the complete start date.
149
     *
150
     * @return \DateTime
151
     */
152
    public function getStartDateComplete()
153
    {
154
        $date = $this->getStartDate();
155
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
156
            $time = DateTimeUtility::normalizeDateTimeSingle($this->getStartTime());
157
158
            return \DateTime::createFromFormat('Y-m-d H:i', $date->format('Y-m-d') . ' ' . $time->format('H:i'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor... $time->format('H:i')); of type DateTime|false adds false to the return on line 158 which is incompatible with the return type documented by HDNET\Calendarize\Domain...x::getStartDateComplete of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
159
        }
160
161
        return $date;
162
    }
163
164
    /**
165
     * Get the complete end date.
166
     *
167
     * @return \DateTime
168
     */
169
    public function getEndDateComplete()
170
    {
171
        $date = $this->getEndDate();
172
        if (!$this->isAllDay() && $date instanceof \DateTimeInterface) {
173
            $time = DateTimeUtility::normalizeDateTimeSingle($this->getEndTime());
174
175
            return \DateTime::createFromFormat('Y-m-d H:i', $date->format('Y-m-d') . ' ' . $time->format('H:i'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor... $time->format('H:i')); of type DateTime|false adds false to the return on line 175 which is incompatible with the return type documented by HDNET\Calendarize\Domain...dex::getEndDateComplete of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
176
        }
177
178
        return $date;
179
    }
180
181
    /**
182
     * Set foreign uid.
183
     *
184
     * @param int $foreignUid
185
     */
186
    public function setForeignUid($foreignUid)
187
    {
188
        $this->foreignUid = $foreignUid;
189
    }
190
191
    /**
192
     * Get foreign uid.
193
     *
194
     * @return int
195
     */
196
    public function getForeignUid()
197
    {
198
        return $this->foreignUid;
199
    }
200
201
    /**
202
     * Set unique register key.
203
     *
204
     * @param string $uniqueRegisterKey
205
     */
206
    public function setUniqueRegisterKey($uniqueRegisterKey)
207
    {
208
        $this->uniqueRegisterKey = $uniqueRegisterKey;
209
    }
210
211
    /**
212
     * Get unique register key.
213
     *
214
     * @return string
215
     */
216
    public function getUniqueRegisterKey()
217
    {
218
        return $this->uniqueRegisterKey;
219
    }
220
221
    /**
222
     * Set foreign table.
223
     *
224
     * @param string $foreignTable
225
     */
226
    public function setForeignTable($foreignTable)
227
    {
228
        $this->foreignTable = $foreignTable;
229
    }
230
231
    /**
232
     * Get foreign table.
233
     *
234
     * @return string
235
     */
236
    public function getForeignTable()
237
    {
238
        return $this->foreignTable;
239
    }
240
241
    /**
242
     * Set all day.
243
     *
244
     * @param bool $allDay
245
     */
246
    public function setAllDay($allDay)
247
    {
248
        $this->allDay = $allDay;
249
    }
250
251
    /**
252
     * Is all day.
253
     *
254
     * @return bool
255
     */
256
    public function isAllDay()
257
    {
258
        return (bool) $this->allDay;
259
    }
260
261
    /**
262
     * Set end date.
263
     *
264
     * @param \DateTime $endDate
265
     */
266
    public function setEndDate($endDate)
267
    {
268
        $this->endDate = $endDate;
269
    }
270
271
    /**
272
     * Get end date.
273
     *
274
     * @return \DateTime
275
     */
276
    public function getEndDate()
277
    {
278
        return $this->endDate;
279
    }
280
281
    /**
282
     * Set end time.
283
     *
284
     * @param int $endTime
285
     */
286
    public function setEndTime($endTime)
287
    {
288
        $this->endTime = $endTime;
289
    }
290
291
    /**
292
     * Get end time.
293
     *
294
     * @return int
295
     */
296
    public function getEndTime()
297
    {
298
        return $this->endTime;
299
    }
300
301
    /**
302
     * Set start date.
303
     *
304
     * @param \DateTime $startDate
305
     */
306
    public function setStartDate($startDate)
307
    {
308
        $this->startDate = $startDate;
309
    }
310
311
    /**
312
     * Get start date.
313
     *
314
     * @return \DateTime
315
     */
316
    public function getStartDate()
317
    {
318
        return $this->startDate;
319
    }
320
321
    /**
322
     * Set start time.
323
     *
324
     * @param int $startTime
325
     */
326
    public function setStartTime($startTime)
327
    {
328
        $this->startTime = $startTime;
329
    }
330
331
    /**
332
     * Get start time.
333
     *
334
     * @return int
335
     */
336
    public function getStartTime()
337
    {
338
        return $this->startTime;
339
    }
340
341
    /**
342
     * Get state.
343
     *
344
     * @return string
345
     */
346
    public function getState()
347
    {
348
        return $this->state;
349
    }
350
351
    /**
352
     * Set state.
353
     *
354
     * @param string $state
355
     */
356
    public function setState($state)
357
    {
358
        $this->state = $state;
359
    }
360
361
    /**
362
     * Get sys language uid.
363
     *
364
     * @return int
365
     */
366
    public function getSysLanguageUid()
367
    {
368
        return (int) $this->_languageUid;
369
    }
370
371
    /**
372
     * @return bool
373
     */
374
    public function isOpenEndTime()
375
    {
376
        return $this->openEndTime;
377
    }
378
379
    /**
380
     * @param bool $openEndTime
381
     */
382
    public function setOpenEndTime($openEndTime)
383
    {
384
        $this->openEndTime = $openEndTime;
385
    }
386
}
387