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

FilteredTrait::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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