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

Offer::GetPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 12
ccs 6
cts 6
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\Review;
10
use SignpostMarv\DaftObject\SchemaOrg\DataTypes\Date;
11
use SignpostMarv\DaftObject\SchemaOrg\DataTypes\DateTime;
12
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\BusinessEntityType;
13
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\BusinessFunction;
14
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\DeliveryMethod;
15
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\ItemAvailability;
16
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\OfferItemCondition;
17
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\PaymentMethod;
18
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Enumeration\PhysicalActivityCategory;
19
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Rating\AggregateRating;
20
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Service;
21
use SignpostMarv\DaftObject\SchemaOrg\Intangible\Service\FinancialProduct\LoanOrCredit;
22
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\PriceSpecification;
23
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\QuantitativeValue;
24
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\TypeAndQuantityNode;
25
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue\WarrantyPromise;
26
use SignpostMarv\DaftObject\SchemaOrg\Place\AdministrativeArea;
27
28
/**
29
* @property array<int, LoanOrCredit|PaymentMethod> $acceptedPaymentMethod
30
* @property array<int, Offer> $addOn
31
* @property array<int, QuantitativeValue> $advanceBookingRequirement
32
* @property array<int, AggregateRating> $aggregateRating
33
* @property array<int, string|AdministrativeArea|GeoShape|Place> $areaServed
34
* @property array<int, ItemAvailability> $availability
35
* @property array<int, DateTime> $availabilityEnds
36
* @property array<int, DateTime> $availabilityStarts
37
* @property array<int, Place> $availableAtOrFrom
38
* @property array<int, DeliveryMethod> $availableDeliveryMethod
39
* @property array<int, Type> $businessFunction
40
* @property array<int, string|Thing|PhysicalActivityCategory> $category
41
* @property array<int, QuantitativeValue> $deliveryLeadTime
42
* @property array<int, BusinessEntityType> $eligibleCustomerType
43
* @property array<int, QuantitativeValue> $eligibleDuration
44
* @property array<int, QuantitativeValue> $eligibleQuantity
45
* @property array<int, string|GeoShape|Place> $eligibleRegion
46
* @property array<int, PriceSpecification> $eligibleTransactionVolume
47
* @property array<int, string> $gtin12
48
* @property array<int, string> $gtin13
49
* @property array<int, string> $gtin14
50
* @property array<int, string> $gtin8
51
* @property array<int, TypeAndQuantityNode> $includesObject
52
* @property array<int, string|GeoShape|Place> $ineligibleRegion
53
* @property array<int, QuantitativeValue> $inventoryLevel
54
* @property array<int, OfferItemCondition> $itemCondition
55
* @property array<int, Product|Service> $itemOffered
56
* @property array<int, string> $mpn
57
* @property array<int, Organization|Person> $offeredBy
58
* @property array<int, string|float|int> $price
59
* @property array<int, string> $priceCurrency
60
* @property array<int, PriceSpecification> $priceSpecification
61
* @property array<int, Date> $priceValidUntil
62
* @property array<int, Review> $review
63
* @property array<int, Organization|Person> $seller
64
* @property array<int, string> $serialNumber
65
* @property array<int, string> $sku
66
* @property array<int, DateTime> $validFrom
67
* @property array<int, DateTime> $validThrough
68
* @property array<int, WarrantyPromise> $warranty
69
*/
70
class Offer extends Thing
71
{
72
    use DaftObjectTraits\IsOfferOrDemand;
73
    use DaftObjectTraits\HasAggregateRating;
74
    use DaftObjectTraits\HasCategory;
75
    use DaftObjectTraits\HasItemCondition;
76
    use DaftObjectTraits\HasMpn;
77
    use DaftObjectTraits\HasReview;
78
79
    const SCHEMA_ORG_TYPE = 'Offer';
80
81
    const PROPERTIES = [
82
        'acceptedPaymentMethod',
83
        'addOn',
84
        'advanceBookingRequirement',
85
        'aggregateRating',
86
        'areaServed',
87
        'availability',
88
        'availabilityEnds',
89
        'availabilityStarts',
90
        'availableAtOrFrom',
91
        'availableDeliveryMethod',
92
        'businessFunction',
93
        'category',
94
        'deliveryLeadTime',
95
        'eligibleCustomerType',
96
        'eligibleDuration',
97
        'eligibleQuantity',
98
        'eligibleRegion',
99
        'eligibleTransactionVolume',
100
        'gtin12',
101
        'gtin13',
102
        'gtin14',
103
        'gtin8',
104
        'includesObject',
105
        'ineligibleRegion',
106
        'inventoryLevel',
107
        'itemCondition',
108
        'itemOffered',
109
        'mpn',
110
        'offeredBy',
111
        'price',
112
        'priceCurrency',
113
        'priceSpecification',
114
        'priceValidUntil',
115
        'review',
116
        'seller',
117
        'serialNumber',
118
        'sku',
119
        'validFrom',
120
        'validThrough',
121
        'warranty',
122
    ];
123
124
    const PROPERTIES_WITH_MULTI_TYPED_ARRAYS = [
125
        'acceptedPaymentMethod' => [
126
            LoanOrCredit::class,
127
            PaymentMethod::class,
128
        ],
129
        'addOn' => [
130
            Offer::class,
131
        ],
132
        'advanceBookingRequirement' => [
133
            QuantitativeValue::class,
134
        ],
135
        'aggregateRating' => [
136
            AggregateRating::class,
137
        ],
138
        'areaServed' => [
139
            'string',
140
            AdministrativeArea::class,
141
            GeoShape::class,
142
            Place::class,
143
        ],
144
        'availability' => [
145
            ItemAvailability::class,
146
        ],
147
        'availabilityEnds' => [
148
            DateTime::class,
149
        ],
150
        'availabilityStarts' => [
151
            DateTime::class,
152
        ],
153
        'availableAtOrFrom' => [
154
            Place::class,
155
        ],
156
        'availableDeliveryMethod' => [
157
            DeliveryMethod::class,
158
        ],
159
        'businessFunction' => [
160
            BusinessFunction::class,
161
        ],
162
        'category' => [
163
            'string',
164
            Thing::class,
165
            PhysicalActivityCategory::class,
166
        ],
167
        'deliveryLeadTime' => TypeUtilities::MULTI_TYPE_DICT__deliveryLeadTime,
168
        'eligibleCustomerType' => TypeUtilities::MULTI_TYPE_DICT__eligibleCustomerType,
169
        'eligibleDuration' => TypeUtilities::MULTI_TYPE_DICT__eligibleDuration,
170
        'eligibleQuantity' => TypeUtilities::MULTI_TYPE_DICT__eligibleQuantity,
171
        'eligibleRegion' => TypeUtilities::MULTI_TYPE_DICT__eligibleRegion,
172
        'eligibleTransactionVolume' => TypeUtilities::MULTI_TYPE_DICT__eligibleTransactionVolume,
173
        'gtin12' => TypeUtilities::MULTI_TYPE_DICT__gtin12,
174
        'gtin13' => TypeUtilities::MULTI_TYPE_DICT__gtin13,
175
        'gtin14' => TypeUtilities::MULTI_TYPE_DICT__gtin14,
176
        'gtin8' => TypeUtilities::MULTI_TYPE_DICT__gtin8,
177
        'includesObject' => TypeUtilities::MULTI_TYPE_DICT__includesObject,
178
        'ineligibleRegion' => TypeUtilities::MULTI_TYPE_DICT__ineligibleRegion,
179
        'inventoryLevel' => TypeUtilities::MULTI_TYPE_DICT__inventoryLevel,
180
        'itemCondition' => TypeUtilities::MULTI_TYPE_DICT__itemCondition,
181
        'itemOffered' => TypeUtilities::MULTI_TYPE_DICT__itemOffered,
182
        'mpn' => TypeUtilities::MULTI_TYPE_DICT__mpn,
183
        'offeredBy' => [
184
            Organization::class,
185
            Person::class,
186
        ],
187
        'price' => [
188
            'string',
189
            'double',
190
            'integer',
191
        ],
192
        'priceCurrency' => [
193
            'string',
194
        ],
195
        'priceSpecification' => [
196
            PriceSpecification::class,
197
        ],
198
        'priceValidUntil' => [
199
            Date::class,
200
        ],
201
        'review' => [
202
            Review::class,
203
        ],
204
        'seller' => [
205
            Organization::class,
206
            Person::class,
207
        ],
208
        'serialNumber' => [
209
            'string',
210
        ],
211
        'sku' => [
212
            'string',
213
        ],
214
        'validFrom' => [
215
            DateTime::class,
216
        ],
217
        'validThrough' => [
218
            DateTime::class,
219
        ],
220
        'warranty' => [
221
            WarrantyPromise::class,
222
        ],
223
    ];
224
225
    /**
226
    * @return array<int, Offer>
227
    */
228 85
    public function GetAddOn() : array
229
    {
230
        /**
231
        * @var array<int, Offer>
232
        */
233 85
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
234 85
            'addOn',
235 85
            $this->RetrievePropertyValueFromData('addOn'),
236 85
            static::class
237
        );
238
239 85
        return $out;
240
    }
