Passed
Push — feature/ECO-808-scrutinizer ( 956529...82fb0b )
by Andrey
05:28 queued 01:30
created

IpnAbstractTransferRequestHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 18 2
A getAffectedSalesOrderItems() 0 9 2
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn;
9
10
use Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay 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 Propel\Runtime\Collection\ObjectCollection;
12
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
13
use SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface;
14
use SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface;
15
use SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface;
16
17
abstract class IpnAbstractTransferRequestHandler implements IpnRequestHandlerInterface
18
{
19
20
    /**
21
     * @var \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsBridge $omsFacade
22
     */
23
    protected $omsFacade;
24
25
    /**
26
     * @var \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer
27
     */
28
    protected $amazonpayQueryContainer;
29
30
    /**
31
     * @var \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger
32
     */
33
    protected $ipnRequestLogger;
34
35
    /**
36
     * @param \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface $omsFacade
37
     * @param \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer
38
     * @param \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger
39
     */
40
    public function __construct(
41
        AmazonpayToOmsInterface $omsFacade,
42
        AmazonpayQueryContainerInterface $amazonpayQueryContainer,
43
        IpnRequestLoggerInterface $ipnRequestLogger
44
    ) {
45
        $this->omsFacade = $omsFacade;
0 ignored issues
show
Documentation Bug introduced by
$omsFacade is of type SprykerEco\Zed\Amazonpay...AmazonpayToOmsInterface, but the property $omsFacade was declared to be of type SprykerEco\Zed\Amazonpay...de\AmazonpayToOmsBridge. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
46
        $this->amazonpayQueryContainer = $amazonpayQueryContainer;
47
        $this->ipnRequestLogger = $ipnRequestLogger;
48
    }
49
50
    /**
51
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $amazonpayIpnRequestTransfer
52
     *
53
     * @return void
54
     */
55
    public function handle(AbstractTransfer $amazonpayIpnRequestTransfer)
56
    {
57
        $paymentEntity = $this->retrievePaymentEntity($amazonpayIpnRequestTransfer);
58
59
        if ($paymentEntity === null) {
60
            return;
61
        }
62
63
        $paymentEntity->setStatus($this->getOmsStatusName());
64
        $paymentEntity->save();
65
66
        $this->omsFacade->triggerEvent(
67
            $this->getOmsEventId(),
68
            $this->getAffectedSalesOrderItems($paymentEntity),
69
            []
70
        );
71
72
        $this->ipnRequestLogger->log($amazonpayIpnRequestTransfer, $paymentEntity);
73
    }
74
75
    /**
76
     * @param \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay $paymentEntity
77
     *
78
     * @return \Propel\Runtime\Collection\ObjectCollection|\Orm\Zed\Sales\Persistence\SpySalesOrderItem[]
79
     */
80
    protected function getAffectedSalesOrderItems(SpyPaymentAmazonpay $paymentEntity)
81
    {
82
        $items = new ObjectCollection();
83
84
        foreach ($paymentEntity->getSpyPaymentAmazonpaySalesOrderItems() as $amazonpaySalesOrderItem) {
85
            $items[] = $amazonpaySalesOrderItem->getSpySalesOrderItem();
86
        }
87
88
        return $items;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $items returns the type Propel\Runtime\Collection\ObjectCollection which is incompatible with the documented return type Orm\Zed\Sales\Persistenc...ection\ObjectCollection.
Loading history...
89
    }
90
91
    /**
92
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $amazonpayIpnPaymentAuthorizeRequestTransfer
93
     *
94
     * @return \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay
95
     */
96
    abstract protected function retrievePaymentEntity(
97
        AbstractTransfer $amazonpayIpnPaymentAuthorizeRequestTransfer
98
    );
99
100
    /**
101
     * @return string
102
     */
103
    abstract protected function getOmsEventId();
104
105
    /**
106
     * @return string
107
     */
108
    abstract protected function getOmsStatusName();
109
110
}
111