Passed
Push — master ( e14a05...ed0db1 )
by Gabor
05:13
created

FilesystemEntity   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 430
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 430
ccs 125
cts 125
cp 1
rs 5.5555
c 0
b 0
f 0
wmc 56

39 Methods

Rating   Name   Duplication   Size   Complexity  
A setPath() 0 5 1
A getIsDeleted() 0 3 1
A getBaseName() 0 3 1
A setFilesystemId() 0 5 1
A getDatePublished() 0 5 2
A setIsHidden() 0 5 2
A getIsHidden() 0 3 1
A setIsReadOnly() 0 5 2
A getDateCreated() 0 5 2
A setBaseName() 0 5 1
A setTitle() 0 5 1
A setFilesystemFileId() 0 5 1
A getType() 0 12 4
A setCategoryId() 0 5 1
A getParentNodeId() 0 5 2
A setFilesystemDirectoryId() 0 5 1
A getFilesystemDocumentId() 0 5 2
A getTitle() 0 3 1
A getFilesystemFileId() 0 5 2
A setDatePublished() 0 5 1
A setParentNodeId() 0 5 1
A getDateModified() 0 5 2
A getIsReadOnly() 0 3 1
A setApplicationId() 0 5 1
A setDateModified() 0 5 1
A getDescription() 0 3 1
A setUri() 0 5 1
A setFilesystemLinkId() 0 5 1
A setDateCreated() 0 5 1
A getPath() 0 3 1
A getFilesystemLinkId() 0 5 2
A getApplicationId() 0 5 2
A getUri() 0 3 1
A setFilesystemDocumentId() 0 5 1
A getFilesystemId() 0 5 2
A getFilesystemDirectoryId() 0 5 2
A getCategoryId() 0 5 2
A setDescription() 0 5 1
A setIsDeleted() 0 5 2

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.

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 - 2018 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;
15
16
use WebHemi\DateTime;
17
18
/**
19
 * Class FilesystemEntity
20
 */
