Passed
Pull Request — master (#19)
by Volodymyr
05:11
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
 * MIT License
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
 */
22
class IsStoreOrderSuccessfulPlugin extends AbstractPlugin implements ConditionInterface
23
{
24
    /**
25
     * @api
26
     *
27
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
28
     *
29
     * @return bool
30
     */
31
    public function check(SpySalesOrderItem $orderItem)
32
    {
33
        return $this->isStoreOrderSuccessful(
34
            $orderItem
35
                ->getOrder()
36
                ->getOrderReference()
37
        );
38
    }
39
40
    /**
41
     * @param string $orderReference
42
     *
43
     * @return bool
44
     */
45
    protected function isStoreOrderSuccessful($orderReference)
46
    {
47
        $storeOrderApiCallLogTransfer = $this->getApiCallLogEntry($orderReference);
48
49
        if ($storeOrderApiCallLogTransfer === null) {
50
            return false;
51
        }
52
53
        return $this->isTransactionSuccessful($storeOrderApiCallLogTransfer);
54
    }
55
56
    /**
57
     * @param string $orderReference
58
     *
59
     * @return \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer
60
     */
61
    protected function getApiCallLogEntry(string $orderReference): ArvatoRssApiCallLogTransfer
62
    {
63
        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...
64
            ->findApiLogByOrderReferenceAndType(
65
                $orderReference,
66
                ArvatoRssApiConfig::TRANSACTION_TYPE_STORE_ORDER
67
            );
68
    }
69
70
    /**
71
     * @param \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer
72
     *
73
     * @return bool
74
     */
75
    protected function isTransactionSuccessful(ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer)
76
    {
77
        return $arvatoRssApiCallLogTransfer->getResultCode() == ArvatoRssApiConfig::RESULT_CODE_SUCCESS;
78
    }
79
}
80