• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gam6itko / ozon-seller / 15486101492

06 Jun 2025 08:20AM UTC coverage: 74.145% (-5.8%) from 79.946%
15486101492

push

github

web-flow
Create DescriptionCategoryService.php (#101)

* Create DescriptionCategoryService.php

0 of 76 new or added lines in 1 file covered. (0.0%)

6 existing lines in 1 file now uncovered.

889 of 1199 relevant lines covered (74.15%)

40.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Service/V1/DescriptionCategoryService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Gam6itko\OzonSeller\Service\V1;
6

7
use Gam6itko\OzonSeller\Enum\Language;
8
use Gam6itko\OzonSeller\Service\AbstractService;
9
use Gam6itko\OzonSeller\TypeCaster;
10
use Gam6itko\OzonSeller\Utils\ArrayHelper;
11

12
/**
13
 * @psalm-type TLanguage = Language::*
14
 * @psalm-type TCategoryNodeChildSameAsParent = array
15
 * @psalm-type TCategoryNode = array{
16
 *     description_category_id: positive-int,
17
 *     category_name: string,
18
 *     disabled: bool,
19
 *     children: list<TCategoryNodeChildSameAsParent>,
20
 *     type_id?: positive-int,
21
 *     type_name?: string
22
 * }
23
 * @psalm-type TAttribute = array{
24
 *     id: positive-int,
25
 *     attribute_complex_id: int,
26
 *     name: string,
27
 *     description: string,
28
 *     type: string,
29
 *     is_collection: bool,
30
 *     is_required: bool,
31
 *     is_aspect: bool,
32
 *     max_value_count: int,
33
 *     group_name: string,
34
 *     group_id: int,
35
 *     dictionary_id: int,
36
 *     category_dependent: bool,
37
 *     complex_is_collection: bool
38
 * }
39
 * @psalm-type TAttributeValue = array{
40
 *     id: positive-int,
41
 *     value: string,
42
 *     info: string,
43
 *     picture: string
44
 * }
45
 * @psalm-type TQuery = array{language?: TLanguage}
46
 * @psalm-type TAttributeValuesQuery = array{
47
 *     language?: TLanguage,
48
 *     last_value_id?: positive-int,
49
 *     limit?: positive-int
50
 * }
51
 * @psalm-type TAttributeValuesSearchQuery = array{
52
 *     value: non-empty-string,
53
 *     limit?: positive-int,
54
 *     language?: TLanguage
55
 * }
56
 * @psalm-type TTreeResponse = array{result: list<TCategoryNode>}
57
 * @psalm-type TAttributesResponse = array{result: list<TAttribute>}
58
 * @psalm-type TAttributeValuesResponse = array{
59
 *     result: list<TAttributeValue>,
60
 *     has_next: bool
61
 * }
62
 */
63
class DescriptionCategoryService extends AbstractService
64
{
65
    protected const DEFAULT_ATTRIBUTE_VALUES_LIMIT = 2000;
66
    protected const DEFAULT_ATTRIBUTE_VALUES_SEARCH_LIMIT = 100;
67

68
    private $path = '/v1/description-category';
69

70
    /**
71
     * @see https://docs.ozon.ru/api/seller/#operation/DescriptionCategoryAPI_GetTree
72
     *
73
     * @param TQuery $query
74
     * @return TTreeResponse
75
     */
76
    public function getCategoryTree(array $query = [])
77
    {
NEW
78
        $query = ArrayHelper::pick($query, ['language']);
×
79

NEW
80
        $query = array_merge(
×
NEW
81
            [
×
NEW
82
                'language' => Language::DEFAULT,
×
NEW
83
            ],
×
NEW
84
            $query
×
NEW
85
        );
×
86

NEW
87
        $query = TypeCaster::castArr(
×
NEW
88
            $query,
×
NEW
89
            [
×
NEW
90
                'language' => 'str',
×
NEW
91
            ]
×
NEW
92
        );
×
93

NEW
94
        return $this->request('POST', "{$this->path}/tree", $query);
×
95
    }
96

97
    /**
98
     * @see https://docs.ozon.ru/api/seller/#operation/DescriptionCategoryAPI_GetAttributes
99
     *
100
     * @param positive-int $categoryId
101
     * @param positive-int $typeId
102
     * @param TQuery $query
103
     * @return TAttributesResponse
104
     */
105
    public function getCategoryAttributes(int $categoryId, int $typeId, array $query = [])
106
    {
NEW
107
        $query = ArrayHelper::pick($query, ['language']);
×
108

NEW
109
        $query = array_merge(
×
NEW
110
            [
×
NEW
111
                'description_category_id' => $categoryId,
×
NEW
112
                'type_id' => $typeId,
×
NEW
113
                'language' => Language::DEFAULT,
×
NEW
114
            ],
×
NEW
115
            $query
×
NEW
116
        );
×
117

NEW
118
        $query = TypeCaster::castArr(
×
NEW
119
            $query,
×
NEW
120
            [
×
NEW
121
                'description_category_id' => 'int',
×
NEW
122
                'type_id' => 'int',
×
NEW
123
                'language' => 'str',
×
NEW
124
            ]
×
NEW
125
        );
×
126

NEW
127
        return $this->request('POST', "{$this->path}/attribute", $query);
×
128
    }
129

130
    /**
131
     * @see https://docs.ozon.ru/api/seller/#operation/DescriptionCategoryAPI_GetAttributeValues
132
     *
133
     * @param positive-int $categoryId
134
     * @param positive-int $typeId
135
     * @param positive-int $attributeId
136
     * @param TAttributeValuesQuery $query
137
     * @return TAttributeValuesResponse
138
     */
139
    public function getAttributeValues(int $categoryId, int $typeId, int $attributeId, array $query = [])
140
    {
NEW
141
        $query = ArrayHelper::pick($query, ['language', 'last_value_id', 'limit']);
×
142

NEW
143
        $query = array_merge(
×
NEW
144
            [
×
NEW
145
                'description_category_id' => $categoryId,
×
NEW
146
                'type_id' => $typeId,
×
NEW
147
                'attribute_id' => $attributeId,
×
NEW
148
                'limit' => self::DEFAULT_ATTRIBUTE_VALUES_LIMIT,
×
NEW
149
                'language' => Language::DEFAULT,
×
NEW
150
            ],
×
NEW
151
            $query
×
NEW
152
        );
×
153

NEW
154
        $query = TypeCaster::castArr(
×
NEW
155
            $query,
×
NEW
156
            [
×
NEW
157
                'description_category_id' => 'int',
×
NEW
158
                'type_id' => 'int',
×
NEW
159
                'attribute_id' => 'int',
×
NEW
160
                'limit' => 'int',
×
NEW
161
                'last_value_id' => 'int',
×
NEW
162
                'language' => 'str',
×
NEW
163
            ]
×
NEW
164
        );
×
165

NEW
166
        return $this->request('POST', "{$this->path}/attribute/values", $query, true, false);
×
167
    }
168

169
    /**
170
     * @see https://docs.ozon.ru/api/seller/#operation/DescriptionCategoryAPI_SearchAttributeValues
171
     *
172
     * @param positive-int $categoryId
173
     * @param positive-int $typeId
174
     * @param positive-int $attributeId
175
     * @param TAttributeValuesSearchQuery $query
176
     * @return TAttributeValuesResponse
177
     */
178
    public function searchAttributeValues(int $categoryId, int $typeId, int $attributeId, array $query)
179
    {
NEW
180
        $query = ArrayHelper::pick($query, ['value', 'limit']);
×
181

NEW
182
        $query = array_merge(
×
NEW
183
            [
×
NEW
184
                'description_category_id' => $categoryId,
×
NEW
185
                'type_id' => $typeId,
×
NEW
186
                'attribute_id' => $attributeId,
×
NEW
187
                'limit' => self::DEFAULT_ATTRIBUTE_VALUES_SEARCH_LIMIT,
×
NEW
188
            ],
×
NEW
189
            $query
×
NEW
190
        );
×
191

NEW
192
        $query = TypeCaster::castArr(
×
NEW
193
            $query,
×
NEW
194
            [
×
NEW
195
                'description_category_id' => 'int',
×
NEW
196
                'type_id' => 'int',
×
NEW
197
                'attribute_id' => 'int',
×
NEW
198
                'limit' => 'int',
×
NEW
199
                'value' => 'str',
×
NEW
200
            ]
×
NEW
201
        );
×
202

NEW
203
        return $this->request('POST', "{$this->path}/attribute/values/search", $query, true, false);
×
204
    }
205
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc