Completed
Push — simplify-address-comparator ( 262042...874173 )
by Kamil
24:53
created

itGivesFixedDiscountOffOnAProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Sylius\Behat\Service\SharedStorageInterface;
17
use Sylius\Component\Core\Factory\PromotionActionFactoryInterface;
18
use Sylius\Component\Core\Factory\PromotionRuleFactoryInterface;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
use Sylius\Component\Core\Model\ProductInterface;
21
use Sylius\Component\Core\Model\PromotionCouponInterface;
22
use Sylius\Component\Core\Model\PromotionInterface;
23
use Sylius\Component\Core\Model\TaxonInterface;
24
use Sylius\Component\Core\Test\Factory\TestPromotionFactoryInterface;
25
use Sylius\Component\Promotion\Factory\PromotionCouponFactoryInterface;
26
use Sylius\Component\Promotion\Model\PromotionActionInterface;
27
use Sylius\Component\Promotion\Model\PromotionRuleInterface;
28
use Sylius\Component\Promotion\Repository\PromotionRepositoryInterface;
29
30
/**
31
 * @author Mateusz Zalewski <[email protected]>
32
 */
33
final class PromotionContext implements Context
34
{
35
    /**
36
     * @var SharedStorageInterface
37
     */
38
    private $sharedStorage;
39
40
    /**
41
     * @var PromotionActionFactoryInterface
42
     */
43
    private $actionFactory;
44
45
    /**
46
     * @var PromotionCouponFactoryInterface
47
     */
48
    private $couponFactory;
49
50
    /**
51
     * @var PromotionRuleFactoryInterface
52
     */
53
    private $ruleFactory;
54
55
    /**
56
     * @var TestPromotionFactoryInterface
57
     */
58
    private $testPromotionFactory;
59
60
    /**
61
     * @var PromotionRepositoryInterface
62
     */
63
    private $promotionRepository;
64
65
    /**
66
     * @var ObjectManager
67
     */
68
    private $objectManager;
69
70
    /**
71
     * @param SharedStorageInterface $sharedStorage
72
     * @param PromotionActionFactoryInterface $actionFactory
73
     * @param PromotionCouponFactoryInterface $couponFactory
74
     * @param PromotionRuleFactoryInterface $ruleFactory
75
     * @param TestPromotionFactoryInterface $testPromotionFactory
76
     * @param PromotionRepositoryInterface $promotionRepository
77
     * @param ObjectManager $objectManager
78
     */
79
    public function __construct(
80
        SharedStorageInterface $sharedStorage,
81
        PromotionActionFactoryInterface $actionFactory,
82
        PromotionCouponFactoryInterface $couponFactory,
83
        PromotionRuleFactoryInterface $ruleFactory,
84
        TestPromotionFactoryInterface $testPromotionFactory,
85
        PromotionRepositoryInterface $promotionRepository,
86
        ObjectManager $objectManager
87
    ) {
88
        $this->sharedStorage = $sharedStorage;
89
        $this->actionFactory = $actionFactory;
90
        $this->couponFactory = $couponFactory;
91
        $this->ruleFactory = $ruleFactory;
92
        $this->testPromotionFactory = $testPromotionFactory;
93
        $this->promotionRepository = $promotionRepository;
94
        $this->objectManager = $objectManager;
95
    }
96
97
    /**
98
     * @Given there is a promotion :promotionName
99
     * @Given there is a promotion :promotionName identified by :promotionCode code
100
     */
101
    public function thereIsPromotion($promotionName, $promotionCode = null)
102
    {
103
        $promotion = $this->testPromotionFactory
104
            ->createForChannel($promotionName, $this->sharedStorage->get('channel'))
105
        ;
106
107
        if (null !== $promotionCode) {
108
            $promotion->setCode($promotionCode);
109
        }
110
111
        $this->promotionRepository->add($promotion);
112
        $this->sharedStorage->set('promotion', $promotion);
113
    }
114
115
    /**
116
     * @Given there is a promotion :promotionName limited to :usageLimit usages
117
     */
118
    public function thereIsPromotionLimitedToUsages($promotionName, $usageLimit)
119
    {
120
        $promotion = $this->testPromotionFactory->createForChannel($promotionName, $this->sharedStorage->get('channel'));
121
122
        $promotion->setUsageLimit($usageLimit);
123
124
        $this->promotionRepository->add($promotion);
125
        $this->sharedStorage->set('promotion', $promotion);
126
    }
127
128
    /**
129
     * @Given the store has promotion :promotionName with coupon :couponCode
130
     * @Given the store has also promotion :promotionName with coupon :couponCode
131
     * @Given the store has a promotion :promotionName with a coupon :couponCode that is limited to :usageLimit usages
132
     */
133
    public function thereIsPromotionWithCoupon($promotionName, $couponCode, $usageLimit = null)
134
    {
135
        /** @var PromotionCouponInterface $coupon */
136
        $coupon = $this->couponFactory->createNew();
137
        $coupon->setCode($couponCode);
138
        $coupon->setUsageLimit($usageLimit);
139
140
        $promotion = $this->testPromotionFactory
141
            ->createForChannel($promotionName, $this->sharedStorage->get('channel'))
142
        ;
143
        $promotion->addCoupon($coupon);
144
        $promotion->setCouponBased(true);
145
146
        $this->promotionRepository->add($promotion);
147
148
        $this->sharedStorage->set('promotion', $promotion);
149
        $this->sharedStorage->set('coupon', $coupon);
150
    }
151
152
    /**
153
     * @Given /^(this promotion) has already expired$/
154
     */
155
    public function thisPromotionHasExpired(PromotionInterface $promotion)
156
    {
157
        $promotion->setEndsAt(new \DateTime('1 day ago'));
158
159
        $this->objectManager->flush();
160
    }
161
162
    /**
163
     * @Given /^(this coupon) has already expired$/
164
     */
165
    public function thisCouponHasExpired(PromotionCouponInterface $coupon)
166
    {
167
        $coupon->setExpiresAt(new \DateTime('1 day ago'));
168
169
        $this->objectManager->flush();
170
    }
171
172
    /**
173
     * @Given /^(this coupon) expires tomorrow$/
174
     */
175
    public function thisCouponExpiresTomorrow(PromotionCouponInterface $coupon)
176
    {
177
        $coupon->setExpiresAt(new \DateTime('tomorrow'));
178
179
        $this->objectManager->flush();
180
    }
181
182
    /**
183
     * @Given /^(this coupon) has already reached its usage limit$/
184
     */
185
    public function thisCouponHasReachedItsUsageLimit(PromotionCouponInterface $coupon)
186
    {
187
        $coupon->setUsed(42);
188
        $coupon->setUsageLimit(42);
189
190
        $this->objectManager->flush();
191
    }
192
193
    /**
194
     * @Given /^(this coupon) can be used (\d+) times?$/
195
     */
196
    public function thisCouponCanBeUsedNTimes(PromotionCouponInterface $coupon, $usageLimit)
197
    {
198
        $coupon->setUsageLimit($usageLimit);
199
200
        $this->objectManager->flush();
201
    }
202
203
    /**
204
     * @Given /^(this coupon) can be used twice per customer$/
205
     */
206
    public function thisCouponCanBeUsedTwicePerCustomer(PromotionCouponInterface $coupon)
207
    {
208
        $coupon->setPerCustomerUsageLimit(2);
209
210
        $this->objectManager->flush();
211
    }
212
213
    /**
214
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order$/
215
     */
216
    public function itGivesFixedDiscountToEveryOrder(PromotionInterface $promotion, $discount)
217
    {
218
        $this->createFixedPromotion($promotion, $discount);
219
    }
220
221
    /**
222
     * @Given /^([^"]+) gives ("[^"]+%") discount to every order$/
223
     */
224
    public function itGivesPercentageDiscountToEveryOrder(PromotionInterface $promotion, $discount)
225
    {
226
        $this->createPercentagePromotion($promotion, $discount);
227
    }
228
229
    /**
230
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order with quantity at least ([^"]+)$/
231
     */
232
    public function itGivesFixedDiscountToEveryOrderWithQuantityAtLeast(
233
        PromotionInterface $promotion,
234
        $discount,
235
        $quantity
236
    ) {
237
        $rule = $this->ruleFactory->createCartQuantity((int) $quantity);
238
239
        $this->createFixedPromotion($promotion, $discount, [], $rule);
240
    }
241
242
    /**
243
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") discount to every order with items total at least ("[^"]+")$/
244
     */
245
    public function itGivesFixedDiscountToEveryOrderWithItemsTotalAtLeast(
246
        PromotionInterface $promotion,
247
        $discount,
248
        $targetAmount
249
    ) {
250
        $rule = $this->ruleFactory->createItemTotal($targetAmount);
251
252
        $this->createFixedPromotion($promotion, $discount, [], $rule);
253
    }
254
255
    /**
256
     * @Given /^([^"]+) gives ("[^"]+%") off on every product when the item total is at least ("(?:€|£|\$)[^"]+")$/
257
     */
258
    public function itGivesOffOnEveryItemWhenItemTotalExceeds(
259
        PromotionInterface $promotion,
260
        $discount,
261
        $targetAmount
262
    ) {
263
        $rule = $this->ruleFactory->createItemTotal($targetAmount);
264
265
        $this->createUnitPercentagePromotion($promotion, $discount, [], $rule);
266
    }
267
268
    /**
269
     * @Given /^([^"]+) gives ("[^"]+%") discount on shipping to every order$/
270
     */
271
    public function itGivesPercentageDiscountOnShippingToEveryOrder(PromotionInterface $promotion, $discount)
272
    {
273
        $action = $this->actionFactory->createShippingPercentageDiscount($discount);
274
        $promotion->addAction($action);
275
276
        $this->objectManager->flush();
277
    }
278
279
    /**
280
     * @Given /^([^"]+) gives free shipping to every order$/
281
     */
282
    public function thePromotionGivesFreeShippingToEveryOrder(PromotionInterface $promotion)
283
    {
284
        $this->itGivesPercentageDiscountOnShippingToEveryOrder($promotion, 1);
285
    }
286
287
    /**
288
     * @Given /^([^"]+) gives ("[^"]+%") off every product (classified as "[^"]+")$/
289
     */
290
    public function itGivesPercentageOffEveryProductClassifiedAs(
291
        PromotionInterface $promotion,
292
        $discount,
293
        TaxonInterface $taxon
294
    ) {
295
        $this->createUnitPercentagePromotion($promotion, $discount, $this->getTaxonFilterConfiguration([$taxon->getCode()]));
296
    }
297
298
    /**
299
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product (classified as "[^"]+")$/
300
     */
301
    public function itGivesFixedOffEveryProductClassifiedAs(
302
        PromotionInterface $promotion,
303
        $discount,
304
        TaxonInterface $taxon
305
    ) {
306
        $this->createUnitFixedPromotion($promotion, $discount, $this->getTaxonFilterConfiguration([$taxon->getCode()]));
307
    }
308
309
    /**
310
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product with minimum price at ("(?:€|£|\$)[^"]+")$/
311
     */
312
    public function thisPromotionGivesOffOnEveryProductWithMinimumPriceAt(
313
        PromotionInterface $promotion,
314
        $discount,
315
        $amount
316
    ) {
317
        $this->createUnitFixedPromotion($promotion, $discount, $this->getPriceRangeFilterConfiguration($amount));
318
    }
319
320
    /**
321
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product priced between ("(?:€|£|\$)[^"]+") and ("(?:€|£|\$)[^"]+")$/
322
     */
323
    public function thisPromotionGivesOffOnEveryProductPricedBetween(
324
        PromotionInterface $promotion,
325
        $discount,
326
        $minAmount,
327
        $maxAmount
328
    ) {
329
        $this->createUnitFixedPromotion(
330
            $promotion,
331
            $discount,
332
            $this->getPriceRangeFilterConfiguration($minAmount, $maxAmount)
333
        );
334
    }
335
336
    /**
337
     * @Given /^([^"]+) gives ("[^"]+%") off on every product with minimum price at ("(?:€|£|\$)[^"]+")$/
338
     */
339
    public function thisPromotionPercentageGivesOffOnEveryProductWithMinimumPriceAt(
340
        PromotionInterface $promotion,
341
        $discount,
342
        $amount
343
    ) {
344
        $this->createUnitPercentagePromotion($promotion, $discount, $this->getPriceRangeFilterConfiguration($amount));
345
    }
346
347
    /**
348
     * @Given /^([^"]+) gives ("[^"]+%") off on every product priced between ("(?:€|£|\$)[^"]+") and ("(?:€|£|\$)[^"]+")$/
349
     */
350
    public function thisPromotionPercentageGivesOffOnEveryProductPricedBetween(
351
        PromotionInterface $promotion,
352
        $discount,
353
        $minAmount,
354
        $maxAmount
355
    ) {
356
        $this->createUnitPercentagePromotion(
357
            $promotion,
358
            $discount,
359
            $this->getPriceRangeFilterConfiguration($minAmount, $maxAmount)
360
        );
361
    }
362
363
    /**
364
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+")$/
365
     */
366
    public function thePromotionGivesOffIfOrderContainsProductsClassifiedAs(
367
        PromotionInterface $promotion,
368
        $discount,
369
        TaxonInterface $taxon
370
    ) {
371
        $rule = $this->ruleFactory->createTaxon([$taxon->getCode()]);
372
373
        $this->createFixedPromotion($promotion, $discount, [], $rule);
374
    }
375
376
    /**
377
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+" or "[^"]+")$/
378
     */
379
    public function thePromotionGivesOffIfOrderContainsProductsClassifiedAsOr(
380
        PromotionInterface $promotion,
381
        $discount,
382
        array $taxons
383
    ) {
384
        $rule = $this->ruleFactory->createTaxon([$taxons[0]->getCode(), $taxons[1]->getCode()]);
385
386
        $this->createFixedPromotion($promotion, $discount, [], $rule);
387
    }
388
389
    /**
390
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains products (classified as "[^"]+") with a minimum value of ("(?:€|£|\$)[^"]+")$/
391
     */
392
    public function thePromotionGivesOffIfOrderContainsProductsClassifiedAsAndPricedAt(
393
        PromotionInterface $promotion,
394
        $discount,
395
        TaxonInterface $taxon,
396
        $amount
397
    ) {
398
        $rule = $this->ruleFactory->createItemsFromTaxonTotal($taxon->getCode(), $amount);
399
400
        $this->createFixedPromotion($promotion, $discount, [], $rule);
401
    }
402
403
    /**
404
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains (\d+) products (classified as "[^"]+")$/
405
     */
406
    public function thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs(
407
        PromotionInterface $promotion,
408
        $discount,
409
        $count,
410
        TaxonInterface $taxon
411
    ) {
412
        $rule = $this->ruleFactory->createContainsTaxon($taxon->getCode(), $count);
413
414
        $this->createFixedPromotion($promotion, $discount, [], $rule);
415
    }
416
417
    /**
418
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off customer's (\d)(?:st|nd|rd|th) order$/
419
     */
420
    public function itGivesFixedOffCustomersNthOrder(PromotionInterface $promotion, $discount, $nth)
421
    {
422
        $rule = $this->ruleFactory->createNthOrder((int) $nth);
423
424
        $this->createFixedPromotion($promotion, $discount, [], $rule);
425
    }
426
427
    /**
428
     * @Given /^([^"]+) gives ("[^"]+%") off on the customer's (\d)(?:st|nd|rd|th) order$/
429
     */
430
    public function itGivesPercentageOffCustomersNthOrder(PromotionInterface $promotion, $discount, $nth)
431
    {
432
        $rule = $this->ruleFactory->createNthOrder((int) $nth);
433
434
        $this->createPercentagePromotion($promotion, $discount, [], $rule);
435
    }
436
437
    /**
438
     * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") if an order contains any product (classified as "[^"]+")$/
439
     */
440
    public function itGivesPercentageOffOnEveryProductClassifiedAsIfAnOrderContainsAnyProductClassifiedAs(
441
        PromotionInterface $promotion,
442
        $discount,
443
        TaxonInterface $discountTaxon,
444
        TaxonInterface $targetTaxon
445
    ) {
446
        $rule = $this->ruleFactory->createContainsTaxon($targetTaxon->getCode(), 1);
447
448
        $this->createUnitPercentagePromotion($promotion, $discount, $this->getTaxonFilterConfiguration([$discountTaxon->getCode()]), $rule);
449
    }
450
451
    /**
452
     * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") and ("(?:€|£|\$)[^"]+") discount on every order$/
453
     */
454
    public function itGivesPercentageOffOnEveryProductClassifiedAsAndAmountDiscountOnOrder(
455
        PromotionInterface $promotion,
456
        $productDiscount,
457
        TaxonInterface $discountTaxon,
458
        $orderDiscount
459
    ) {
460
        $this->createUnitPercentagePromotion($promotion, $productDiscount, $this->getTaxonFilterConfiguration([$discountTaxon->getCode()]));
461
        $this->createFixedPromotion($promotion, $orderDiscount);
462
    }
463
464
    /**
465
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product (classified as "[^"]+") and a free shipping to every order with items total equal at least ("[^"]+")$/
466
     */
467
    public function itGivesOffOnEveryProductClassifiedAsAndAFreeShippingToEveryOrderWithItemsTotalEqualAtLeast(
468
        PromotionInterface $promotion,
469
        $discount,
470
        TaxonInterface $taxon,
0 ignored issues
show
Unused Code introduced by
The parameter $taxon is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
471
        $targetAmount
472
    ) {
473
        $freeShippingAction = $this->actionFactory->createShippingPercentageDiscount(1);
474
        $promotion->addAction($freeShippingAction);
475
476
        $rule = $this->ruleFactory->createItemTotal($targetAmount);
477
478
        $this->createUnitFixedPromotion($promotion, $discount, [], $rule);
479
    }
480
481
    /**
482
     * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") and a ("(?:€|£|\$)[^"]+") discount to every order with items total equal at least ("(?:€|£|\$)[^"]+")$/
483
     */
484
    public function itGivesOffOnEveryProductClassifiedAsAndAFixedDiscountToEveryOrderWithItemsTotalEqualAtLeast(
485
        PromotionInterface $promotion,
486
        $taxonDiscount,
487
        TaxonInterface $taxon,
488
        $orderDiscount,
489
        $targetAmount
490
    ) {
491
        $orderDiscountAction = $this->actionFactory->createFixedDiscount($orderDiscount);
492
        $promotion->addAction($orderDiscountAction);
493
494
        $rule = $this->ruleFactory->createItemTotal($targetAmount);
495
496
        $this->createUnitPercentagePromotion(
497
            $promotion,
498
            $taxonDiscount,
499
            $this->getTaxonFilterConfiguration([$taxon->getCode()]),
500
            $rule
501
        );
502
    }
503
504
    /**
505
     * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+" or "[^"]+") if order contains any product (classified as "[^"]+" or "[^"]+")$/
506
     */
507
    public function itGivesOffOnEveryProductClassifiedAsOrIfOrderContainsAnyProductClassifiedAsOr(
508
        PromotionInterface $promotion,
509
        $discount,
510
        array $discountTaxons,
511
        array $targetTaxons
512
    ) {
513
        $discountTaxonsCodes = [$discountTaxons[0]->getCode(), $discountTaxons[1]->getCode()];
514
        $targetTaxonsCodes = [$targetTaxons[0]->getCode(), $targetTaxons[1]->getCode()];
515
516
        $rule = $this->ruleFactory->createTaxon($targetTaxonsCodes);
517
518
        $this->createUnitPercentagePromotion(
519
            $promotion,
520
            $discount,
521
            $this->getTaxonFilterConfiguration($discountTaxonsCodes),
522
            $rule
523
        );
524
    }
525
526
    /**
527
     * @Given /^(it) is coupon based promotion$/
528
     */
529
    public function itIsCouponBasedPromotion(PromotionInterface $promotion)
530
    {
531
        $promotion->setCouponBased(true);
532
533
        $this->objectManager->flush();
534
    }
535
536
    /**
537
     * @Given /^(the promotion) was disabled for the (channel "[^"]+")$/
538
     */
539
    public function thePromotionWasDisabledForTheChannel(PromotionInterface $promotion, ChannelInterface $channel)
540
    {
541
        $promotion->removeChannel($channel);
542
543
        $this->objectManager->flush();
544
    }
545
546
    /**
547
     * @Given /^the (coupon "[^"]+") was used up to its usage limit$/
548
     */
549
    public function theCouponWasUsed(PromotionCouponInterface $coupon)
550
    {
551
        $coupon->setUsed($coupon->getUsageLimit());
552
553
        $this->objectManager->flush();
554
    }
555
556
    /**
557
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains (?:a|an) ("[^"]+" product)$/
558
     */
559
    public function thePromotionGivesOffIfOrderContainsProducts(PromotionInterface $promotion, $discount, ProductInterface $product)
560
    {
561
        $rule = $this->ruleFactory->createContainsProduct($product->getCode());
562
563
        $this->createFixedPromotion($promotion, $discount, [], $rule);
564
    }
565
566
    /**
567
     * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on a ("[^"]*" product)$/
568
     */
569
    public function itGivesFixedDiscountOffOnAProduct(PromotionInterface $promotion, $discount, ProductInterface $product)
570
    {
571
        $this->createUnitFixedPromotion($promotion, $discount, $this->getProductsFilterConfiguration([$product->getCode()]));
572
    }
573
574
    /**
575
     * @Given /^([^"]+) gives ("[^"]+%") off on a ("[^"]*" product)$/
576
     */
577
    public function itGivesPercentageDiscountOffOnAProduct(PromotionInterface $promotion, $discount, ProductInterface $product)
578
    {
579
        $this->createUnitPercentagePromotion($promotion, $discount, $this->getProductsFilterConfiguration([$product->getCode()]));
580
    }
581
582
    /**
583
     * @param array $taxonCodes
584
     *
585
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,array<string,array>>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
586
     */
587
    private function getTaxonFilterConfiguration(array $taxonCodes)
588
    {
589
        return ['filters' => ['taxons_filter' => ['taxons' => $taxonCodes]]];
590
    }
591
592
    /**
593
     * @param array $productCodes
594
     *
595
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,array<string,array>>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
596
     */
597
    private function getProductsFilterConfiguration(array $productCodes)
598
    {
599
        return ['filters' => ['products_filter' => ['products' => $productCodes]]];
600
    }
601
602
    /**
603
     * @param int $minAmount
604
     * @param int $maxAmount
0 ignored issues
show
Documentation introduced by
Should the type for parameter $maxAmount not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
605
     *
606
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,array<string,integer>>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
607
     */
608
    private function getPriceRangeFilterConfiguration($minAmount, $maxAmount = null)
609
    {
610
        $configuration = ['filters' => ['price_range_filter' => ['min' => $minAmount]]];
611
        if (null !== $maxAmount) {
612
            $configuration['filters']['price_range_filter']['max'] = $maxAmount;
613
        }
614
615
        return $configuration;
616
    }
617
618
    /**
619
     * @param PromotionInterface $promotion
620
     * @param int $discount
621
     * @param array $configuration
622
     */
623
    private function createUnitFixedPromotion(PromotionInterface $promotion, $discount, array $configuration = [], $rule = null)
624
    {
625
        $this->persistPromotion($promotion, $this->actionFactory->createUnitFixedDiscount($discount), $configuration, $rule);
626
    }
627
628
    /**
629
     * @param PromotionInterface $promotion
630
     * @param int $discount
631
     * @param array $configuration
632
     */
633
    private function createUnitPercentagePromotion(PromotionInterface $promotion, $discount, array $configuration = [], $rule = null)
634
    {
635
        $this->persistPromotion($promotion, $this->actionFactory->createUnitPercentageDiscount($discount), $configuration, $rule);
636
    }
637
638
    /**
639
     * @param PromotionInterface $promotion
640
     * @param int $discount
641
     * @param array $configuration
642
     * @param PromotionRuleInterface $rule
0 ignored issues
show
Documentation introduced by
Should the type for parameter $rule not be null|PromotionRuleInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
643
     */
644
    private function createFixedPromotion(PromotionInterface $promotion, $discount, array $configuration = [], PromotionRuleInterface $rule = null)
645
    {
646
        $this->persistPromotion($promotion, $this->actionFactory->createFixedDiscount($discount), $configuration, $rule);
647
    }
648
649
    /**
650
     * @param PromotionInterface $promotion
651
     * @param float $discount
652
     * @param array $configuration
653
     * @param PromotionRuleInterface $rule
0 ignored issues
show
Documentation introduced by
Should the type for parameter $rule not be null|PromotionRuleInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
654
     */
655
    private function createPercentagePromotion(PromotionInterface $promotion, $discount, array $configuration = [], PromotionRuleInterface $rule = null)
656
    {
657
        $this->persistPromotion($promotion, $this->actionFactory->createPercentageDiscount($discount), $configuration, $rule);
658
    }
659
660
    /**
661
     * @param PromotionInterface $promotion
662
     * @param PromotionActionInterface $action
663
     * @param array $configuration
664
     * @param PromotionRuleInterface|null $rule
665
     */
666
    private function persistPromotion(PromotionInterface $promotion, PromotionActionInterface $action, array $configuration, PromotionRuleInterface $rule = null)
667
    {
668
        $configuration = array_merge($configuration, $action->getConfiguration());
669
        $action->setConfiguration($configuration);
670
671
        $promotion->addAction($action);
672
        if (null !== $rule) {
673
            $promotion->addRule($rule);
674
        }
675
676
        $this->objectManager->flush();
677
    }
678
}
679