5
5
namespace Setono \SyliusCatalogPromotionPlugin \Factory ;
6
6
7
7
use InvalidArgumentException ;
8
+ use Setono \SyliusCatalogPromotionPlugin \Checker \PreQualification \Rule \ContainsProductRuleChecker ;
9
+ use Setono \SyliusCatalogPromotionPlugin \Checker \PreQualification \Rule \ContainsProductsRuleChecker ;
10
+ use Setono \SyliusCatalogPromotionPlugin \Checker \PreQualification \Rule \HasNotTaxonRuleChecker ;
11
+ use Setono \SyliusCatalogPromotionPlugin \Checker \PreQualification \Rule \HasTaxonRuleChecker ;
8
12
use Setono \SyliusCatalogPromotionPlugin \Model \PromotionRuleInterface ;
9
- use Setono \SyliusCatalogPromotionPlugin \Rule \ContainsProductRule ;
10
- use Setono \SyliusCatalogPromotionPlugin \Rule \ContainsProductsRule ;
11
- use Setono \SyliusCatalogPromotionPlugin \Rule \HasNotTaxonRule ;
12
- use Setono \SyliusCatalogPromotionPlugin \Rule \HasTaxonRule ;
13
- use function sprintf ;
14
13
use Sylius \Component \Resource \Factory \FactoryInterface ;
15
14
use Webmozart \Assert \Assert ;
16
15
17
16
final class PromotionRuleFactory implements PromotionRuleFactoryInterface
18
17
{
19
- private FactoryInterface $ decoratedFactory ;
20
-
21
- private array $ rules ;
22
-
23
- public function __construct (
24
- FactoryInterface $ decoratedFactory ,
25
- array $ rules ,
26
- ) {
27
- $ this ->decoratedFactory = $ decoratedFactory ;
28
- $ this ->rules = $ rules ;
18
+ public function __construct (private readonly FactoryInterface $ decoratedFactory , private readonly array $ rules )
19
+ {
29
20
}
30
21
31
22
public function createNew (): PromotionRuleInterface
32
23
{
33
- /** @var PromotionRuleInterface $obj */
34
24
$ obj = $ this ->decoratedFactory ->createNew ();
25
+ Assert::isInstanceOf ($ obj , PromotionRuleInterface::class);
35
26
36
27
return $ obj ;
37
28
}
38
29
39
30
public function createByType (string $ type , array $ configuration , bool $ strict = false ): PromotionRuleInterface
40
31
{
41
32
switch ($ type ) {
42
- case HasTaxonRule ::TYPE :
33
+ case HasTaxonRuleChecker ::TYPE :
43
34
Assert::keyExists ($ configuration , 'taxons ' );
44
35
Assert::isArray ($ configuration ['taxons ' ]);
45
36
46
37
return $ this ->createHasTaxon ($ configuration ['taxons ' ]);
47
- case HasNotTaxonRule ::TYPE :
38
+ case HasNotTaxonRuleChecker ::TYPE :
48
39
Assert::keyExists ($ configuration , 'taxons ' );
49
40
Assert::isArray ($ configuration ['taxons ' ]);
50
41
51
42
return $ this ->createHasNotTaxon ($ configuration ['taxons ' ]);
52
- case ContainsProductRule ::TYPE :
43
+ case ContainsProductRuleChecker ::TYPE :
53
44
Assert::keyExists ($ configuration , 'product ' );
54
45
Assert::string ($ configuration ['product ' ]);
55
46
56
47
return $ this ->createContainsProduct ($ configuration ['product ' ]);
57
- case ContainsProductsRule ::TYPE :
48
+ case ContainsProductsRuleChecker ::TYPE :
58
49
Assert::keyExists ($ configuration , 'products ' );
59
50
Assert::isArray ($ configuration ['products ' ]);
60
51
@@ -76,7 +67,7 @@ public function createHasTaxon(array $taxonCodes): PromotionRuleInterface
76
67
Assert::allString ($ taxonCodes );
77
68
78
69
return $ this ->createPromotionRule (
79
- HasTaxonRule ::TYPE ,
70
+ HasTaxonRuleChecker ::TYPE ,
80
71
['taxons ' => $ taxonCodes ],
81
72
);
82
73
}
@@ -86,15 +77,15 @@ public function createHasNotTaxon(array $taxonCodes): PromotionRuleInterface
86
77
Assert::allString ($ taxonCodes );
87
78
88
79
return $ this ->createPromotionRule (
89
- HasNotTaxonRule ::TYPE ,
80
+ HasNotTaxonRuleChecker ::TYPE ,
90
81
['taxons ' => $ taxonCodes ],
91
82
);
92
83
}
93
84
94
85
public function createContainsProduct (string $ productCode ): PromotionRuleInterface
95
86
{
96
87
return $ this ->createPromotionRule (
97
- ContainsProductRule ::TYPE ,
88
+ ContainsProductRuleChecker ::TYPE ,
98
89
['product ' => $ productCode ],
99
90
);
100
91
}
@@ -104,7 +95,7 @@ public function createContainsProducts(array $productCodes): PromotionRuleInterf
104
95
Assert::allString ($ productCodes );
105
96
106
97
return $ this ->createPromotionRule (
107
- ContainsProductsRule ::TYPE ,
98
+ ContainsProductsRuleChecker ::TYPE ,
108
99
['products ' => $ productCodes ],
109
100
);
110
101
}
0 commit comments