Passed
Pull Request — master (#4)
by Andrey
06:53 queued 03:48
created

AbstractByOrderItemConditionPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 38
loc 38
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaymentAmazonpayBySalesOrderItem() 9 9 2
A check() 9 9 2

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
 * 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\Communication\Plugin\Oms\Condition;
9
10
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...
11
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface;
12
13 View Code Duplication
abstract class AbstractByOrderItemConditionPlugin 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...
14
{
15
16
    /**
17
     * @return string
18
     */
19
    abstract protected function getConditionalStatus();
20
21
    /**
22
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
23
     *
24
     * @return bool
25
     */
26
    public function check(SpySalesOrderItem $orderItem)
27
    {
28
        $payment = $this->getPaymentAmazonpayBySalesOrderItem($orderItem);
29
30
        if ($payment === null) {
31
            return true;
32
        }
33
34
        return $payment->getStatus() === $this->getConditionalStatus();
35
    }
36
37
    /**
38
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
39
     *
40
     * @return \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay|null
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...
41
     */
42
    protected function getPaymentAmazonpayBySalesOrderItem(SpySalesOrderItem $orderItem)
43
    {
44
        $lastPayment = $orderItem->getSpyPaymentAmazonpaySalesOrderItems()->getLast();
45
46
        if (!$lastPayment) {
47
            return null;
48
        }
49
50
        return $lastPayment->getSpyPaymentAmazonpay();
51
    }
52
53
}
54