Completed
Push — master ( 2a18cf...56a686 )
by Oleksandr
14s queued 11s
created

savePaymentHeidelpayNotificationEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 16
rs 9.9332
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Heidelpay\Persistence;
9
10
use Generated\Shared\Transfer\HeidelpayNotificationTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...payNotificationTransfer 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 Generated\Shared\Transfer\HeidelpayPaymentTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\HeidelpayPaymentTransfer 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...
12
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayNotificationQuery;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Heidelpay\Persis...delpayNotificationQuery 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...
13
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayQuery;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Heidelpay\Persis...pyPaymentHeidelpayQuery 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...
14
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
15
use SprykerEco\Zed\Heidelpay\Persistence\Propel\Mapper\HeidelpayPersistenceMapper;
16
17
/**
18
 * @method \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayPersistenceFactory getFactory()
19
 */
20
class HeidelpayEntityManager extends AbstractEntityManager implements HeidelpayEntityManagerInterface
21
{
22
    /**
23
     * @param \Generated\Shared\Transfer\HeidelpayPaymentTransfer $heidelpayPaymentTransfer
24
     *
25
     * @return \Generated\Shared\Transfer\HeidelpayPaymentTransfer
26
     */
27
    public function savePaymentHeidelpayEntity(HeidelpayPaymentTransfer $heidelpayPaymentTransfer): HeidelpayPaymentTransfer
28
    {
29
        $paymentHeidelpayEntity = $this->getPaymentHeidelpayQuery()
30
            ->filterByFkSalesOrder($heidelpayPaymentTransfer->getFkSalesOrder())
31
            ->findOneOrCreate();
32
33
        $paymentHeidelpayEntity->fromArray(
34
            $heidelpayPaymentTransfer->modifiedToArray()
35
        );
36
        $paymentHeidelpayEntity->save();
37
38
        return $this->getMapper()
39
            ->mapEntityToHeidelpayPaymentTransfer(
40
                $paymentHeidelpayEntity,
41
                $heidelpayPaymentTransfer
42
            );
43
    }
44
45
    /**
46
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $heidelpayNotificationTransfer
47
     *
48
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
49
     */
50
    public function savePaymentHeidelpayNotificationEntity(
51
        HeidelpayNotificationTransfer $heidelpayNotificationTransfer
52
    ): HeidelpayNotificationTransfer {
53
        $paymentHeidelpayNotificationEntity = $this->getPaymentHeidelpayNotificationQuery()
54
            ->filterByUniqueId($heidelpayNotificationTransfer->getUniqueId())
55
            ->findOneOrCreate();
56
57
        $paymentHeidelpayNotificationEntity->fromArray(
58
            $heidelpayNotificationTransfer->modifiedToArray()
59
        );
60
        $paymentHeidelpayNotificationEntity->save();
61
62
        return $this->getMapper()
63
            ->mapEntityToHeidelpayNotificationTransfer(
64
                $paymentHeidelpayNotificationEntity,
65
                $heidelpayNotificationTransfer
66
            );
67
    }
68
69
    /**
70
     * @return \SprykerEco\Zed\Heidelpay\Persistence\Propel\Mapper\HeidelpayPersistenceMapper
71
     */
72
    protected function getMapper(): HeidelpayPersistenceMapper
73
    {
74
        return $this->getFactory()->createHeidelpayPersistenceMapper();
75
    }
76
77
    /**
78
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayQuery
79
     */
80
    protected function getPaymentHeidelpayQuery(): SpyPaymentHeidelpayQuery
81
    {
82
        return $this->getFactory()->createPaymentHeidelpayQuery();
83
    }
84
85
    /**
86
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayNotificationQuery
87
     */
88
    protected function getPaymentHeidelpayNotificationQuery(): SpyPaymentHeidelpayNotificationQuery
89
    {
90
        return $this->getFactory()->createPaymentHeidelpayNotificationQuery();
91
    }
92
}
93