9
9
10
10
use Magento \Directory \Model \CountryFactory ;
11
11
use Magento \Directory \Model \RegionFactory ;
12
+ use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
12
13
use Magento \Framework \Api \Search \FilterGroup ;
13
14
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
15
+ use Magento \Framework \Api \SearchCriteriaInterface ;
16
+ use Magento \Framework \App \ObjectManager ;
14
17
use Magento \Framework \Exception \InputException ;
15
18
use Magento \Framework \Exception \LocalizedException ;
19
+ use Magento \Tax \Api \Data \TaxRateInterface ;
20
+ use Magento \Tax \Api \Data \TaxRuleSearchResultsInterfaceFactory ;
21
+ use Magento \Tax \Api \TaxRateRepositoryInterface ;
22
+ use Magento \Tax \Model \Api \SearchCriteria \TaxRateCollectionProcessor ;
16
23
use Magento \Tax \Model \Calculation \Rate \Converter ;
17
24
use Magento \Tax \Model \ResourceModel \Calculation \Rate \Collection ;
18
25
19
26
/**
20
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
28
*/
22
- class RateRepository implements \ Magento \ Tax \ Api \ TaxRateRepositoryInterface
29
+ class RateRepository implements TaxRateRepositoryInterface
23
30
{
24
31
public const MESSAGE_TAX_RATE_ID_IS_NOT_ALLOWED = 'id is not expected for this request. ' ;
25
32
@@ -38,7 +45,7 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
38
45
protected $ rateRegistry ;
39
46
40
47
/**
41
- * @var \Magento\Tax\Api\Data\ TaxRuleSearchResultsInterfaceFactory
48
+ * @var TaxRuleSearchResultsInterfaceFactory
42
49
*/
43
50
private $ taxRateSearchResultsFactory ;
44
51
@@ -63,7 +70,7 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
63
70
protected $ resourceModel ;
64
71
65
72
/**
66
- * @var \Magento\Framework\Api\ExtensionAttribute\ JoinProcessorInterface
73
+ * @var JoinProcessorInterface
67
74
*/
68
75
protected $ joinProcessor ;
69
76
@@ -75,23 +82,23 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
75
82
/**
76
83
* @param Converter $converter
77
84
* @param RateRegistry $rateRegistry
78
- * @param \Magento\Tax\Api\Data\ TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory
85
+ * @param TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory
79
86
* @param RateFactory $rateFactory
80
87
* @param CountryFactory $countryFactory
81
88
* @param RegionFactory $regionFactory
82
89
* @param \Magento\Tax\Model\ResourceModel\Calculation\Rate $rateResource
83
- * @param \Magento\Framework\Api\ExtensionAttribute\ JoinProcessorInterface $joinProcessor
84
- * @param CollectionProcessorInterface $collectionProcessor
90
+ * @param JoinProcessorInterface $joinProcessor
91
+ * @param CollectionProcessorInterface|null $collectionProcessor
85
92
*/
86
93
public function __construct (
87
94
Converter $ converter ,
88
95
RateRegistry $ rateRegistry ,
89
- \ Magento \ Tax \ Api \ Data \ TaxRuleSearchResultsInterfaceFactory $ taxRateSearchResultsFactory ,
96
+ TaxRuleSearchResultsInterfaceFactory $ taxRateSearchResultsFactory ,
90
97
RateFactory $ rateFactory ,
91
98
CountryFactory $ countryFactory ,
92
99
RegionFactory $ regionFactory ,
93
100
\Magento \Tax \Model \ResourceModel \Calculation \Rate $ rateResource ,
94
- \ Magento \ Framework \ Api \ ExtensionAttribute \ JoinProcessorInterface $ joinProcessor ,
101
+ JoinProcessorInterface $ joinProcessor ,
95
102
CollectionProcessorInterface $ collectionProcessor = null
96
103
) {
97
104
$ this ->converter = $ converter ;
@@ -102,15 +109,14 @@ public function __construct(
102
109
$ this ->regionFactory = $ regionFactory ;
103
110
$ this ->resourceModel = $ rateResource ;
104
111
$ this ->joinProcessor = $ joinProcessor ;
105
- $ this ->collectionProcessor = $ collectionProcessor ?? \Magento \Framework \App \ObjectManager::getInstance ()->get (
106
- 'Magento\Tax\Model\Api\SearchCriteria\TaxRateCollectionProcessor '
107
- );
112
+ $ this ->collectionProcessor = $ collectionProcessor
113
+ ?? ObjectManager::getInstance ()->get (TaxRateCollectionProcessor::class);
108
114
}
109
115
110
116
/**
111
117
* @inheritdoc
112
118
*/
113
- public function save (\ Magento \ Tax \ Api \ Data \ TaxRateInterface $ taxRate )
119
+ public function save (TaxRateInterface $ taxRate )
114
120
{
115
121
if ($ taxRate ->getId ()) {
116
122
$ this ->rateRegistry ->retrieveTaxRate ($ taxRate ->getId ());
@@ -138,7 +144,7 @@ public function get($rateId)
138
144
/**
139
145
* @inheritdoc
140
146
*/
141
- public function delete (\ Magento \ Tax \ Api \ Data \ TaxRateInterface $ taxRate )
147
+ public function delete (TaxRateInterface $ taxRate )
142
148
{
143
149
return $ this ->resourceModel ->delete ($ taxRate );
144
150
}
@@ -157,7 +163,7 @@ public function deleteById($rateId)
157
163
/**
158
164
* @inheritdoc
159
165
*/
160
- public function getList (\ Magento \ Framework \ Api \ SearchCriteriaInterface $ searchCriteria )
166
+ public function getList (SearchCriteriaInterface $ searchCriteria )
161
167
{
162
168
/** @var \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection $collection */
163
169
$ collection = $ this ->rateFactory ->create ()->getCollection ();
@@ -185,7 +191,6 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
185
191
* @param Collection $collection
186
192
* @return void
187
193
* @deprecated 100.2.0
188
- * @throws \Magento\Framework\Exception\InputException
189
194
*/
190
195
protected function addFilterGroupToCollection (FilterGroup $ filterGroup , Collection $ collection )
191
196
{
@@ -221,49 +226,52 @@ protected function translateField($field)
221
226
/**
222
227
* Validate tax rate
223
228
*
224
- * @param \Magento\Tax\Api\Data\ TaxRateInterface $taxRate
229
+ * @param TaxRateInterface $taxRate
225
230
* @throws InputException
226
231
* @return void
227
232
*
228
233
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
229
234
* @SuppressWarnings(PHPMD.NPathComplexity)
230
235
*/
231
- private function validate (\ Magento \ Tax \ Api \ Data \ TaxRateInterface $ taxRate )
236
+ private function validate (TaxRateInterface $ taxRate )
232
237
{
233
238
$ exception = new InputException ();
234
239
235
240
$ countryCode = $ taxRate ->getTaxCountryId ();
241
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
236
242
if (!\Zend_Validate::is ($ countryCode , 'NotEmpty ' )) {
237
243
$ exception ->addError (__ ('"%fieldName" is required. Enter and try again. ' , ['fieldName ' => 'country_id ' ]));
244
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
238
245
} elseif (!\Zend_Validate::is (
239
246
$ this ->countryFactory ->create ()->loadByCode ($ countryCode )->getId (),
240
247
'NotEmpty '
241
248
)) {
242
- $ exception ->addError (
243
- __ (
244
- 'Invalid value of "%value" provided for the %fieldName field. ' ,
245
- [
246
- 'fieldName ' => 'country_id ' ,
247
- 'value ' => $ countryCode
248
- ]
249
- )
250
- );
249
+ $ exception ->addError (__ (
250
+ 'Invalid value of "%value" provided for the %fieldName field. ' ,
251
+ [
252
+ 'fieldName ' => 'country_id ' ,
253
+ 'value ' => $ countryCode
254
+ ]
255
+ ));
251
256
}
252
257
253
258
$ regionCode = $ taxRate ->getTaxRegionId ();
254
259
// if regionCode eq 0 (all regions *), do not validate with existing region list
260
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
255
261
if (\Zend_Validate::is ($ regionCode , 'NotEmpty ' ) &&
262
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
256
263
$ regionCode != "0 " && !\Zend_Validate::is (
257
264
$ this ->regionFactory ->create ()->load ($ regionCode )->getId (),
258
265
'NotEmpty '
259
266
)
260
267
) {
261
- $ exception ->addError (
262
- __ (
263
- 'Invalid value of "%value" provided for the %fieldName field. ' ,
264
- ['fieldName ' => 'region_id ' , 'value ' => $ regionCode ]
265
- )
266
- );
268
+ $ exception ->addError (__ (
269
+ 'Invalid value of "%value" provided for the %fieldName field. ' ,
270
+ [
271
+ 'fieldName ' => 'region_id ' ,
272
+ 'value ' => $ regionCode
273
+ ]
274
+ ));
267
275
}
268
276
269
277
if (!is_numeric ($ taxRate ->getRate ()) || $ taxRate ->getRate () < 0 ) {
@@ -273,6 +281,7 @@ private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
273
281
}
274
282
275
283
if ($ taxRate ->getCode () === null
284
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
276
285
|| !\Zend_Validate::is (trim ($ taxRate ->getCode ()), 'NotEmpty ' )
277
286
) {
278
287
$ exception ->addError (__ ('"%fieldName" is required. Enter and try again. ' , ['fieldName ' => 'code ' ]));
@@ -298,6 +307,7 @@ private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
298
307
}
299
308
} else {
300
309
if ($ taxRate ->getTaxPostcode () === null
310
+ // phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
301
311
|| !\Zend_Validate::is (trim ($ taxRate ->getTaxPostcode ()), 'NotEmpty ' )
302
312
) {
303
313
$ exception ->addError (
0 commit comments