Passed
Pull Request — dev (#4)
by Mykyta
11:52 queued 07:39
created

IsAuthorizationCompletedPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCustomerCompletedAuthorization() 8 8 2
A check() 3 3 1
A isTransactionSuccessful() 3 3 1
A getExternalTransactionLogEntry() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Heidelpay\Communication\Plugin\Checkout\Oms\Condition;
9
10
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Heidelpay\Persis...HeidelpayTransactionLog 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;
1 ignored issue
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\Heidelpay\HeidelpayConfig;
15
16
/**
17
 * @method \SprykerEco\Zed\Heidelpay\Business\HeidelpayFacade getFacade()
18
 * @method \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayQueryContainer getQueryContainer()
19
 * @method \SprykerEco\Zed\Heidelpay\Communication\HeidelpayCommunicationFactory getFactory()
20
 */
21 View Code Duplication
class IsAuthorizationCompletedPlugin extends AbstractPlugin implements ConditionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * @api
25
     *
26
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
27
     *
28
     * @return bool
29
     */
30
    public function check(SpySalesOrderItem $orderItem)
31
    {
32
        return $this->hasCustomerCompletedAuthorization($orderItem->getFkSalesOrder());
33
    }
34
35
    /**
36
     * @param int $idSalesOrder
37
     *
38
     * @return bool
39
     */
40
    protected function hasCustomerCompletedAuthorization($idSalesOrder)
41
    {
42
        $externalTransactionLog = $this->getExternalTransactionLogEntry($idSalesOrder);
43
        if ($externalTransactionLog === null) {
44
            return false;
45
        }
46
47
        return $this->isTransactionSuccessful($externalTransactionLog);
48
    }
49
50
    /**
51
     * @param int $idSalesOrder
52
     *
53
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog|null
54
     */
55
    protected function getExternalTransactionLogEntry($idSalesOrder)
56
    {
57
        $transactionLogQuery = $this->getQueryContainer()->queryExternalResponseTransactionLog($idSalesOrder);
58
        return $transactionLogQuery->findOne();
59
    }
60
61
    /**
62
     * @param \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog $externalTransactionLog
63
     *
64
     * @return bool
65
     */
66
    protected function isTransactionSuccessful(SpyPaymentHeidelpayTransactionLog $externalTransactionLog)
67
    {
68
        return $externalTransactionLog->getResponseCode() === HeidelpayConfig::EXTERNAL_RESPONSE_TRANSACTION_STATUS_OK;
69
    }
70
}
71