ExpenseMapper::mapExpenses()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 33
rs 9.536
cc 3
nc 3
nop 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\OrderTransfer;
0 ignored issues
show
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...
11
use Spryker\Shared\Shipment\ShipmentConfig;
12
use SprykerEco\Shared\Payone\PayoneApiConstants;
13
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
14
15
class ExpenseMapper implements ExpenseMapperInterface
16
{
17
    protected const HANDLING_PRODUCT_DESCRIPTION = 'Handling';
18
    protected const ZERRO_ITEM_TAX_RATE = 0;
19
    protected const ONE_ITEM_AMOUNT = 1;
20
21
    /**
22
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
23
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
24
     *
25
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
26
     */
27
    public function mapExpenses(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
28
    {
29
        $arrayIt = $container->getIt() ?? [];
30
        $arrayId = $container->getId() ?? [];
31
        $arrayPr = $container->getPr() ?? [];
32
        $arrayNo = $container->getNo() ?? [];
33
        $arrayDe = $container->getDe() ?? [];
34
        $arrayVa = $container->getVa() ?? [];
35
36
        $key = count($arrayId) + 1;
37
38
        foreach ($orderTransfer->getExpenses() as $expense) {
39
            if ($expense->getType() === ShipmentConfig::SHIPMENT_EXPENSE_TYPE) {
40
                continue;
41
            }
42
43
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
44
            $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
45
            $arrayPr[$key] = $expense->getSumGrossPrice();
46
            $arrayNo[$key] = static::ONE_ITEM_AMOUNT;
47
            $arrayDe[$key] = static::HANDLING_PRODUCT_DESCRIPTION;
48
            $arrayVa[$key] = static::ZERRO_ITEM_TAX_RATE;
49
            $key++;
50
        }
51
52
        $container->setIt($arrayIt);
53
        $container->setId($arrayId);
54
        $container->setPr($arrayPr);
55
        $container->setNo($arrayNo);
56
        $container->setDe($arrayDe);
57
        $container->setVa($arrayVa);
58
59
        return $container;
60
    }
61
}
62