Completed
Push — master ( 9db63e...40913a )
by Oleksandr
24s queued 13s
created

ShipmentMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDeliveryCosts() 0 9 3
A mapShipment() 0 26 1
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 Spryker\Shared\Shipment\ShipmentConfig;
11
use SprykerEco\Shared\Payone\PayoneApiConstants;
12
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
13
14
class ShipmentMapper implements ShipmentMapperInterface
15
{
16
    protected const SHIPMENT_PRODUCT_DESCRIPTION = 'Shipment';
17
    protected const ZERRO_ITEM_TAX_RATE = 0;
18
    protected const ONE_ITEM_AMOUNT = 1;
19
20
    /**
21
     * @param \Generated\Shared\Transfer\OrderTransfer|\Generated\Shared\Transfer\QuoteTransfer $shipmentContainer
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...
22
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
23
     *
24
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
25
     */
26
    public function mapShipment($shipmentContainer, AbstractRequestContainer $container): AbstractRequestContainer
27
    {
28
        $arrayIt = $container->getIt() ?? [];
29
        $arrayId = $container->getId() ?? [];
30
        $arrayPr = $container->getPr() ?? [];
31
        $arrayNo = $container->getNo() ?? [];
32
        $arrayDe = $container->getDe() ?? [];
33
        $arrayVa = $container->getVa() ?? [];
34
35
        $key = count($arrayId) + 1;
36
37
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
38
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
39
        $arrayPr[$key] = $this->getDeliveryCosts($shipmentContainer);
40
        $arrayNo[$key] = static::ONE_ITEM_AMOUNT;
41
        $arrayDe[$key] = static::SHIPMENT_PRODUCT_DESCRIPTION;
42
        $arrayVa[$key] = static::ZERRO_ITEM_TAX_RATE;
43
44
        $container->setIt($arrayIt);
45
        $container->setId($arrayId);
46
        $container->setPr($arrayPr);
47
        $container->setNo($arrayNo);
48
        $container->setDe($arrayDe);
49
        $container->setVa($arrayVa);
50
51
        return $container;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\OrderTransfer|\Generated\Shared\Transfer\QuoteTransfer $expenseContainer
56
     *
57
     * @return int
58
     */
59
    protected function getDeliveryCosts($expenseContainer): int
60
    {
61
        foreach ($expenseContainer->getExpenses() as $expense) {
62
            if ($expense->getType() === ShipmentConfig::SHIPMENT_EXPENSE_TYPE) {
63
                return $expense->getSumGrossPrice();
64
            }
65
        }
66
67
        return 0;
68
    }
69
}
70