Passed
Pull Request — master (#4)
by
unknown
07:28
created

FilteredTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 11
c 1
b 0
f 1
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A getFiltered() 0 14 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Actions;
6
7
use CdekSDK2\Constants;
8
use CdekSDK2\Http\ApiResponse;
9
10
trait FilteredTrait
11
{
12
    /**
13
     * @param array $filter
14
     * @return ApiResponse
15
     */
16 2
    public function getFiltered(array $filter = []): ApiResponse
17
    {
18 2
        $add_params = '';
19 2
        if (!empty($filter)) {
20 2
            $filtered = [];
21 2
            foreach ($filter as $k => $v) {
22 2
                if (array_key_exists($k, Constants::OFFICE_FILTER)) {
23 2
                    $filtered[$k] = $v;
24
                }
25
            }
26 2
            $filter = array_replace(Constants::OFFICE_FILTER, $filtered);
27 2
            $add_params = empty($filter) ? '' : http_build_query($filter);
28
        }
29 2
        return $this->get($add_params);
30
    }
31
32
    /**
33
     * Переиспользуем стандартный метод
34
     * @param string $filter
35
     * @return ApiResponse
36
     */
37 4
    public function get(string $filter = ''): ApiResponse
38
    {
39 4
        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...
40
    }
41
}
42