241
242
    /**
243
    * @param array<int, Offer> $value
244
    */
245 1
    public function SetAddOn(array $value) : void
246
    {
247 1
        $this->NudgePropertyValue(
248 1
            'addOn',
249 1
            $value
250
        );
251 1
    }
252
253
    /**
254
    * @return array<int, Organization|Person>
255
    */
256 85
    public function GetOfferedBy() : array
257
    {
258
        /**
259
        * @var array<int, Organization|Person>
260
        */
261 85
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
262 85
            'offeredBy',
263 85
            $this->RetrievePropertyValueFromData('offeredBy'),
264 85
            static::class
265
        );
266
267 85
        return $out;
268
    }
269
270
    /**
271
    * @param array<int, Organization|Person> $value
272
    */
273 1
    public function SetOfferedBy(array $value) : void
274
    {
275 1
        $this->NudgePropertyValue(
276 1
            'offeredBy',
277 1
            $value
278
        );
279 1
    }
280
281
    /**
282
    * @return array<int, string|float|int>
283
    */
284 85
    public function GetPrice() : array
285
    {
286
        /**
287
        * @var array<int, string|float|int>
288
        */
289 85
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
290 85
            'price',
291 85
            $this->RetrievePropertyValueFromData('price'),
292 85
            static::class
293
        );
