Passed
Push — master ( ffa34c...f9eaa3 )
by SignpostMarv
12:18
created

Product::SetWeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftObject\SchemaOrg;
8
9
use SignpostMarv\DaftObject\SchemaOrg\CreativeWork\MediaObject\ImageObject;
10
use SignpostMarv\DaftObject\SchemaOrg\CreativeWork\Review;
11
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Brand;
12
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\OfferItemCondition;
13
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\PhysicalActivityCategory;
14
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Quantity\Distance;
15
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Rating\AggregateRating;
16
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Service;
17
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\PropertyValue;
18
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\QuantitativeValue;
19
20
/**
21
* @property array<int, PropertyValue> $additionalProperty
22
* @property array<int, AggregateRating> $aggregateRating
23
* @property array<int, Audience> $audience
24
* @property array<int, string> $award
25
* @property array<int, Brand|Organization> $brand
26
* @property array<int, string|Thing|PhysicalActivityCategory> $category
27
* @property array<int, string> $color
28
* @property array<int, Distance|QuantitativeValue> $depth
29
* @property array<int, string> $gtin12
30
* @property array<int, string> $gtin13
31
* @property array<int, string> $gtin14
32
* @property array<int, string> $gtin8
33
* @property array<int, Distance|QuantitativeValue> $height
34
* @property array<int, Product> $isAccessoryOrSparePartFor
35
* @property array<int, Product> $isConsumableFor
36
* @property array<int, Product|Service> $isRelatedTo
37
* @property array<int, Product|Service> $isSimilarTo
38
* @property array<int, OfferItemCondition> $itemCondition
39
* @property array<int, ImageObject> $logo
40
* @property array<int, Organization> $manufacturer
41
* @property array<int, string|Product> $material
42
* @property array<int, string|Product\ProductModel> $model
43
* @property array<int, string> $mpn
44
* @property array<int, Offer> $offers
45
* @property array<int, string> $productID
46
* @property array<int, DataTypes\Date> $productionDate
47
* @property array<int, DataTypes\Date> $purchaseDate
48
* @property array<int, DataTypes\Date> $releaseDate
49
* @property array<int, Review> $review
50
* @property array<int, string> $sku
51
* @property array<int, QuantitativeValue> $weight
52
* @property array<int, Distance|QuantitativeValue> $width
53
*/
54
class Product extends Thing
55
{
56
    use DaftObjectTraits\TraitAdditionalProperty;
57
    use DaftObjectTraits\HasAggregateRating;
58
    use DaftObjectTraits\HasAudience;
59
    use DaftObjectTraits\HasAward;
60
    use DaftObjectTraits\HasBrand;
61
    use DaftObjectTraits\HasCategory;
62
    use DaftObjectTraits\HasGtin;
63
    use DaftObjectTraits\HasHeights;
64
    use DaftObjectTraits\HasItemCondition;
65
    use DaftObjectTraits\HasLogo;
66
    use DaftObjectTraits\IsRelatedOrSimilarTo;
67
    use DaftObjectTraits\HasMaterial;
68
    use DaftObjectTraits\HasMpn;
69
    use DaftObjectTraits\HasOffers;
70
    use DaftObjectTraits\HasReview;
71
    use DaftObjectTraits\HasSku;
72
    use DaftObjectTraits\HasWidth;
73
74
    const SCHEMA_ORG_TYPE = 'Product';
75
76
    const PROPERTIES = [
77
        'additionalProperty',
78
        'aggregateRating',
79
        'audience',
80
        'award',
81
        'brand',
82
        'category',
83
        'color',
84
        'depth',
85
        'gtin12',
86
        'gtin13',
87
        'gtin14',
88
        'gtin8',
89
        'height',
90
        'isAccessoryOrSparePartFor',
91
        'isConsumableFor',
92
        'isRelatedTo',
93
        'isSimilarTo',
94
        'itemCondition',
95
        'logo',
96
        'manufacturer',
97
        'material',
98
        'model',
99
        'mpn',
100
        'offers',
101
        'productID',
102
        'productionDate',
103
        'purchaseDate',
104
        'releaseDate',
105
        'review',
106
        'sku',
107
        'weight',
108
        'width',
109
    ];
110
111
    const PROPERTIES_WITH_MULTI_TYPED_ARRAYS = [
112
        'additionalProperty' => [
113
            PropertyValue::class,
114
        ],
115
        'aggregateRating' => [
116
            AggregateRating::class,
117
        ],
118
        'audience' => [
119
            Audience::class,
120
        ],
121
        'award' => [
122
            'string',
123
        ],
124
        'brand' => [
125
            Brand::class,
126
            Organization::class,
127
        ],
128
        'category' => [
129
            'string',
130
            Thing::class,
131
            PhysicalActivityCategory::class,
132
        ],
133
        'color' => [
134
            'string',
135
        ],
136
        'depth' => [
137
            Distance::class,
138
            QuantitativeValue::class,
139
        ],
140
        'gtin12' => [
141
            'string',
142
        ],
143
        'gtin13' => [
144
            'string',
145
        ],
146
        'gtin14' => [
147
            'string',
148
        ],
149
        'gtin8' => [
150
            'string',
151
        ],
152
        'height' => [
153
            Distance::class,
154
            QuantitativeValue::class,
155
        ],
156
        'isAccessoryOrSparePartFor' => [
157
            Product::class,
158
        ],
159
        'isConsumableFor' => [
160
            Product::class,
161
        ],
162
        'isRelatedTo' => [
163
            Product::class,
164
            Service::class,
165
        ],
166
        'isSimilarTo' => [
167
            Product::class,
168
            Service::class,
169
        ],
170
        'itemCondition' => [
171
            OfferItemCondition::class,
172
        ],
173
        'logo' => [
174
            ImageObject::class,
175
        ],
176
        'manufacturer' => [
177
            Organization::class,
178
        ],
179
        'material' => [
180
            'string',
181
            Product::class,
182
        ],
183
        'model' => [
184
            'string',
185
            Product\ProductModel::class,
186
        ],
187
        'mpn' => [
188
            'string',
189
        ],
190
        'offers' => [
191
            Offer::class,
192
        ],
193
        'productID' => [
194
            'string',
195
        ],
196
        'productionDate' => [
197
            DataTypes\Date::class,
198
        ],
199
        'purchaseDate' => [
200
            DataTypes\Date::class,
201
        ],
202
        'releaseDate' => [
203
            DataTypes\Date::class,
204
        ],
205
        'review' => [
206
            Review::class,
207
        ],
208
        'sku' => [
209
            'string',
210
        ],
211
        'weight' => [
212
            QuantitativeValue::class,
213
        ],
214
        'width' => [
215
            Distance::class,
216
            QuantitativeValue::class,
217
        ],
218
    ];
219
220
    /**
221
    * @return array<int, string>
222
    */
223 90
    public function GetColor() : array
224
    {
225
        /**
226
        * @var array<int, string>
227
        */
228 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
229 90
            'color',
230 90
            $this->RetrievePropertyValueFromData('color'),
231 90
            static::class
232
        );
233
234 90
        return $out;
235
    }
