Passed
Pull Request — master (#67)
by
unknown
09:59
created

ProductMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 27
c 1
b 0
f 0
dl 0
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaxRateFromItemTransfer() 0 8 2
A mapProductItems() 0 29 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment\DataMapper;
9
10
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Spryker\DecimalObject\Decimal;
12
use SprykerEco\Shared\Payone\PayoneApiConstants;
13
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
14
15
class ProductMapper implements ProductMapperInterface
16
{
17
    /**
18
     * @param \Generated\Shared\Transfer\OrderTransfer|\Generated\Shared\Transfer\QuoteTransfer $itemsContainer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $requestContainer
20
     *
21
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
22
     */
23
    public function mapProductItems($itemsContainer, AbstractRequestContainer $requestContainer): AbstractRequestContainer
24
    {
25
        $arrayIt = [];
26
        $arrayId = [];
27
        $arrayPr = [];
28
        $arrayNo = [];
29
        $arrayDe = [];
30
        $arrayVa = [];
31
32
        $key = 1;
33
34
        foreach ($itemsContainer->getItems() as $itemTransfer) {
35
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
36
            $arrayId[$key] = $itemTransfer->getSku();
37
            $arrayPr[$key] = $itemTransfer->getUnitGrossPrice();
38
            $arrayNo[$key] = $itemTransfer->getQuantity();
39
            $arrayDe[$key] = $itemTransfer->getName();
40
            $arrayVa[$key] = $this->getTaxRateFromItemTransfer($itemTransfer);
41
            $key++;
42
        }
43
44
        $requestContainer->setIt($arrayIt);
45
        $requestContainer->setId($arrayId);
46
        $requestContainer->setPr($arrayPr);
47
        $requestContainer->setNo($arrayNo);
48
        $requestContainer->setDe($arrayDe);
49
        $requestContainer->setVa($arrayVa);
50
51
        return $requestContainer;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
56
     *
57
     * @return int
58
     */
59
    protected function getTaxRateFromItemTransfer(ItemTransfer $itemTransfer): int
60
    {
61
        $taxRateValue = $itemTransfer->getTaxRate();
62
        if ($taxRateValue instanceof Decimal) {
63
            return $taxRateValue->toInt();
64
        }
65
66
        return (int)$taxRateValue;
67
    }
68
}
69