ParseFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 2
b 0
f 0
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateQueryString() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Seams-CMS Delivery SDK package.
7
 *
8
 * (c) Seams-CMS.com
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace SeamsCMS\Delivery;
15
16
use function GuzzleHttp\Psr7\build_query;
17
18
/**
19
 * Class Filter
20
 * @package SeamsCMS\Delivery
21
 */
22
class ParseFilter
23
{
24
    /**
25
     * @param Filter|null $filter
26
     * @return string
27
     */
28 5
    public static function generateQueryString(Filter $filter = null): string
29
    {
30 5
        if (is_null($filter)) {
31 2
            return "";
32
        }
33
34 3
        $params = [];
35 3
        $params['offset'] = $filter->getOffset();
36 3
        $params['limit'] = $filter->getLimit();
37 3
        if (! empty($filter->getSort())) {
38 2
            $params['sort'] = $filter->getSort();
39
        }
40 3
        if (! empty($filter->getQuery())) {
41 1
            $params['query'] = $filter->getQuery();
42
        }
43
44 3
        return build_query($params);
45
    }
46
}
47