294
295 85
        return $out;
296
    }
297
298
    /**
299
    * @param array<int, string|float|int> $value
300
    */
301 1
    public function SetPrice(array $value) : void
302
    {
303 1
        $this->NudgePropertyValue(
304 1
            'price',
305 1
            $value,
306 1
            true
307
        );
308 1
    }
309
310
    /**
311
    * @return array<int, string>
312
    */
313 85
    public function GetPriceCurrency() : array
314
    {
315
        /**
316
        * @var array<int, string>
317
        */
318 85
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
319 85
            'priceCurrency',
320 85
            $this->RetrievePropertyValueFromData('priceCurrency'),
321 85
            static::class
322
        );
323
324 85
        return $out;
325
    }
326
327
    /**
328
    * @param array<int, string> $value
329
    */
330 1
    public function SetPriceCurrency(array $value) : void
331
    {
332 1
        $this->NudgePropertyValue(
333 1
            'priceCurrency',
334 1
            $value,
335 1
            true
336
        );
337 1
    }
338
339
    /**
340
    * @return array<int, Date>
341
    */
342 85
    public function GetPriceValidUntil() : array
343
    {
344
        /**
345
        * @var array<int, Date>
346
        */
347 85
        $out = TypeUtilities::ExpectRetrievedValueIsArray(
348 85
            'priceValidUntil',
349 85
            $this->RetrievePropertyValueFromData('priceValidUntil'),
350 85
            static::class
351
        );
352
353 85
        return $out;
354
    }
355
356
    /**
357
    * @param array<int, Date> $value
358
    */
359 1
    public function SetPriceValidUntil(array $value) : void
360
    {
361 1
        $this->NudgePropertyValue(
362 1
            'priceValidUntil',
363 1
            $value
364
        );
365 1
    }
366
}
367