Attribute::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 1
nc 1
nop 13

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Document;
14
15
use BitBag\SyliusVueStorefrontPlugin\Document\Attribute\Option;
16
17
class Attribute implements Indexable
18
{
19
    private const ENTITY_ID = 'id';
20
21
    private const ID = 'attribute_id';
22
23
    private const CODE = 'attribute_code';
24
25
    private const POSITION = 'position';
26
27
    private const OPTIONS = 'options';
28
29
    private const IS_UNIQUE = 'is_unique';
30
31
    private const IS_VISIBLE = 'is_visible';
32
33
    private const IS_COMPARABLE = 'is_comparable';
34
35
    private const IS_USER_DEFINED = 'is_user_defined';
36
37
    private const IS_VISIBLE_ON_FRONTEND = 'is_visible_on_front';
38
39
    private const FRONTEND_INPUT = 'frontend_input';
40
41
    private const FRONTEND_LABEL = 'frontend_label';
42
43
    //    TODO SAMPLE FROM VS API CATALOG_BACKUP.JSON ONLY
44
45
    private const IS_WYSIWYG_ENABLED = 'is_wysiwyg_enabled';
46
47
    private const IS_HTML_ALLOWED_ON_FRONTEND = 'is_html_allowed_on_frontend';
48
49
    private const IS_USED_FOR_SORTING = 'used_for_sort_by';
50
51
    private const IS_FILTERABLE = 'is_filterable';
52
53
    private const IS_FILTERABLE_IN_SEARCH = 'is_filterable_in_search';
54
55
    private const IS_USED_IN_GRID = 'is_used_in_grid';
56
57
    private const IS_VISIBLE_IN_GRID = 'is_visible_in_grid';
58
59
    private const IS_FILTERABLE_IN_GRID = 'is_filterable_in_grid';
60
61
    private const APPLY_TO = 'apply_to';
62
63
    private const IS_SEARCHABLE = 'is_searchable';
64
65
    private const IS_VISIBLE_IN_ADVANCED_SEARCH = 'is_visible_in_advanced_search';
66
67
    private const IS_USED_FOR_PROMO_RULES = 'is_used_for_promo_rules';
68
69
    private const IS_USED_IN_PRODUCT_LISTING = 'used_in_product_listing';
70
71
    private const SCOPE = 'scope';
72
73
    private const ENTITY_TYPE_ID = 'entity_type_id';
74
75
    private const IS_REQUIRED = 'is_required';
76
77
    private const DEFAULT_FRONTEND_LABEL = 'default_frontend_label';
78
79
    private const FRONTEND_LABELS = 'frontend_labels';
80
81
    private const BACKEND_TYPE = 'backend_type';
82
83
    private const SOURCE_MODEL = 'source_model';
84
85
    private const DEFAULT_VALUE = 'default_value';
86
87
    private const VALIDATION_RULES = 'validation_rules';
88
89
    /** @var int */
90
    private $documentId;
91
92
    /** @var int */
93
    private $entityId;
94
95
    /** @var int */
96
    private $id;
97
98
    /** @var string */
99
    private $code;
100
101
    /** @var int */
102
    private $position;
103
104
    /** @var Option[] */
105
    private $options;
106
107
    /** @var bool */
108
    private $isUnique;
109
110
    /** @var bool */
111
    private $isVisible;
112
113
    /** @var bool */
114
    private $isComparable;
115
116
    /** @var bool */
117
    private $isUserDefined;
118
119
    /** @var bool */
120
    private $isVisibleOnFrontend;
121
122
    /** @var string */
123
    private $frontendInput;
124
125
    /** @var string */
126
    private $frontendLabel;
127
128
    //    TODO SAMPLE FROM VS API CATALOG_BACKUP.JSON ONLY, BELOW FRONTEND_LABELS, ABOVE FRONTEND_LABEL
129
130
    /** @var bool */
131
    private $isWysiwygEnabled = false;
132
133
    /** @var bool */
134
    private $isHtmlAllowedOnFronted = false;
135
136
    /** @var bool */
137
    private $isUsedForSorting = false;
138
139
    /** @var bool */
140
    private $isFilterable = false;
141
142
    /** @var bool */
143
    private $isFilterableInSearch = false;
144
145
    /** @var bool */
146
    private $isUsedInGrid = false;
147
148
    /** @var bool */
149
    private $isVisibleInGrid = false;
150
151
    /** @var bool */
152
    private $isFilterableInGrid = false;
153
154
    /** @var array */
155
    private $applyTo = [];
156
157
    /** @var bool */
158
    private $isSearchable = false;
159
160
    /** @var bool */
161
    private $isVisibleInAdvancedSearch = false;
162
163
    /** @var bool */
164
    private $isUsedForPromoRules = false;
165
166
    /** @var bool */
167
    private $isUsedInProductListing = false;
168
169
    /** @var string */
170
    private $scope = 'store';
171
172
    /** @var int */
173
    private $entityTypeId = 4;
174
175
    /** @var bool */
176
    private $isRequired = false;
177
178
    /** @var string */
179
    private $defaultFrontendLabel;
180
181
    /** @var array|null */
182
    private $frontendLabels;
183
184
    /** @var string */
185
    private $backendType = 'varchar';
186
187
    /** @var string */
188
    private $sourceModel = 'Magento\Catalog\Model\Entity\Product\Attribute\Design\Options\Container';
189
190
    /** @var string */
191
    private $defaultValue = 'container2';
192
193
    /** @var array */
194
    private $validationRules = [];
195
196
    public function __construct(
197
        int $documentId,
198
        int $entityId,
199
        int $id,
200
        string $code,
201
        int $position,
202
        array $options,
203
        bool $isUnique,
204
        bool $isVisible,
205
        bool $isComparable,
206
        bool $isUserDefined,
207
        bool $isVisibleOnFrontend,
208
        string $frontendInput,
209
        string $frontendLabel
210
    ) {
211
        $this->documentId = $documentId;
212
        $this->entityId = $entityId;
213
        $this->id = $id;
214
        $this->code = $code;
215
        $this->position = $position;
216
        $this->options = $options;
217
        $this->isUnique = $isUnique;
218
        $this->isVisible = $isVisible;
219
        $this->isComparable = $isComparable;
220
        $this->isUserDefined = $isUserDefined;
221
        $this->isVisibleOnFrontend = $isVisibleOnFrontend;
222
        $this->frontendInput = $frontendInput;
223
        $this->frontendLabel = $frontendLabel;
224
        $this->defaultFrontendLabel = $frontendLabel;
225
    }
226
227
    public function getDocumentId(): int
228
    {
229
        return $this->documentId;
230
    }
231
232
    public function toElasticArray(): array
233
    {
234
        return [
235
            self::ENTITY_ID => $this->entityId,
236
            self::ID => $this->id,
237
            self::CODE => $this->code,
238
            self::POSITION => $this->position,
239
            self::OPTIONS => $this->options,
240
            self::IS_UNIQUE => $this->isUnique,
241
            self::IS_VISIBLE => $this->isVisible,
242
            self::IS_COMPARABLE => $this->isComparable,
243
            self::IS_USER_DEFINED => $this->isUserDefined,
244
            self::IS_VISIBLE_ON_FRONTEND => $this->isVisibleOnFrontend,
245
            self::FRONTEND_INPUT => $this->frontendInput,
246
            self::FRONTEND_LABEL => $this->frontendLabel,
247
            self::IS_WYSIWYG_ENABLED => $this->isWysiwygEnabled,
248
            self::IS_HTML_ALLOWED_ON_FRONTEND => $this->isHtmlAllowedOnFronted,
249
            self::IS_USED_FOR_SORTING => $this->isUsedForSorting,
250
            self::IS_FILTERABLE => $this->isFilterable,
251
            self::IS_FILTERABLE_IN_SEARCH => $this->isFilterableInSearch,
252
            self::IS_USED_IN_GRID => $this->isUsedInGrid,
253
            self::IS_VISIBLE_IN_GRID => $this->isVisibleInGrid,
254
            self::IS_FILTERABLE_IN_GRID => $this->isFilterableInGrid,
255
            self::APPLY_TO => $this->applyTo,
256
            self::IS_SEARCHABLE => $this->isSearchable,
257
            self::IS_VISIBLE_IN_ADVANCED_SEARCH => $this->isVisibleInAdvancedSearch,
258
            self::IS_USED_FOR_PROMO_RULES => $this->isUsedForPromoRules,
259
            self::IS_USED_IN_PRODUCT_LISTING => $this->isUsedInProductListing,
260
            self::SCOPE => $this->scope,
261
            self::ENTITY_TYPE_ID => $this->entityTypeId,
262
            self::IS_REQUIRED => $this->isRequired,
263
            self::DEFAULT_FRONTEND_LABEL => $this->defaultFrontendLabel,
264
            self::FRONTEND_LABELS => $this->frontendLabels,
265
            self::BACKEND_TYPE => $this->backendType,
266
            self::SOURCE_MODEL => $this->sourceModel,
267
            self::DEFAULT_VALUE => $this->defaultValue,
268
            self::VALIDATION_RULES => $this->validationRules,
269
        ];
270
    }
271
}
272