FilteredTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 13
c 1
b 0
f 1
dl 0
loc 41
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseFilter() 0 15 4
A get() 0 3 1
A getFiltered() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Actions;
6
7
use CdekSDK2\Http\ApiResponse;
8
9
trait FilteredTrait
10
{
11
    /**
12
     * @param array $filter
13
     * @return ApiResponse
14
     */
15
    public function getFiltered(array $filter = []): ApiResponse
16
    {
17
        $add_params = $this->parseFilter($filter);
18
        return $this->get($add_params);
19
    }
20
21
    /**
22
     * @param  array  $filter
23
     * @return string
24
     */
25
    private function parseFilter(array $filter = []): string
26
    {
27
        $add_params = '';
28
        if (empty($filter)) {
29
            return $add_params;
30
        }
31
32
        $filtered = [];
33
        foreach ($filter as $k => $v) {
34
            if (array_key_exists($k, self::FILTER)) {
0 ignored issues
show
Bug introduced by
The constant CdekSDK2\Actions\FilteredTrait::FILTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
                $filtered[$k] = $v;
36
            }
37
        }
38
        $add_params = http_build_query($filtered);
39
        return $add_params;
40
    }
41
42
    /**
43
     * Переиспользуем стандартный метод
44
     * @param string $filter
45
     * @return ApiResponse
46
     */
47
    public function get(string $filter = ''): ApiResponse
48
    {
49
        return $this->http_client->get(self::URL . '?' . $filter);
0 ignored issues
show
Bug introduced by
The constant CdekSDK2\Actions\FilteredTrait::URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
50
    }
51
}
52