21
class FilesystemEntity extends AbstractEntity
22
{
23
    public const TYPE_DOCUMENT = 'document';
24
    public const TYPE_BINARY = 'binary';
25
    public const TYPE_DIRECTORY = 'directory';
26
    public const TYPE_SYMLINK = 'symlink';
27
28
    /**
29
     * @var array
30
     */
31
    protected $container = [
32
        'id_filesystem' => null,
33
        'fk_application' => null,
34
        'fk_category' => null,
35
        'fk_parent_node' => null,
36
        'fk_filesystem_document' => null,
37
        'fk_filesystem_file' => null,
38
        'fk_filesystem_directory' => null,
39
        'fk_filesystem_link' => null,
40
        'path' => null,
41
        'basename' => null,
42
        'uri' => null,
43
        'title' => null,
44
        'description' => null,
45
        'is_hidden' => null,
46
        'is_read_only' => null,
47
        'is_deleted' => null,
48
        'date_created' => null,
49
        'date_modified' => null,
50
        'date_published' => null,
51
    ];
52
53
    /**
54
     * @return null|string
55
     */
56 15
    public function getType() : ? string
57
    {
58 15
        if (!empty($this->container['fk_filesystem_file'])) {
59 7
            return self::TYPE_BINARY;
60
        }
61 8
        if (!empty($this->container['fk_filesystem_directory'])) {
62 4
            return self::TYPE_DIRECTORY;
63
        }
64 4
        if (!empty($this->container['fk_filesystem_link'])) {
65 2
            return self::TYPE_SYMLINK;
66
        }
67 2
        return self::TYPE_DOCUMENT;
68
    }
69
70
    /**
71
     * @param int $identifier
72
     * @return FilesystemEntity
73
     */
74 1
    public function setFilesystemId(int $identifier) : FilesystemEntity
75
    {
76 1
        $this->container['id_filesystem'] = $identifier;
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @return int|null
83
     */
84 1
    public function getFilesystemId() : ? int
85
    {
86 1
        return !is_null($this->container['id_filesystem'])
87 1
            ? (int) $this->container['id_filesystem']
88 1
            : null;
89
    }
90
91
    /**
92
     * @param int $applicationIdentifier
93
     * @return FilesystemEntity
94
     */
95 1
    public function setApplicationId(int $applicationIdentifier) : FilesystemEntity
96
    {
97 1
        $this->container['fk_application'] = $applicationIdentifier;
98
99 1
        return $this;
100
    }
101
102
    /**
103
     * @return int|null
104
     */
105 1
    public function getApplicationId() : ? int
106
    {
107 1
        return !is_null($this->container['fk_application'])
108 1
            ? (int) $this->container['fk_application']
109 1
            : null;
110
    }
111
112
    /**
113
     * @param int $categoryIdentifier
114
     * @return FilesystemEntity
115
     */
116 1
    public function setCategoryId(int $categoryIdentifier) : FilesystemEntity
117
    {
118 1
        $this->container['fk_category'] = $categoryIdentifier;
119
120 1
        return $this;
121
    }
122
123
    /**
124
     * @return int|null
125
     */
126 1
    public function getCategoryId() : ? int
127
    {
128 1
        return !is_null($this->container['fk_category'])
129 1
            ? (int) $this->container['fk_category']
130 1
            : null;
131
    }
132
133
    /**
134
     * @param null|int $parentNodeIdentifier
135
     * @return FilesystemEntity
136
     */
137 1
    public function setParentNodeId(? int $parentNodeIdentifier) : FilesystemEntity
138
    {
139 1
        $this->container['fk_parent_node'] = $parentNodeIdentifier;
140
141 1
        return $this;
142
    }
143
144
    /**
145
     * @return int|null
146
     */
147 1
    public function getParentNodeId() : ? int
148
    {
149 1
        return !is_null($this->container['fk_parent_node'])
150 1
            ? (int) $this->container['fk_parent_node']
151 1
            : null;
152
    }
153
154
    /**
155
     * @param null|int $documentIdentifier
156
     * @return FilesystemEntity
157
     */
158 1
    public function setFilesystemDocumentId(? int $documentIdentifier) : FilesystemEntity
159
    {
160 1
        $this->container['fk_filesystem_document'] = $documentIdentifier;
161
162 1
        return $this;
163
    }
164
165
    /**
166
     * @return int|null
167
     */
168 1
    public function getFilesystemDocumentId() : ? int
169
    {
170 1
        return !is_null($this->container['fk_filesystem_document'])
171 1
            ? (int) $this->container['fk_filesystem_document']
172 1
            : null;
173
    }
174
175
    /**
176
     * @param null|int $fileIdentifier
177
     * @return FilesystemEntity
178
     */
179 1
    public function setFilesystemFileId(? int $fileIdentifier) : FilesystemEntity
180
    {
181 1
        $this->container['fk_filesystem_file'] = $fileIdentifier;
182
183 1
        return $this;
184
    }
185
186
    /**
187
     * @return int|null
188
     */
189 1
    public function getFilesystemFileId() : ? int
190
    {
191 1
        return !is_null($this->container['fk_filesystem_file'])
192 1
            ? (int) $this->container['fk_filesystem_file']
193 1
            : null;
194
    }
195
196
    /**
197
     * @param null|int $directoryIdentifier
198
     * @return FilesystemEntity
199
     */
200 1
    public function setFilesystemDirectoryId(? int $directoryIdentifier) : FilesystemEntity
201
    {
202 1
        $this->container['fk_filesystem_directory'] = $directoryIdentifier;
203
204 1
        return $this;
205
    }
206
207
    /**
208
     * @return int|null
209
     */
210 1
    public function getFilesystemDirectoryId() : ? int
211
    {
212 1
        return !is_null($this->container['fk_filesystem_directory'])
213 1
            ? (int) $this->container['fk_filesystem_directory']
214 1
            : null;
215
    }
216
217
    /**
218
     * @param null|int $linkIdentifier
219
     * @return FilesystemEntity
220
     */
221 1
    public function setFilesystemLinkId(? int $linkIdentifier) : FilesystemEntity
222
    {
223 1
        $this->container['fk_filesystem_link'] = $linkIdentifier;
224
225 1
        return $this;
226
    }
227
228
    /**
229
     * @return int|null
230
     */
231 1
    public function getFilesystemLinkId() : ? int
232
    {
233 1
        return !is_null($this->container['fk_filesystem_link'])
234 1
            ? (int) $this->container['fk_filesystem_link']
235 1
            : null;
236
    }
237
238
    /**
239
     * @param string $path
240
     * @return FilesystemEntity
241
     */
242 1
    public function setPath(string $path) : FilesystemEntity
243
    {
244 1
        $this->container['path'] = $path;
245
246 1
        return $this;
247
    }
248
249
    /**
250
     * @return null|string
251
     */
252 1
    public function getPath() : ? string
253
    {
254 1
        return $this->container['path'];
255
    }
256
257
    /**
258
     * @param string $baseName
259
     * @return FilesystemEntity
260
     */
261 1
    public function setBaseName(string $baseName) : FilesystemEntity
262
    {
263 1
        $this->container['basename'] = $baseName;
264
265 1
        return $this;
266
    }
267
268
    /**
269
     * @return null|string
270
     */
271 1
    public function getBaseName() : ? string
272
    {
273 1
        return $this->container['basename'];
274
    }
275
276
    /**
277
     * @param string $uri
278
     * @return FilesystemEntity
279
     */
280 1
    public function setUri(string $uri) : FilesystemEntity
281
    {
282 1
        $this->container['uri'] = $uri;
283
284 1
        return $this;
285
    }
286
287
    /**
288
     * @return null|string
289
     */
290 1
    public function getUri() : ? string
291
    {
292 1
        return $this->container['uri'];
293
    }
294
295
    /**
296
     * @param string $title
297
     * @return FilesystemEntity
298
     */
299 1
    public function setTitle(string $title) : FilesystemEntity
300
    {
301 1
        $this->container['title'] = $title;
302
303 1
        return $this;
304
    }
305
306
    /**
307
     * @return null|string
308
     */
309 1
    public function getTitle() : ? string
310
    {
311 1
        return $this->container['title'];
312
    }
313
314
    /**
315
     * @param string $description
316
     * @return FilesystemEntity
317
     */
318 1
    public function setDescription(string $description) : FilesystemEntity
319
    {
320 1
        $this->container['description'] = $description;
321
322 1
        return $this;
323
    }
324
325
    /**
326
     * @return null|string
327
     */
328 1
    public function getDescription() : ? string
329
    {
330 1
        return $this->container['description'];
331
    }
332
333
    /**
334
     * @param bool $isHidden
335
     * @return FilesystemEntity
336
     */
337 1
    public function setIsHidden(bool $isHidden) : FilesystemEntity
338
    {
339 1
        $this->container['is_hidden'] = $isHidden ? 1 : 0;
340
341 1
        return $this;
342
    }
343
344
    /**
345
     * @return bool
346
     */
347 1
    public function getIsHidden() : bool
348
    {
349 1
        return !empty($this->container['is_hidden']);
350
    }
351
352
    /**
353
     * @param bool $isReadonly
354
     * @return FilesystemEntity
355
     */
356 1
    public function setIsReadOnly(bool $isReadonly) : FilesystemEntity
357
    {
358 1
        $this->container['is_read_only'] = $isReadonly ? 1 : 0;
359
360 1
        return $this;
361
    }
362
363
    /**
364
     * @return bool
365
     */
366 1
    public function getIsReadOnly() : bool
367
    {
368 1
        return !empty($this->container['is_read_only']);
369
    }
370
371
    /**
372
     * @param bool $isDeleted
373
     * @return FilesystemEntity
374
     */
375 1
    public function setIsDeleted(bool $isDeleted) : FilesystemEntity
376
    {
377 1
        $this->container['is_deleted'] = $isDeleted ? 1 : 0;
378
379 1
        return $this;
380
    }
381
382
    /**
383
     * @return bool
384
     */
385 1
    public function getIsDeleted() : bool
386
    {
387 1
        return !empty($this->container['is_deleted']);
388
    }
389
390
    /**
391
     * @param DateTime $dateTime
392
     * @return FilesystemEntity
393
     */
394 1
    public function setDateCreated(DateTime $dateTime) : FilesystemEntity
395
    {
396 1
        $this->container['date_created'] = $dateTime->format('Y-m-d H:i:s');
397
398 1
        return $this;
399
    }
400
401
    /**
402
     * @return null|DateTime
403
     */
404 1
    public function getDateCreated() : ? DateTime
405
    {
406 1
        return !empty($this->container['date_created'])
407 1
            ? new DateTime($this->container['date_created'])
408 1
            : null;
409
    }
410
411
    /**
412
     * @param DateTime $dateTime
413
     * @return FilesystemEntity
414
     */
415 1
    public function setDateModified(DateTime $dateTime) : FilesystemEntity
416
    {
417 1
        $this->container['date_modified'] = $dateTime->format('Y-m-d H:i:s');
418
419 1
        return $this;
420
    }
421
422
    /**
423
     * @return null|DateTime
424
     */
425 1
    public function getDateModified() : ? DateTime
426
    {
427 1
        return !empty($this->container['date_modified'])
428 1
            ? new DateTime($this->container['date_modified'])
429 1
            : null;
430
    }
431
432
    /**
433
     * @param DateTime $dateTime
434
     * @return FilesystemEntity
435
     */
436 1
    public function setDatePublished(DateTime $dateTime) : FilesystemEntity
437
    {
438 1
        $this->container['date_published'] = $dateTime->format('Y-m-d H:i:s');
439
440 1
        return $this;
441
    }
442
443
    /**
444
     * @return null|DateTime
445
     */
446 1
    public function getDatePublished() : ? DateTime
447
    {
448 1
        return !empty($this->container['date_published'])
449 1
            ? new DateTime($this->container['date_published'])
450 1
            : null;
451
    }
452
}
453