isStoreOrderSuccessful()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
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\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
     * {@inheritdoc}
27
     * - Checks if StoreOrder API call was successful.
28
     *
29
     * @api
30
     *
31
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
32
     *
33
     * @return bool
34
     */
35
    public function check(SpySalesOrderItem $orderItem): bool
36
    {
37
        return $this->isStoreOrderSuccessful(
38
            $orderItem
39
                ->getOrder()
40
                ->getOrderReference()
41
        );
42
    }
43
44
    /**
45
     * @param string $orderReference
46
     *
47
     * @return bool
48
     */
49
    protected function isStoreOrderSuccessful(string $orderReference): bool
50
    {
51
        $storeOrderApiCallLogTransfer = $this->getApiCallLogEntry($orderReference);
52
53
        if ($storeOrderApiCallLogTransfer === null) {
54
            return false;
55
        }
56
57
        return $this->isTransactionSuccessful($storeOrderApiCallLogTransfer);
58
    }
59
60
    /**
61
     * @param string $orderReference
62
     *
63
     * @return \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer|null
64
     */
65
    protected function getApiCallLogEntry(string $orderReference): ?ArvatoRssApiCallLogTransfer
66
    {
67
        return $this->getRepository()
68
            ->findApiLogByOrderReferenceAndType(
69
                $orderReference,
70
                ArvatoRssApiConfig::TRANSACTION_TYPE_STORE_ORDER
71
            );
72
    }
73
74
    /**
75
     * @param \Generated\Shared\Transfer\ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer
76
     *
77
     * @return bool
78
     */
79
    protected function isTransactionSuccessful(ArvatoRssApiCallLogTransfer $arvatoRssApiCallLogTransfer)
80
    {
81
        return $arvatoRssApiCallLogTransfer->getResultCode() == ArvatoRssApiConfig::RESULT_CODE_SUCCESS;
82
    }
83
}
84