Passed
Push — master ( c12552...22ad80 )
by Gabor
04:56
created

FilesystemEntity   B

Complexity

Total Complexity 47

Size/Duplication

Total Lines 455
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 47
lcom 4
cbo 0
dl 0
loc 455
ccs 0
cts 201
cp 0
rs 8.439
c 0
b 0
f 0

40 Methods

Rating   Name   Duplication   Size   Complexity  
A setKeyData() 0 6 1
A getKeyData() 0 4 1
A setFilesystemId() 0 6 1
A getFilesystemId() 0 4 1
A setApplicationId() 0 6 1
A getApplicationId() 0 4 1
A setCategoryId() 0 6 1
A getCategoryId() 0 4 1
A setParentId() 0 6 1
A getParentId() 0 4 1
A resetType() 0 6 1
A getType() 0 16 4
A setDocumentId() 0 10 2
A getDocumentId() 0 4 1
A setFileId() 0 10 2
A getFileId() 0 4 1
A setDirectoryId() 0 10 2
A getDirectoryId() 0 4 1
A setLinkId() 0 10 2
A getLinkId() 0 4 1
A setPath() 0 6 1
A getPath() 0 4 1
A setBaseName() 0 6 1
A getBaseName() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A setDescription() 0 6 1
A getDescription() 0 4 1
A setHidden() 0 6 1
A getHidden() 0 4 1
A setReadOnly() 0 6 1
A getReadOnly() 0 4 1
A setDeleted() 0 6 1
A getDeleted() 0 4 1
A setDateCreated() 0 6 1
A getDateCreated() 0 4 1
A setDateModified() 0 6 1
A getDateModified() 0 4 1
A setDatePublished() 0 6 1
A getDatePublished() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like FilesystemEntity often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FilesystemEntity, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Data\Entity\Filesystem;
15
16
use WebHemi\Data\EntityInterface;
17
use WebHemi\DateTime;
18
19
/**
20
 * Class FilesystemEntity.
21
 */
