Completed
Push — master ( dbc0ff...b4a470 )
by WEBEWEB
01:31
created

DataTablesSearch   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 89
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRegex() 0 3 1
A getValue() 0 3 1
A parse() 0 18 3
A setRegex() 0 4 1
A setValue() 0 4 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\API;
13
14
use WBW\Library\Core\Utility\Argument\BooleanUtility;
15
16
/**
17
 * DataTables search.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\JQuery\DatatablesBundle\API
21
 */
22
class DataTablesSearch {
23
24
    /**
25
     * Regex.
26
     *
27
     * @var boolean
28
     */
29
    private $regex;
30
31
    /**
32
     * Value.
33
     *
34
     * @var string
35
     */
36
    private $value;
37
38
    /**
39
     * Constructor.
40
     */
41
    public function __construct() {
42
        // NOTHING TO DO.
43
    }
44
45
    /**
46
     * Get the regex.
47
     *
48
     * @return boolean Returns the regex.
49
     */
50
    public function getRegex() {
51
        return $this->regex;
52
    }
53
54
    /**
55
     * Get the value.
56
     *
57
     * @return string Returns the value.
58
     */
59
    public function getValue() {
60
        return $this->value;
61
    }
62
63
    /**
64
     * Parse a raw search array.
65
     *
66
     * @param array $rawSearch The raw search array.
67
     * @return DataTablesSearch Returns the DataTables search in case of success, null otherwise.
68
     */
69
    public static function parse(array $rawSearch = []) {
70
71
        // Determines if the raw search is valid.
72
        if (false === array_key_exists("regex", $rawSearch)) {
73
            return null;
74
        }
75
        if (false === array_key_exists("value", $rawSearch)) {
76
            return null;
77
        }
78
79
        // Create a DataTable search.
80
        $dtSearch = new DataTablesSearch();
81
        $dtSearch->setRegex(BooleanUtility::parseString($rawSearch["regex"]));
82
        $dtSearch->setValue($rawSearch["value"]);
83
84
        // Return the DataTables search.
85
        return $dtSearch;
86
    }
87
88
    /**
89
     * Set the regex.
90
     *
91
     * @param boolean $regex The regex.
92
     * @return DataTablesSearch Returns this DataTables search.
93
     */
94
    public function setRegex($regex) {
95
        $this->regex = $regex;
96
        return $this;
97
    }
98
99
    /**
100
     * Set the value.
101
     *
102
     * @param string $value The value.
103
     * @return DataTablesSearch Returns this DataTables search.
104
     */
105
    public function setValue($value) {
106
        $this->value = $value;
107
        return $this;
108
    }
109
110
}
111