236
237
    /**
238
    * @param array<int, string> $value
239
    */
240 3
    public function SetColor(array $value) : void
241
    {
242 3
        $this->NudgePropertyValue(
243 3
            'color',
244 3
            $value,
245 3
            true
246
        );
247 3
    }
248
249
    /**
250
    * @return array<int, Distance|QuantitativeValue>
251
    */
252 90
    public function GetDepth() : array
253
    {
254
        /**
255
        * @var array<int, Distance|QuantitativeValue>
256
        */
257 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
258 90
            'depth',
259 90
            $this->RetrievePropertyValueFromData('depth'),
260 90
            static::class
261
        );
262
263 90
        return $out;
264
    }
265
266
    /**
267
    * @param array<int, Distance|QuantitativeValue> $value
268
    */
269 3
    public function SetDepth(array $value) : void
270
    {
271 3
        $this->NudgePropertyValue(
272 3
            'depth',
273 3
            $value
274
        );
275 3
    }
276
277
    /**
278
    * @return array<int, Product>
279
    */
280 90
    public function GetIsAccessoryOrSparePartFor() : array
281
    {
282
        /**
283
        * @var array<int, Product>
284
        */
285 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
286 90
            'isAccessoryOrSparePartFor',
287 90
            $this->RetrievePropertyValueFromData('isAccessoryOrSparePartFor'),
288 90
            static::class
289
        );
290
291 90
        return $out;
292
    }
293
294
    /**
295
    * @param array<int, Product> $value
296
    */
297 3
    public function SetIsAccessoryOrSparePartFor(array $value) : void
298
    {
299 3
        $this->NudgePropertyValue(
300 3
            'isAccessoryOrSparePartFor',
301 3
            $value
302
        );
303 3
    }
304
305
    /**
306
    * @return array<int, Product>
307
    */
308 90
    public function GetIsConsumableFor() : array
309
    {
310
        /**
311
        * @var array<int, Product>
312
        */
313 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
314 90
            'isConsumableFor',
315 90
            $this->RetrievePropertyValueFromData('isConsumableFor'),
316 90
            static::class
317
        );
318
319 90
        return $out;
320
    }
321
322
    /**
323
    * @param array<int, Product> $value
324
    */
325 3
    public function SetIsConsumableFor(array $value) : void
326
    {
327 3
        $this->NudgePropertyValue(
328 3
            'isConsumableFor',
329 3
            $value
330
        );
331 3
    }
