Completed
Push — master ( e78d8a...96e91a )
by WEBEWEB
01:20
created

DataTablesColumn   C

Complexity

Total Complexity 62

Size/Duplication

Total Lines 533
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 62
lcom 1
cbo 1
dl 0
loc 533
rs 5.9493
c 0
b 0
f 0

34 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getCellType() 0 3 1
A getClassname() 0 3 1
A getContentPadding() 0 3 1
A getData() 0 3 1
A getDefaultContent() 0 3 1
A getMapping() 0 3 1
A getName() 0 3 1
A getOrderData() 0 3 1
A getOrderDataType() 0 3 1
A getOrderSequence() 0 3 1
A getOrderable() 0 3 1
A getSearchable() 0 3 1
A getTitle() 0 3 1
A getType() 0 3 1
A getVisible() 0 3 1
A getWidth() 0 3 1
A jsonSerialize() 0 3 1
A setCellType() 0 11 3
A setClassname() 0 4 1
A setContentPadding() 0 4 1
A setData() 0 4 1
A setDefaultContent() 0 4 1
A setName() 0 4 1
A setOrderData() 0 4 1
A setOrderDataType() 0 4 1
A setOrderSequence() 0 11 3
A setOrderable() 0 4 1
A setSearchable() 0 4 1
A setTitle() 0 4 1
B setType() 0 15 7
A setVisible() 0 4 1
A setWidth() 0 4 1
F toArray() 0 54 19

How to fix   Complexity   

Complex Class

Complex classes like DataTablesColumn 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 DataTablesColumn, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DatatablesBundle\Column;
13
14
use JsonSerializable;
15
use WBW\Bundle\JQuery\DatatablesBundle\Mapping\DataTablesMapping;
16
17
/**
18
 * DataTables column.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\JQuery\DatatablesBundle\Column
22
 * @final
23
 */
