Completed
Push — master ( 645396...c43b9a )
by WEBEWEB
01:32
created

DataTablesColumn::getCellType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
16
/**
17
 * DataTables column.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\JQuery\DatatablesBundle\Column
21
 * @final
22
 */
23
final class DataTablesColumn implements JsonSerializable {
24
25
    /**
26
     * Cell type.
27
     *
28
     * @var string
29
     */
30
    private $cellType = "td";
31
32
    /**
33
     * Class name.
34
     *
35
     * @var string
36
     */
37
    private $classname;
38
39
    /**
40
     * Content padding.
41
     *
42
     * @var string
43
     */
44
    private $contentPadding;
45
46
    /**
47
     * Data.
48
     *
49
     * @var integer|string
50
     */
51
    private $data;
52
53
    /**
54
     * Default content.
55
     *
56
     * @var string
57
     */
58
    private $defaultContent;
59
60
    /**
61
     * Name.
62
     *
63
     * @var string
64
     */
65
    private $name;
66
67
    /**
68
     * Order data.
69
     *
70
     * @var integer|array
71
     */
72
    private $orderData;
73
74
    /**
75
     * Order data type.
76
     *
77
     * @var string
78
     */
79
    private $orderDataType;
80
81
    /**
82
     * Order sequence.
83
     *
84
     * @var string
85
     */
86
    private $orderSequence;
87
88
    /**
89
     * Orderable.
90
     *
91
     * @var boolean
92
     */
93
    private $orderable = true;
94
95
    /**
96
     * Searchable.
97
     *
98
     * @var boolean
99
     */
100
    private $searchable = true;
101
102
    /**
103
     * Title.
104
     *
105
     * @var string
106
     */
107
    private $title;
108
109
    /**
110
     * Type.
111
     *
112
     * @var string
113
     */
114
    private $type;
115
116
    /**
117
     * Visible.
118
     *
119
     * @var boolean
120
     */
121
    private $visible = true;
122
123
    /**
124
     * Width.
125
     *
126
     * @var string
127
     */
128
    private $width;
129
130
    /**
131
     * Constructor.
132
     */
133
    public function __construct() {
134
        // NOTHING TO DO.
135
    }
136
137
    /**
138
     * Get the cell type.
139
     *
140
     * @return string Returns the cell type.
141
     */
142
    public function getCellType() {
143
        return $this->cellType;
144
    }
145
146
    /**
147
     * Get the class name.
148
     *
149
     * @return string Returns the class name.
150
     */
151
    public function getClassname() {
152
        return $this->classname;
153
    }
154
155
    /**
156
     * Get the content padding.
157
     *
158
     * @return string Returns the content padding.
159
     */
160
    public function getContentPadding() {
161
        return $this->contentPadding;
162
    }
163
164
    /**
165
     * Get the data.
166
     *
167
     * @return integer|string Returns the data.
168
     */
169
    public function getData() {
170
        return $this->data;
171
    }
172
173
    /**
174
     * Get the default content
175
     *
176
     * @return string Returns the default content.
177
     */
178
    public function getDefaultContent() {
179
        return $this->defaultContent;
180
    }
181
182
    /**
183
     * Get the name.
184
     *
185
     * @return string Returns the name.
186
     */
187
    public function getName() {
188
        return $this->name;
189
    }
190
191
    /**
192
     * Get the order data.
193
     *
194
     * @return integer|array Returns the order data.
195
     */
196
    public function getOrderData() {
197
        return $this->orderData;
198
    }
199
200
    /**
201
     * Get the order data type.
202
     *
203
     * @return string Returns the order data type.
204
     */
205
    public function getOrderDataType() {
206
        return $this->orderDataType;
207
    }
208
209
    /**
210
     * Get the order sequence.
211
     *
212
     * @return string Returns the order sequence.
213
     */
214
    public function getOrderSequence() {
215
        return $this->orderSequence;
216
    }
217
218
    /**
219
     * Get the orderable.
220
     *
221
     * @return boolean Returns the orderable.
222
     */
223
    public function getOrderable() {
224
        return $this->orderable;
225
    }
226
227
    /**
228
     * Get the searchable.
229
     *
230
     * @return boolean Returns the searchable.
231
     */
232
    public function getSearchable() {
233
        return $this->searchable;
234
    }
235
236
    /**
237
     * Get the title.
238
     *
239
     * @return string Returns the title.
240
     */
241
    public function getTitle() {
242
        return $this->title;
243
    }
244
245
    /**
246
     * Get the type.
247
     *
248
     * @return string Returns the type.
249
     */
250
    public function getType() {
251
        return $this->type;
252
    }
253
254
    /**
255
     * Get the visible.
256
     *
257
     * @return boolean Returns the visible.
258
     */
259
    public function getVisible() {
260
        return $this->visible;
261
    }
262
263
    /**
264
     * Get the width.
265
     *
266
     * @return string Returns the width.
267
     */
268
    public function getWidth() {
269
        return $this->width;
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function jsonSerialize() {
276
        return $this->toArray();
277
    }
278
279
    /**
280
     * Set the cell type.
281
     *
282
     * @param string $cellType The cell type.
283
     * @return DataTablesColumn Returns the DataTables column.
284
     */
285
    public function setCellType($cellType) {
286
        switch ($cellType) {
287
            case "td":
288
            case "th":
289
                $this->cellType = $cellType;
290
                break;
291
            default:
292
                $this->cellType = "td";
293
        }
294
        return $this;
295
    }
296
297
    /**
298
     * Set the class name.
299
     *
300
     * @param string $classname The class name.
301
     * @return DataTablesColumn Returns the DataTables column.
302
     */
303
    public function setClassname($classname) {
304
        $this->classname = $classname;
305
        return $this;
306
    }
307
308
    /**
309
     * Set the content padding.
310
     *
311
     * @param string $contentPadding The content padding.
312
     * @return DataTablesColumn Returns the DataTables column.
313
     */
314
    public function setContentPadding($contentPadding) {
315
        $this->contentPadding = $contentPadding;
316
        return $this;
317
    }
318
319
    /**
320
     * Set the data.
321
     *
322
     * @param integer|strign $data The data.
323
     * @return DataTablesColumn Returns the DataTables column.
324
     */
325
    public function setData($data) {
326
        $this->data = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can also be of type object<WBW\Bundle\JQuery...esBundle\Column\strign>. However, the property $data is declared as type integer|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
327
        return $this;
328
    }
329
330
    /**
331
     * Set the default content.
332
     *
333
     * @param string $defaultContent The default content.
334
     * @return DataTablesColumn Returns the DataTables column.
335
     */
336
    public function setDefaultContent($defaultContent) {
337
        $this->defaultContent = $defaultContent;
338
        return $this;
339
    }
340
341
    /**
342
     * Set the name.
343
     *
344
     * @param string $name The name.
345
     * @return DataTablesColumn Returns the DataTables column.
346
     */
347
    public function setName($name) {
348
        $this->name = $name;
349
        return $this;
350
    }
351
352
    /**
353
     * Set the order data.
354
     *
355
     * @param integer|array $orderData The order data.
356
     * @return DataTablesColumn Returns the DataTables column.
357
     */
358
    public function setOrderData($orderData) {
359
        $this->orderData = $orderData;
360
        return $this;
361
    }
362
363
    /**
364
     * Set the order data type.
365
     *
366
     * @param string $orderDataType The order data type.
367
     * @return DataTablesColumn Returns the DataTables column.
368
     */
369
    public function setOrderDataType($orderDataType) {
370
        $this->orderDataType = $orderDataType;
371
        return $this;
372
    }
373
374
    /**
375
     * Set the order sequence.
376
     *
377
     * @param string $orderSequence The order sequence.
378
     * @return DataTablesColumn Returns the DataTables column.
379
     */
380
    public function setOrderSequence($orderSequence) {
381
        switch ($orderSequence) {
382
            case "asc":
383
            case "desc":
384
                $this->orderSequence = $orderSequence;
385
                break;
386
            default:
387
                $this->orderSequence = null;
388
        }
389
        return $this;
390
    }
391
392
    /**
393
     * Set the orderable.
394
     *
395
     * @param boolean $orderable The orderable.
396
     * @return DataTablesColumn Returns the DataTables column.
397
     */
398
    public function setOrderable($orderable) {
399
        $this->orderable = $orderable;
400
        return $this;
401
    }
402
403
    /**
404
     * Set the searchable.
405
     *
406
     * @param boolean $searchable The searchable.
407
     * @return DataTablesColumn Returns the DataTables column.
408
     */
409
    public function setSearchable($searchable) {
410
        $this->searchable = $searchable;
411
        return $this;
412
    }
413
414
    /**
415
     * Set the title.
416
     *
417
     * @param string $title The title.
418
     * @return DataTablesColumn Returns the DataTables column.
419
     */
420
    public function setTitle($title) {
421
        $this->title = $title;
422
        return $this;
423
    }
424
425
    /**
426
     * Set the type.
427
     *
428
     * @param string $type The type.
429
     * @return DataTablesColumn Returns the DataTables column.
430
     */
431
    public function setType($type) {
432
        switch ($type) {
433
            case "date":
434
            case "num":
435
            case "num-fmt":
436
            case "html":
437
            case "html-num":
438
            case "string":
439
                $this->type = $type;
440
                break;
441
            default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
442
                $this->type = null;
443
        }
444
        return $this;
445
    }
446
447
    /**
448
     * Set the visible.
449
     *
450
     * @param boolean $visible The visible.
451
     * @return DataTablesColumn Returns the DataTables column.
452
     */
453
    public function setVisible($visible) {
454
        $this->visible = $visible;
455
        return $this;
456
    }
457
458
    /**
459
     * Set the width.
460
     *
461
     * @param string $width The width.
462
     * @return DataTablesColumn Returns the DataTables column.
463
     */
464
    public function setWidth($width) {
465
        $this->width = $width;
466
        return $this;
467
    }
468
469
    /**
470
     * Convert into an array representing this instance.
471
     *
472
     * @return array Returns an array representing this instance.
473
     */
474
    public function toArray() {
475
476
        // Initialize the output.
477
        $output = [];
478
479
        if (null !== $this->cellType) {
480
            $output["cellType"] = $this->cellType;
481
        }
482
        if (null !== $this->classname) {
483
            $output["classname"] = $this->classname;
484
        }
485
        if (null !== $this->contentPadding) {
486
            $output["contentPadding"] = $this->contentPadding;
487
        }
488
        if (null !== $this->data) {
489
            $output["data"] = $this->data;
490
        }
491
        if (null !== $this->defaultContent) {
492
            $output["defaultContent"] = $this->defaultContent;
493
        }
494
        if (null !== $this->name) {
495
            $output["name"] = $this->name;
496
        }
497
        if (null !== $this->orderable && false === $this->orderable) {
498
            $output["orderable"] = $this->orderable;
499
        }
500
        if (null !== $this->orderData) {
501
            $output["orderData"] = $this->orderData;
502
        }
503
        if (null !== $this->orderDataType) {
504
            $output["orderDataType"] = $this->orderDataType;
505
        }
506
        if (null !== $this->orderSequence) {
507
            $output["orderSequence"] = $this->orderSequence;
508
        }
509
        if (null !== $this->searchable && false === $this->searchable) {
510
            $output["searchable"] = $this->searchable;
511
        }
512
        if (null !== $this->title) {
513
            $output["title"] = $this->title;
514
        }
515
        if (null !== $this->type) {
516
            $output["type"] = $this->type;
517
        }
518
        if (null !== $this->visible && false === $this->visible) {
519
            $output["visible"] = $this->visible;
520
        }
521
        if (null !== $this->width) {
522
            $output["width"] = $this->width;
523
        }
524
525
        // Return the output.
526
        return $output;
527
    }
528
529
}
530