Completed
Push — master ( a91069...e573fc )
by WEBEWEB
01:35
created

DataTablesFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A newSearch() 0 20 3
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\Factory;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesSearch;
15
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesSearchInterface;
16
use WBW\Library\Core\Argument\BooleanHelper;
17
18
/**
19
 * DataTables factory.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Factory
23
 */
24
class DataTablesFactory {
25
26
    /**
27
     * Creates a new search.
28
     *
29
     * @param array $rawSearch The raw search.
30
     * @return DataTablesSearchInterface Returns a search instance.
31
     */
32
    public static function newSearch(array $rawSearch) {
33
34
        // Initialize a DataTables search.
35
        $dtSearch = new DataTablesSearch();
36
37
        // Determines if the raw search is valid.
38
        if (false === array_key_exists(DataTablesSearchInterface::DATATABLES_PARAMETER_REGEX, $rawSearch)) {
39
            return $dtSearch;
40
        }
41
        if (false === array_key_exists(DataTablesSearchInterface::DATATABLES_PARAMETER_VALUE, $rawSearch)) {
42
            return $dtSearch;
43
        }
44
45
        // Set the search.
46
        $dtSearch->setRegex(BooleanHelper::parseString($rawSearch[DataTablesSearchInterface::DATATABLES_PARAMETER_REGEX]));
47
        $dtSearch->setValue($rawSearch[DataTablesSearchInterface::DATATABLES_PARAMETER_VALUE]);
48
49
        // Return the search.
50
        return $dtSearch;
51
    }
52
53
}
54