24
final class DataTablesColumn implements JsonSerializable {
25
26
    /**
27
     * Cell type.
28
     *
29
     * @var string
30
     */
31
    private $cellType = "td";
32
33
    /**
34
     * Class name.
35
     *
36
     * @var string
37
     */
38
    private $classname;
39
40
    /**
41
     * Content padding.
42
     *
43
     * @var string
44
     */
45
    private $contentPadding;
46
47
    /**
48
     * Data.
49
     *
50
     * @var integer|string
51
     */
52
    private $data;
53
54
    /**
55
     * Default content.
56
     *
57
     * @var string
58
     */
59
    private $defaultContent;
60
61
    /**
62
     * mapping.
63
     *
64
     * @var DataTablesMapping
65
     */
66
    private $mapping;
67
68
    /**
69
     * Name.
70
     *
71
     * @var string
72
     */
73
    private $name;
74
75
    /**
76
     * Order data.
77
     *
78
     * @var integer|array
79
     */
80
    private $orderData;
81
82
    /**
83
     * Order data type.
84
     *
85
     * @var string
86
     */
87
    private $orderDataType;
88
89
    /**
90
     * Order sequence.
91
     *
92
     * @var string
93
     */
94
    private $orderSequence;
95
96
    /**
97
     * Orderable.
98
     *
99
     * @var boolean
100
     */
101
    private $orderable = true;
102
103
    /**
104
     * Searchable.
105
     *
106
     * @var boolean
107
     */
108
    private $searchable = true;
109
110
    /**
111
     * Title.
112
     *
113
     * @var string
114
     */
115
    private $title;
116
117
    /**
118
     * Type.
119
     *
120
     * @var string
121
     */
122
    private $type;
123
124
    /**
125
     * Visible.
126
     *
127
     * @var boolean
128
     */
129
    private $visible = true;
130
131
    /**
132
     * Width.
133
     *
134
     * @var string
135
     */
136
    private $width;
137
138
    /**
139
     * Constructor.
140
     *
141
     * @param string $name The column name.
142
     * @param string $title The column title.
143
     * @param string $cellType The column cell type.
144
     */
145
    public function __construct($name, $title, $cellType = "td") {
146
        $this->mapping = new DataTablesMapping();
147
        $this->mapping->setColumn($name);
148
149
        $this->setCellType($cellType);
150
        $this->setData($name);
151
        $this->setName($name);
152
        $this->setTitle($title);
153
    }
154
155
    /**
156
     * Get the cell type.
157
     *
158
     * @return string Returns the cell type.
159
     */
160
    public function getCellType() {
161
        return $this->cellType;
162
    }
163
164
    /**
165
     * Get the class name.
166
     *
167
     * @return string Returns the class name.
168
     */
169
    public function getClassname() {
170
        return $this->classname;
171
    }
172
173
    /**
174
     * Get the content padding.
175
     *
176
     * @return string Returns the content padding.
177
     */
178
    public function getContentPadding() {
179
        return $this->contentPadding;
180
    }
181
182
    /**
183
     * Get the data.
184
     *
185
     * @return integer|string Returns the data.
186
     */
187
    public function getData() {
188
        return $this->data;
189
    }
190
191
    /**
192
     * Get the default content
193
     *
194
     * @return string Returns the default content.
195
     */
196
    public function getDefaultContent() {
197
        return $this->defaultContent;
198
    }
199
200
    /**
201
     * Get the mapping.
202
     *
203
     * @return DataTablesMapping The mapping.
204
     */
205
    public function getMapping() {
206
        return $this->mapping;
207
    }
208
209
    /**
210
     * Get the name.
211
     *
212
     * @return string Returns the name.
213
     */
214
    public function getName() {
215
        return $this->name;
216
    }
217
218
    /**
219
     * Get the order data.
220
     *
221
     * @return integer|array Returns the order data.
222
     */
223
    public function getOrderData() {
224
        return $this->orderData;
225
    }
226
227
    /**
228
     * Get the order data type.
229
     *
230
     * @return string Returns the order data type.
231
     */
232
    public function getOrderDataType() {
233
        return $this->orderDataType;
234
    }
235
236
    /**
237
     * Get the order sequence.
238
     *
239
     * @return string Returns the order sequence.
240
     */
241
    public function getOrderSequence() {
242
        return $this->orderSequence;
243
    }
244
245
    /**
246
     * Get the orderable.
247
     *
248
     * @return boolean Returns the orderable.
249
     */
250
    public function getOrderable() {
251
        return $this->orderable;
252
    }
253
254
    /**
255
     * Get the searchable.
256
     *
257
     * @return boolean Returns the searchable.
258
     */
259
    public function getSearchable() {
260
        return $this->searchable;
261
    }
262
263
    /**
264
     * Get the title.
265
     *
266
     * @return string Returns the title.
267
     */
268
    public function getTitle() {
269
        return $this->title;
270
    }
271
272
    /**
273
     * Get the type.
274
     *
275
     * @return string Returns the type.
276
     */
277
    public function getType() {
278
        return $this->type;
279
    }
280
281
    /**
282
     * Get the visible.
283
     *
284
     * @return boolean Returns the visible.
285
     */
286
    public function getVisible() {
287
        return $this->visible;
288
    }
289
290
    /**
291
     * Get the width.
292
     *
293
     * @return string Returns the width.
294
     */
295
    public function getWidth() {
296
        return $this->width;
297
    }
298
299
    /**
300
     * {@inheritdoc}
301
     */
302
    public function jsonSerialize() {
303
        return $this->toArray();
304
    }
305
306
    /**
307
     * Set the cell type.
308
     *
309
     * @param string $cellType The cell type.
310
     * @return DataTablesColumn Returns the DataTables column.
311
     */
312
    public function setCellType($cellType) {
313
        switch ($cellType) {
314
            case "td":
315
            case "th":
316
                $this->cellType = $cellType;
317
                break;
318
            default:
319
                $this->cellType = "td";
320
        }
321
        return $this;
322
    }
323
324
    /**
325
     * Set the class name.
326
     *
327
     * @param string $classname The class name.
328
     * @return DataTablesColumn Returns the DataTables column.
329
     */
330
    public function setClassname($classname) {
331
        $this->classname = $classname;
332
        return $this;
333
    }
334
335
    /**
336
     * Set the content padding.
337
     *
338
     * @param string $contentPadding The content padding.
339
     * @return DataTablesColumn Returns the DataTables column.
340
     */
341
    public function setContentPadding($contentPadding) {
342
        $this->contentPadding = $contentPadding;
343
        return $this;
344
    }
345
346
    /**
347
     * Set the data.
348
     *
349
     * @param integer|string $data The data.
350
     * @return DataTablesColumn Returns the DataTables column.
351
     */
352
    public function setData($data) {
353
        $this->data = $data;
354
        return $this;
355
    }
356
357
    /**
358
     * Set the default content.
359
     *
360
     * @param string $defaultContent The default content.
361
     * @return DataTablesColumn Returns the DataTables column.
362
     */
363
    public function setDefaultContent($defaultContent) {
364
        $this->defaultContent = $defaultContent;
365
        return $this;
366
    }
367
368
    /**
369
     * Set the name.
370
     *
371
     * @param string $name The name.
372
     * @return DataTablesColumn Returns the DataTables column.
373
     */
374
    public function setName($name) {
375
        $this->name = $name;
376
        return $this;
377
    }
378
379
    /**
380
     * Set the order data.
381
     *
382
     * @param integer|array $orderData The order data.
383
     * @return DataTablesColumn Returns the DataTables column.
384
     */
385
    public function setOrderData($orderData) {
386
        $this->orderData = $orderData;
387
        return $this;
388
    }
389
390
    /**
391
     * Set the order data type.
392
     *
393
     * @param string $orderDataType The order data type.
394
     * @return DataTablesColumn Returns the DataTables column.
395
     */
396
    public function setOrderDataType($orderDataType) {
397
        $this->orderDataType = $orderDataType;
398
        return $this;
399
    }
400
401
    /**
402
     * Set the order sequence.
403
     *
404
     * @param string $orderSequence The order sequence.
405
     * @return DataTablesColumn Returns the DataTables column.
406
     */
407
    public function setOrderSequence($orderSequence) {
408
        switch ($orderSequence) {
409
            case "asc":
410
            case "desc":
411
                $this->orderSequence = $orderSequence;
412
                break;
413
            default:
414
                $this->orderSequence = null;
415
        }
416
        return $this;
417
    }
418
419
    /**
420
     * Set the orderable.
421
     *
422
     * @param boolean $orderable The orderable.
423
     * @return DataTablesColumn Returns the DataTables column.
424
     */
425
    public function setOrderable($orderable) {
426
        $this->orderable = $orderable;
427
        return $this;
428
    }
429
430
    /**
431
     * Set the searchable.
432
     *
433
     * @param boolean $searchable The searchable.
434
     * @return DataTablesColumn Returns the DataTables column.
435
     */
436
    public function setSearchable($searchable) {
437
        $this->searchable = $searchable;
438
        return $this;
439
    }
440
441
    /**
442
     * Set the title.
443
     *
444
     * @param string $title The title.
445
     * @return DataTablesColumn Returns the DataTables column.
446
     */
447
    public function setTitle($title) {
448
        $this->title = $title;
449
        return $this;
450
    }
451
452
    /**
453
     * Set the type.
454
     *
455
     * @param string $type The type.
456
     * @return DataTablesColumn Returns the DataTables column.
457
     */
458
    public function setType($type) {
459
        switch ($type) {
460
            case "date":
461
            case "num":
462
            case "num-fmt":
463
            case "html":
464
            case "html-num":
465
            case "string":
466
                $this->type = $type;
467
                break;
468
            default:
469
                $this->type = null;
470
        }
471
        return $this;
472
    }
473
474
    /**
475
     * Set the visible.
476
     *
477
     * @param boolean $visible The visible.
478
     * @return DataTablesColumn Returns the DataTables column.
479
     */
480
    public function setVisible($visible) {
481
        $this->visible = $visible;
482
        return $this;
483
    }
484
485
    /**
486
     * Set the width.
487
     *
488
     * @param string $width The width.
489
     * @return DataTablesColumn Returns the DataTables column.
490
     */
491
    public function setWidth($width) {
492
        $this->width = $width;
493
        return $this;
494
    }
495
496
    /**
497
     * Convert into an array representing this instance.
498
     *
499
     * @return array Returns an array representing this instance.
500
     */
501
    public function toArray() {
502
503
        // Initialize the output.
504
        $output = [];
505
506
        if (null !== $this->cellType) {
507
            $output["cellType"] = $this->cellType;
508
        }
509
        if (null !== $this->classname) {
510
            $output["classname"] = $this->classname;
511
        }
512
        if (null !== $this->contentPadding) {
513
            $output["contentPadding"] = $this->contentPadding;
514
        }
515
        if (null !== $this->data) {
516
            $output["data"] = $this->data;
517
        }
518
        if (null !== $this->defaultContent) {
519
            $output["defaultContent"] = $this->defaultContent;
520
        }
521
        if (null !== $this->name) {
522
            $output["name"] = $this->name;
523
        }
524
        if (null !== $this->orderable && false === $this->orderable) {
525
            $output["orderable"] = $this->orderable;
526
        }
527
        if (null !== $this->orderData) {
528
            $output["orderData"] = $this->orderData;
529
        }
530
        if (null !== $this->orderDataType) {
531
            $output["orderDataType"] = $this->orderDataType;
532
        }
533
        if (null !== $this->orderSequence) {
534
            $output["orderSequence"] = $this->orderSequence;
535
        }
536
        if (null !== $this->searchable && false === $this->searchable) {
537
            $output["searchable"] = $this->searchable;
538
        }
539
        if (null !== $this->title) {
540
            $output["title"] = $this->title;
541
        }
542
        if (null !== $this->type) {
543
            $output["type"] = $this->type;
544
        }
545
        if (null !== $this->visible && false === $this->visible) {
546
            $output["visible"] = $this->visible;
547
        }
548
        if (null !== $this->width) {
549
            $output["width"] = $this->width;
550
        }
551
552
        // Return the output.
553
        return $output;
554
    }
555
556
}
557