Failed Conditions
Pull Request — experimental/3.1 (#2526)
by Kentaro
40:11 queued 13:18
created

OrderItemCollection   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 83
Duplicated Lines 20.48 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 21.88%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 17
loc 83
ccs 7
cts 32
cp 0.2188
rs 10
wmc 11
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A reduce() 0 4 1
A getProductClasses() 0 7 1
A getDeliveryFees() 0 7 1
A getCharges() 0 7 1
A getDiscounts() 0 7 1
A hasProductByName() 9 9 1
A hasItemByOrderItemType() 8 8 2
A getType() 0 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
namespace Eccube\Service\Calculator;
4
5
use Eccube\Entity\Master\OrderItemType;
6
use Eccube\Entity\ItemInterface;
7
use Eccube\Entity\Order;
8
9
class OrderItemCollection extends \Doctrine\Common\Collections\ArrayCollection
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
10
{
11
    protected $type;
12
13 124
    public function __construct($OrderItems, $type = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
14
    {
15
        // $OrderItems が Collection だったら toArray(); する
16 124
        $this->type = is_null($type) ? Order::class : $type;
17 124
        parent::__construct($OrderItems);
18
    }
19
20
    public function reduce(\Closure $func, $initial = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
21
    {
22
        return array_reduce($this->toArray(), $func, $initial);
23
    }
24
25
    // 明細種別ごとに返すメソッド作る
26 124
    public function getProductClasses()
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
27
    {
28 124
        return $this->filter(
29
            function(ItemInterface $OrderItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
30 124
                return $OrderItem->isProduct();
31 124
            });
32
    }
33
34
    public function getDeliveryFees()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
35
    {
36
        return $this->filter(
37
            function(ItemInterface $OrderItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
38
                return $OrderItem->isDeliveryFee();
39
            });
40
    }
41
42
    public function getCharges()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
43
    {
44
        return $this->filter(
45
            function(ItemInterface $OrderItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
46
                return $OrderItem->isCharge();
47
            });
48
    }
49
50
    public function getDiscounts()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
51
    {
52
        return $this->filter(
53
            function(ItemInterface $OrderItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
54
                return $OrderItem->isDiscount();
55
            });
56
    }
57
58
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$productName" missing
Loading history...
59
     * 同名の明細が存在するかどうか.
60
     *
61
     * TODO 暫定対応. 本来は明細種別でチェックする.
62
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
63 View Code Duplication
    public function hasProductByName($productName)
0 ignored issues
show
Duplication introduced by
This method 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...
64
    {
65
        $OrderItems = $this->filter(
66
            function (ItemInterface $OrderItem) use ($productName) {
67
                /* @var OrderItem $OrderItem */
68
                return $OrderItem->getProductName() == $productName;
69
            });
70
        return !$OrderItems->isEmpty();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
71
    }
72
73
    /**
74
     * 指定した受注明細区分の明細が存在するかどうか
75
     * @param OrderItemType $OrderItemType 受注区分
76
     * @return boolean
77
     */
78 View Code Duplication
    public function hasItemByOrderItemType($OrderItemType)
0 ignored issues
show
Duplication introduced by
This method 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...
79
    {
80
        $filteredItems = $this->filter(function(ItemInterface $OrderItem) use ($OrderItemType) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
81
            /* @var OrderItem $OrderItem */
82
            return $OrderItem->getOrderItemType() && $OrderItem->getOrderItemType()->getId() == $OrderItemType->getId();
83
        });
84
        return !$filteredItems->isEmpty();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
85
    }
86
87
    public function getType()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
88
    {
89
        return $this->type;
90
    }
91
}
92