Completed
Pull Request — master (#139)
by
unknown
10:24
created

CategoryClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 111
Duplicated Lines 9.01 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 5
dl 10
loc 111
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getList() 0 10 1
A get() 10 10 1
A getChildren() 0 10 1
A getModels() 0 10 1
A getFilters() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Yandex PHP Library
4
 *
5
 * @copyright NIX Solutions Ltd.
6
 * @link https://github.com/nixsolutions/yandex-php-library
7
 */
8
9
/**
10
 * @namespace
11
 */
12
namespace Yandex\Market\Content\Clients;
13
14
use Yandex\Market\Content\ContentClient;
15
use Yandex\Market\Content\Models;
16
17
/**
18
 * Class CategoryClient
19
 *
20
 * @category Yandex
21
 * @package MarketContent
22
 *
23
 * @author   Oleg Scherbakov <[email protected]>
24
 * @created  04.01.16 23:54
25
 */
26
class CategoryClient extends ContentClient
27
{
28
    /**
29
     * Get Categories
30
     *
31
     * Returns categories list of Yandex.Market service according to params.
32
     * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-docpage/
33
     *
34
     * @param array $params
35
     *
36
     * @return Models\ResponseCategoryGetList
37
     */
38
    public function getList($params = array())
39
    {
40
        $resource = 'category.json';
41
        $resource .= '?' . $this->buildQueryString($params);
42
        $response = $this->getServiceResponse($resource);
43
44
        $getCategoriesResponse = new Models\ResponseCategoryGetList($response);
45
46
        return $getCategoriesResponse;
47
    }
48
49
    /**
50
     * Get category information
51
     *
52
     * Returns category of Yandex.Market service according to params.
53
     * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-docpage/
54
     *
55
     * @param int $categoryId
56
     * @param array $params
57
     *
58
     * @return Models\Category
59
     */
60 View Code Duplication
    public function get($categoryId, $params = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        $resource = 'category/' . $categoryId . '.json';
63
        $resource .= '?' . $this->buildQueryString($params);
64
        $response = $this->getServiceResponse($resource);
65
66
        $getCategoryResponse = new Models\ResponseCategoryGet($response);
67
68
        return $getCategoryResponse->getCategory();
69
    }
70
71
    /**
72
     * Get children categories
73
     *
74
     * Returns children categories list of Yandex.Market service according to params.
75
     * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-children-docpage/
76
     *
77
     * @param int $categoryId
78
     * @param array $params
79
     *
80
     * @return Models\ResponseCategoryGetList
81
     */
82
    public function getChildren($categoryId, $params = array())
83
    {
84
        $resource = 'category/' . $categoryId . '/children.json';
85
        $resource .= '?' . $this->buildQueryString($params);
86
        $response = $this->getServiceResponse($resource);
87
88
        $getCategoryResponse = new Models\ResponseCategoryGetList($response);
89
90
        return $getCategoryResponse;
91
    }
92
93
    /**
94
     * Get models in category
95
     *
96
     * Returns models list represented in category of Yandex.Market service according to params.
97
     * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-model-docpage/
98
     *
99
     * @param int $categoryId
100
     * @param array $params
101
     *
102
     * @return Models\ResponseCategoryGetModels
103
     */
104
    public function getModels($categoryId, $params = array())
105
    {
106
        $resource = 'category/' . $categoryId . '/models.json';
107
        $resource .= '?' . $this->buildQueryString($params);
108
        $response = $this->getServiceResponse($resource);
109
110
        $getCategoryModelsResponse = new Models\ResponseCategoryGetModels($response);
111
112
        return $getCategoryModelsResponse;
113
    }
114
115
    /**
116
     * Get filters in category
117
     *
118
     * Returns filters list of models represented in category of Yandex.Market service according to params.
119
     * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-filters-docpage/
120
     *
121
     * @param int $categoryId
122
     * @param array $params
123
     *
124
     * @return Models\ResponseCategoryGetFilters
125
     */
126
    public function getFilters($categoryId, $params = array())
127
    {
128
        $resource = 'category/' . $categoryId . '/filters.json';
129
        $resource .= '?' . $this->buildQueryString($params);
130
        $response = $this->getServiceResponse($resource);
131
132
        $getCategoryFiltersResponse = new Models\ResponseCategoryGetFilters($response);
133
134
        return $getCategoryFiltersResponse;
135
    }
136
}
137