DataTablesNormalizer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
eloc 22
c 2
b 1
f 0
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeResponse() 0 7 1
A normalizeColumn() 0 20 1
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2019 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\Normalizer;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesColumnInterface;
15
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesResponseInterface;
16
use WBW\Library\Types\Helper\ArrayHelper;
17
18
/**
19
 * DataTables normalizer.
20
 *
21
 * @author webeweb <https://github.com/webeweb>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Normalizer
23
 */
24
class DataTablesNormalizer {
25
26
    /**
27
     * Normalize a column.
28
     *
29
     * @param DataTablesColumnInterface $column The column.
30
     * @return array<string,mixed> Returns teh normalized column.
31
     */
32
    public static function normalizeColumn(DataTablesColumnInterface $column): array {
33
34
        $output = [];
35
36
        ArrayHelper::set($output, "cellType", $column->getCellType(), [null]);
37
        ArrayHelper::set($output, "classname", $column->getClassname(), [null]);
38
        ArrayHelper::set($output, "contentPadding", $column->getContentPadding(), [null]);
39
        ArrayHelper::set($output, "data", $column->getData(), [null]);
40
        ArrayHelper::set($output, "defaultContent", $column->getDefaultContent(), [null]);
41
        ArrayHelper::set($output, "name", $column->getName(), [null]);
42
        ArrayHelper::set($output, "orderable", $column->getOrderable(), [null, true]);
43
        ArrayHelper::set($output, "orderData", $column->getOrderData(), [null]);
44
        ArrayHelper::set($output, "orderDataType", $column->getOrderDataType(), [null]);
45
        ArrayHelper::set($output, "orderSequence", $column->getOrderSequence(), [null]);
46
        ArrayHelper::set($output, "searchable", $column->getSearchable(), [null, true]);
47
        ArrayHelper::set($output, "type", $column->getType(), [null]);
48
        ArrayHelper::set($output, "visible", $column->getVisible(), [null, true]);
49
        ArrayHelper::set($output, "width", $column->getWidth(), [null]);
50
51
        return $output;
52
    }
53
54
    /**
55
     * Normalize a response.
56
     *
57
     * @param DataTablesResponseInterface $response The response.
58
     * @return array<string,mixed> Returns the normalized response.
59
     */
60
    public static function normalizeResponse(DataTablesResponseInterface $response): array {
61
62
        return [
63
            "data"            => $response->getData(),
64
            "draw"            => $response->getDraw(),
65
            "recordsFiltered" => $response->getRecordsFiltered(),
66
            "recordsTotal"    => $response->getRecordsTotal(),
67
        ];
68
    }
69
}
70