Passed
Pull Request — master (#19)
by Volodymyr
04:21
created

isTransactionSuccessful()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\ArvatoRss\Communication\Plugin\Oms\Condition;
9
10
use Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...toRssApiCallLogTransfer 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 Orm\Zed\Sales\Persistence\SpySalesOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItem 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 Spryker\Zed\Kernel\Communication\AbstractPlugin;
13
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface;
14
use SprykerEco\Shared\ArvatoRss\ArvatoRssApiConfig;
15
16
/**
17
 * @method \SprykerEco\Zed\ArvatoRss\Business\ArvatorssFacadeInterface getFacade()
18
 * @method \SprykerEco\Zed\ArvatoRss\Persistence\ArvatoRssQueryContainerInterface getQueryContainer()
19
 * @method \SprykerEco\Zed\ArvatoRss\Persistence\ArvatoRssRepositoryInterface getRepository()
20
 * @method \SprykerEco\Zed\ArvatoRss\Communication\ArvatoRssCommunicationFactory getFactory()
21
 * @method \SprykerEco\Zed\ArvatoRss\ArvatoRssConfig getConfig()
22
 */
23
class IsStoreOrderSuccessfulPlugin extends AbstractPlugin implements ConditionInterface
24
{
25
    /**
26
     * @api
27
     *
28
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
29
     *
30
     * @return bool
31
     */
32
    public function check(SpySalesOrderItem $orderItem)
33
    {
34
        return $this->isStoreOrderSuccessful(
35
            $orderItem
36
                ->getOrder()
37
                ->getOrderReference()
38
        );
39
    }
40
41
    /**
42
     * @param string $orderReference
43
     *
44
     * @return bool
45
     */
46
    protected function isStoreOrderSuccessful($orderReference)
47
    {
48
        $storeOrderApiCallLogTransfer = $this->getApiCallLogEntry($orderReference);
49
50
        if ($storeOrderApiCallLogTransfer->getIdPaymentArvatoRssApiCallLog() === null) {
51
            return false;
52
        }
53
54
        return $this->isTransactionSuccessful($storeOrderApiCallLogTransfer);
55
    }
56
57
    /**
58
     * @param string $orderReference
59
     *
60
     * @return \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer
61
     */
62
    protected function getApiCallLogEntry(string $orderReference): ArvatoRssApiCallLogTransfer
63
    {
64
        return $this->getRepository()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getReposit...CTION_TYPE_STORE_ORDER) could return the type null which is incompatible with the type-hinted return Generated\Shared\Transfe...toRssApiCallLogTransfer. Consider adding an additional type-check to rule them out.
Loading history...
65
            ->findApiLogByOrderReferenceAndType(
66
                $orderReference,
67
                ArvatoRssApiConfig::TRANSACTION_TYPE_STORE_ORDER
68
            );
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer
73
     *
74
     * @return bool
75
     */
76
    protected function isTransactionSuccessful(ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer)
77
    {
78
        return $arvatoRssApiCallLogTransfer->getResultCode() == ArvatoRssApiConfig::RESULT_CODE_SUCCESS;
79
    }
80
}
81