Completed
Push — master ( a7ed84...65cc57 )
by WEBEWEB
02:22
created

DataTablesMappingHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 9 3
A getParam() 0 10 1
A getWhere() 0 10 1
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\Helper;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesMapping;
15
16
/**
17
 * DataTables mapping helper.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\JQuery\DataTablesBundle\Helper
21
 */
22
class DataTablesMappingHelper {
23
24
    /**
25
     * Get an alias.
26
     *
27
     * @param DataTablesMapping $mapping The mapping.
28
     * @return string Returns the alias.
29
     */
30
    public static function getAlias(DataTablesMapping $mapping) {
31
        if (null === $mapping->getColumn()) {
32
            return null;
33
        }
34
        if (null === $mapping->getPrefix()) {
35
            return $mapping->getColumn();
36
        }
37
        return implode(".", [$mapping->getPrefix(), $mapping->getColumn()]);
38
    }
39
40
    /**
41
     * Get a param.
42
     *
43
     * @param DataTablesMapping $mapping The mapping.
44
     * @return string Returns the param.
45
     */
46
    public static function getParam(DataTablesMapping $mapping) {
47
48
        // Initialize the param.
49
        $param = ":";
50
        $param .= $mapping->getPrefix();
51
        $param .= $mapping->getColumn();
52
53
        // Return the param.
54
        return $param;
55
    }
56
57
    /**
58
     * Get a mapping where.
59
     *
60
     * @param DataTablesMapping $mapping The mapping.
61
     * @return string Returns the where.
62
     */
63
    public static function getWhere(DataTablesMapping $mapping) {
64
65
        // Initialize the where.
66
        $where = self::getAlias($mapping);
67
        $where .= " LIKE ";
68
        $where .= self::getParam($mapping);
69
70
        // Return the where.
71
        return $where;
72
    }
73
74
}
75