22
class FilesystemEntity implements EntityInterface
23
{
24
    public const TYPE_DOCUMENT = 'document';
25
    public const TYPE_BINARY = 'binary';
26
    public const TYPE_DIRECTORY = 'directory';
27
    public const TYPE_SYMLINK = 'symlink';
28
29
    /** @var int */
30
    private $filesystemId;
31
    /** @var int */
32
    private $applicationId;
33
    /** @var int */
34
    private $categoryId;
35
    /** @var int */
36
    private $parentId;
37
    /** @var int */
38
    private $documentId;
39
    /** @var int */
40
    private $fileId;
41
    /** @var int */
42
    private $directoryId;
43
    /** @var int */
44
    private $linkId;
45
    /** @var string */
46
    private $path;
47
    /** @var string */
48
    private $baseName;
49
    /** @var string */
50
    private $title;
51
    /** @var string */
52
    private $description;
53
    /** @var bool */
54
    private $isHidden;
55
    /** @var bool */
56
    private $isReadOnly;
57
    /** @var bool */
58
    private $isDeleted;
59
    /** @var DateTime */
60
    private $dateCreated;
61
    /** @var DateTime */
62
    private $datePublished;
63
    /** @var DateTime */
64
    private $dateModified;
65
66
    /**
67
     * Sets the value of the entity identifier.
68
     *
69
     * @param int $entityId
70
     * @return FilesystemEntity
71
     */
72
    public function setKeyData(int $entityId) : FilesystemEntity
73
    {
74
        $this->filesystemId = $entityId;
75
76
        return $this;
77
    }
78
79
    /**
80
     * Gets the value of the entity identifier.
81
     *
82
     * @return null|int
83
     */
84
    public function getKeyData() : ? int
85
    {
86
        return $this->filesystemId;
87
    }
88
89
    /**
90
     * @param int $filesystemId
91
     * @return FilesystemEntity
92
     */
93
    public function setFilesystemId(int $filesystemId) : FilesystemEntity
94
    {
95
        $this->filesystemId = $filesystemId;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @return null|int
102
     */
103
    public function getFilesystemId() : ? int
104
    {
105
        return $this->filesystemId;
106
    }
107
108
    /**
109
     * @param int $applicationId
110
     * @return FilesystemEntity
111
     */
112
    public function setApplicationId(int $applicationId) : FilesystemEntity
113
    {
114
        $this->applicationId = $applicationId;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @return null|int
121
     */
122
    public function getApplicationId() : ? int
123
    {
124
        return $this->applicationId;
125
    }
126
127
    /**
128
     * @param null|int $categoryId
129
     * @return FilesystemEntity
130
     */
131
    public function setCategoryId(? int $categoryId) : FilesystemEntity
132
    {
133
        $this->categoryId = $categoryId;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @return null|int
140
     */
141
    public function getCategoryId() : ? int
142
    {
143
        return $this->categoryId;
144
    }
145
146
    /**
147
     * @param int|null $parentId
148
     * @return FilesystemEntity
149
     */
150
    public function setParentId(? int $parentId) : FilesystemEntity
151
    {
152
        $this->parentId = $parentId;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return null|int
159
     */
160
    public function getParentId() : ? int
161
    {
162
        return $this->parentId;
163
    }
164
165
    /**
166
     * @return FilesystemEntity
167
     */
168
    private function resetType() : FilesystemEntity
169
    {
170
        $this->documentId = $this->fileId = $this->directoryId = $this->linkId = null;
171
172
        return $this;
173
    }
174
175
    /**
176
     * @return null|string
177
     */
178
    public function getType() : ? string
179
    {
180
        if (!empty($this->fileId)) {
181
            return self::TYPE_BINARY;
182
        }
183
184
        if (!empty($this->directoryId)) {
185
            return self::TYPE_DIRECTORY;
186
        }
187
188
        if (!empty($this->linkId)) {
189
            return self::TYPE_SYMLINK;
190
        }
191
192
        return self::TYPE_DOCUMENT;
193
    }
194
195
    /**
196
     * @param int|null $documentId
197
     * @return FilesystemEntity
198
     */
199
    public function setDocumentId(? int $documentId) : FilesystemEntity
200
    {
201
        if (!empty($documentId)) {
202
            $this->resetType();
203
        }
204
205
        $this->documentId = $documentId;
206
207
        return $this;
208
    }
209
210
    /**
211
     * @return int|null
212
     */
213
    public function getDocumentId() : ? int
214
    {
215
        return $this->documentId;
216
    }
217
218
    /**
219
     * @param int|null $fileId
220
     * @return FilesystemEntity
221
     */
222
    public function setFileId(? int $fileId) : FilesystemEntity
223
    {
224
        if (!empty($fileId)) {
225
            $this->resetType();
226
        }
227
228
        $this->fileId = $fileId;
229
230
        return $this;
231
    }
232
233
    /**
234
     * @return int|null
235
     */
236
    public function getFileId() : ? int
237
    {
238
        return $this->fileId;
239
    }
240
241
    /**
242
     * @param int|null $directoryId
243
     * @return FilesystemEntity
244
     */
245
    public function setDirectoryId(? int $directoryId) : FilesystemEntity
246
    {
247
        if (!empty($directoryId)) {
248
            $this->resetType();
249
        }
250
251
        $this->directoryId = $directoryId;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return int|null
258
     */
259
    public function getDirectoryId() : ? int
260
    {
261
        return $this->directoryId;
262
    }
263
264
    /**
265
     * @param int|null $linkId
266
     * @return FilesystemEntity
267
     */
268
    public function setLinkId(? int $linkId) : FilesystemEntity
269
    {
270
        if (!empty($linkId)) {
271
            $this->resetType();
272
        }
273
274
        $this->linkId = $linkId;
275
276
        return $this;
277
    }
278
279
    /**
280
     * @return int|null
281
     */
282
    public function getLinkId() : ? int
283
    {
284
        return $this->linkId;
285
    }
286
287
    /**
288
     * @param string $path
289
     * @return FilesystemEntity
290
     */
291
    public function setPath(string $path) : FilesystemEntity
292
    {
293
        $this->path = $path;
294
295
        return $this;
296
    }
297
298
    /**
299
     * @return string
300
     */
301
    public function getPath() : string
302
    {
303
        return $this->path;
304
    }
305
306
    /**
307
     * @param string $baseName
308
     * @return FilesystemEntity
309
     */
310
    public function setBaseName(string $baseName) : FilesystemEntity
311
    {
312
        $this->baseName = $baseName;
313
314
        return $this;
315
    }
316
317
    /**
318
     * @return null|string
319
     */
320
    public function getBaseName() : ? string
321
    {
322
        return $this->baseName;
323
    }
324
325
    /**
326
     * @param string $title
327
     * @return FilesystemEntity
328
     */
329
    public function setTitle(string $title) : FilesystemEntity
330
    {
331
        $this->title = $title;
332
333
        return $this;
334
    }
335
336
    /**
337
     * @return null|string
338
     */
339
    public function getTitle() : ? string
340
    {
341
        return $this->title;
342
    }
343
344
    /**
345
     * @param string $description
346
     * @return FilesystemEntity
347
     */
348
    public function setDescription(string $description) : FilesystemEntity
349
    {
350
        $this->description = $description;
351
352
        return $this;
353
    }
354
355
    /**
356
     * @return null|string
357
     */
358
    public function getDescription() : ? string
359
    {
360
        return $this->description;
361
    }
362
363
    /**
364
     * @param bool $state
365
     * @return FilesystemEntity
366
     */
367
    public function setHidden(bool $state) : FilesystemEntity
368
    {
369
        $this->isHidden = $state;
370
371
        return $this;
372
    }
373
374
    /**
375
     * @return bool
376
     */
377
    public function getHidden() : bool
378
    {
379
        return $this->isHidden ?? false;
380
    }
381
382
    /**
383
     * @param bool $state
384
     * @return FilesystemEntity
385
     */
386
    public function setReadOnly(bool $state) : FilesystemEntity
387
    {
388
        $this->isReadOnly = $state;
389
390
        return $this;
391
    }
392
393
    /**
394
     * @return bool
395
     */
396
    public function getReadOnly() : bool
397
    {
398
        return $this->isReadOnly ?? false;
399
    }
400
401
    /**
402
     * @param bool $state
403
     * @return FilesystemEntity
404
     */
405
    public function setDeleted(bool $state) : FilesystemEntity
406
    {
407
        $this->isDeleted = $state;
408
409
        return $this;
410
    }
411
412
    /**
413
     * @return bool
414
     */
415
    public function getDeleted() : bool
416
    {
417
        return $this->isDeleted ?? false;
418
    }
419
420
    /**
421
     * @param DateTime $dateCreated
422
     * @return FilesystemEntity
423
     */
424
    public function setDateCreated(DateTime $dateCreated) : FilesystemEntity
425
    {
426
        $this->dateCreated = $dateCreated;
427
428
        return $this;
429
    }
430
431
    /**
432
     * @return null|DateTime
433
     */
434
    public function getDateCreated() : ? DateTime
435
    {
436
        return $this->dateCreated;
437
    }
438
439
    /**
440
     * @param DateTime $dateModified
441
     * @return FilesystemEntity
442
     */
443
    public function setDateModified(? DateTime $dateModified) : FilesystemEntity
444
    {
445
        $this->dateModified = $dateModified;
446
447
        return $this;
448
    }
449
450
    /**
451
     * @return null|DateTime
452
     */
453
    public function getDateModified() : ? DateTime
454
    {
455
        return $this->dateModified;
456
    }
457
458
    /**
459
     * @param DateTime $datePublished
460
     * @return FilesystemEntity
461
     */
462
    public function setDatePublished(? DateTime $datePublished) : FilesystemEntity
463
    {
464
        $this->datePublished = $datePublished;
465
466
        return $this;
467
    }
468
469
    /**
470
     * @return null|DateTime
471
     */
472
    public function getDatePublished() : ? DateTime
473
    {
474
        return $this->datePublished;
475
    }
476
}
477