332
333
    /**
334
    * @return array<int, Organization>
335
    */
336 90
    public function GetManufacturer() : array
337
    {
338
        /**
339
        * @var array<int, Organization>
340
        */
341 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
342 90
            'manufacturer',
343 90
            $this->RetrievePropertyValueFromData('manufacturer'),
344 90
            static::class
345
        );
346
347 90
        return $out;
348
    }
349
350
    /**
351
    * @param array<int, Organization> $value
352
    */
353 3
    public function SetManufacturer(array $value) : void
354
    {
355 3
        $this->NudgePropertyValue(
356 3
            'manufacturer',
357 3
            $value
358
        );
359 3
    }
360
361
    /**
362
    * @return array<int, string|Product\ProductModel>
363
    */
364 90
    public function GetModel() : array
365
    {
366
        /**
367
        * @var array<int, string|Product\ProductModel>
368
        */
369 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
370 90
            'model',
371 90
            $this->RetrievePropertyValueFromData('model'),
372 90
            static::class
373
        );
374
375 90
        return $out;
376
    }
377
378
    /**
379
    * @param array<int, string|Product\ProductModel> $value
380
    */
381 3
    public function SetModel(array $value) : void
382
    {
383 3
        $this->NudgePropertyValue(
384 3
            'model',
385 3
            $value,
386 3
            true
387
        );
388 3
    }
389
390
    /**
391
    * @return array<int, string>
392
    */
393 90
    public function GetProductID() : array
394
    {
395
        /**
396
        * @var array<int, string>
397
        */
398 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
399 90
            'productID',
400 90
            $this->RetrievePropertyValueFromData('productID'),
401 90
            static::class
402
        );
403
404 90
        return $out;
405
    }
406
407
    /**
408
    * @param array<int, string> $value
409
    */
410 3
    public function SetProductID(array $value) : void
411
    {
412 3
        $this->NudgePropertyValue(
413 3
            'productID',
414 3
            $value,
415 3
            true
416
        );
417 3
    }
418
419
    /**
420
    * @return array<int, DataTypes\Date>
421
    */
422 90
    public function GetProductionDate() : array
423
    {
424
        /**
425
        * @var array<int, DataTypes\Date>
426
        */
427 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
428 90
            'productionDate',
429 90
            $this->RetrievePropertyValueFromData('productionDate'),
430 90
            static::class
431
        );
432
433 90
        return $out;
434
    }
435
436
    /**
437
    * @param array<int, DataTypes\Date> $value
438
    */
439 3
    public function SetProductionDate(array $value) : void
440
    {
441 3
        $this->NudgePropertyValue(
442 3
            'productionDate',
443 3
            $value
444
        );
445 3
    }
446
447
    /**
448
    * @return array<int, DataTypes\Date>
449
    */
450 90
    public function GetPurchaseDate() : array
451
    {
452
        /**
453
        * @var array<int, DataTypes\Date>
454
        */
455 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
456 90
            'purchaseDate',
457 90
            $this->RetrievePropertyValueFromData('purchaseDate'),
458 90
            static::class
459
        );
460
461 90
        return $out;
462
    }
463
464
    /**
465
    * @param array<int, DataTypes\Date> $value
466
    */
467 3
    public function SetPurchaseDate(array $value) : void
468
    {
469 3
        $this->NudgePropertyValue(
470 3
            'purchaseDate',
471 3
            $value
472
        );
473 3
    }
474
475
    /**
476
    * @return array<int, DataTypes\Date>
477
    */
478 90
    public function GetReleaseDate() : array
479
    {
480
        /**
481
        * @var array<int, DataTypes\Date>
482
        */
483 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
484 90
            'releaseDate',
485 90
            $this->RetrievePropertyValueFromData('releaseDate'),
486 90
            static::class
487
        );
488
489 90
        return $out;
490
    }
491
492
    /**
493
    * @param array<int, DataTypes\Date> $value
494
    */
495 3
    public function SetReleaseDate(array $value) : void
496
    {
497 3
        $this->NudgePropertyValue(
498 3
            'releaseDate',
499 3
            $value
500
        );
501 3
    }
502
503
    /**
504
    * @return array<int, QuantitativeValue>
505
    */
506 90
    public function GetWeight() : array
507
    {
508
        /**
509
        * @var array<int, QuantitativeValue>
510
        */
511 90
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
512 90
            'weight',
513 90
            $this->RetrievePropertyValueFromData('weight'),
514 90
            static::class
515
        );
516
517 90
        return $out;
518
    }
519
520
    /**
521
    * @param array<int, QuantitativeValue> $value
522
    */
523 3
    public function SetWeight(array $value) : void
524
    {
525 3
        $this->NudgePropertyValue(
526 3
            'weight',
527 3
            $value
528
        );
529 3
    }
530
}
531