Skip to content

Commit 461f217

Browse files
committed
CE#34569: Fixed MHI failures
1 parent b85d00f commit 461f217

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

app/code/Magento/Tax/Model/Calculation/RateRepository.php

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@
99

1010
use Magento\Directory\Model\CountryFactory;
1111
use Magento\Directory\Model\RegionFactory;
12+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1213
use Magento\Framework\Api\Search\FilterGroup;
1314
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
15+
use Magento\Framework\Api\SearchCriteriaInterface;
16+
use Magento\Framework\App\ObjectManager;
1417
use Magento\Framework\Exception\InputException;
1518
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;
1623
use Magento\Tax\Model\Calculation\Rate\Converter;
1724
use Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection;
1825

1926
/**
2027
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2128
*/
22-
class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
29+
class RateRepository implements TaxRateRepositoryInterface
2330
{
2431
public const MESSAGE_TAX_RATE_ID_IS_NOT_ALLOWED = 'id is not expected for this request.';
2532

@@ -38,7 +45,7 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
3845
protected $rateRegistry;
3946

4047
/**
41-
* @var \Magento\Tax\Api\Data\TaxRuleSearchResultsInterfaceFactory
48+
* @var TaxRuleSearchResultsInterfaceFactory
4249
*/
4350
private $taxRateSearchResultsFactory;
4451

@@ -63,7 +70,7 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
6370
protected $resourceModel;
6471

6572
/**
66-
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface
73+
* @var JoinProcessorInterface
6774
*/
6875
protected $joinProcessor;
6976

@@ -75,23 +82,23 @@ class RateRepository implements \Magento\Tax\Api\TaxRateRepositoryInterface
7582
/**
7683
* @param Converter $converter
7784
* @param RateRegistry $rateRegistry
78-
* @param \Magento\Tax\Api\Data\TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory
85+
* @param TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory
7986
* @param RateFactory $rateFactory
8087
* @param CountryFactory $countryFactory
8188
* @param RegionFactory $regionFactory
8289
* @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
8592
*/
8693
public function __construct(
8794
Converter $converter,
8895
RateRegistry $rateRegistry,
89-
\Magento\Tax\Api\Data\TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory,
96+
TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory,
9097
RateFactory $rateFactory,
9198
CountryFactory $countryFactory,
9299
RegionFactory $regionFactory,
93100
\Magento\Tax\Model\ResourceModel\Calculation\Rate $rateResource,
94-
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
101+
JoinProcessorInterface $joinProcessor,
95102
CollectionProcessorInterface $collectionProcessor = null
96103
) {
97104
$this->converter = $converter;
@@ -102,15 +109,14 @@ public function __construct(
102109
$this->regionFactory = $regionFactory;
103110
$this->resourceModel = $rateResource;
104111
$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);
108114
}
109115

110116
/**
111117
* @inheritdoc
112118
*/
113-
public function save(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
119+
public function save(TaxRateInterface $taxRate)
114120
{
115121
if ($taxRate->getId()) {
116122
$this->rateRegistry->retrieveTaxRate($taxRate->getId());
@@ -138,7 +144,7 @@ public function get($rateId)
138144
/**
139145
* @inheritdoc
140146
*/
141-
public function delete(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
147+
public function delete(TaxRateInterface $taxRate)
142148
{
143149
return $this->resourceModel->delete($taxRate);
144150
}
@@ -157,7 +163,7 @@ public function deleteById($rateId)
157163
/**
158164
* @inheritdoc
159165
*/
160-
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
166+
public function getList(SearchCriteriaInterface $searchCriteria)
161167
{
162168
/** @var \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection $collection */
163169
$collection = $this->rateFactory->create()->getCollection();
@@ -185,7 +191,6 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
185191
* @param Collection $collection
186192
* @return void
187193
* @deprecated 100.2.0
188-
* @throws \Magento\Framework\Exception\InputException
189194
*/
190195
protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
191196
{
@@ -221,49 +226,52 @@ protected function translateField($field)
221226
/**
222227
* Validate tax rate
223228
*
224-
* @param \Magento\Tax\Api\Data\TaxRateInterface $taxRate
229+
* @param TaxRateInterface $taxRate
225230
* @throws InputException
226231
* @return void
227232
*
228233
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
229234
* @SuppressWarnings(PHPMD.NPathComplexity)
230235
*/
231-
private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
236+
private function validate(TaxRateInterface $taxRate)
232237
{
233238
$exception = new InputException();
234239

235240
$countryCode = $taxRate->getTaxCountryId();
241+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
236242
if (!\Zend_Validate::is($countryCode, 'NotEmpty')) {
237243
$exception->addError(__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'country_id']));
244+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
238245
} elseif (!\Zend_Validate::is(
239246
$this->countryFactory->create()->loadByCode($countryCode)->getId(),
240247
'NotEmpty'
241248
)) {
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+
));
251256
}
252257

253258
$regionCode = $taxRate->getTaxRegionId();
254259
// if regionCode eq 0 (all regions *), do not validate with existing region list
260+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
255261
if (\Zend_Validate::is($regionCode, 'NotEmpty') &&
262+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
256263
$regionCode != "0" && !\Zend_Validate::is(
257264
$this->regionFactory->create()->load($regionCode)->getId(),
258265
'NotEmpty'
259266
)
260267
) {
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+
));
267275
}
268276

269277
if (!is_numeric($taxRate->getRate()) || $taxRate->getRate() < 0) {
@@ -273,6 +281,7 @@ private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
273281
}
274282

275283
if ($taxRate->getCode() === null
284+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
276285
|| !\Zend_Validate::is(trim($taxRate->getCode()), 'NotEmpty')
277286
) {
278287
$exception->addError(__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'code']));
@@ -298,6 +307,7 @@ private function validate(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)
298307
}
299308
} else {
300309
if ($taxRate->getTaxPostcode() === null
310+
// phpstan:ignore "File has calls static method. (phpStaticMethodCalls)"
301311
|| !\Zend_Validate::is(trim($taxRate->getTaxPostcode()), 'NotEmpty')
302312
) {
303313
$exception->addError(

0 commit comments

Comments
 (0)