Failed Conditions
Pull Request — experimental/3.1 (#2374)
by Kentaro
29:44
created

ShipmentItemCollection::getCharges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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 ShipmentItemCollection extends \Doctrine\Common\Collections\ArrayCollection
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
10
{
11
    protected $type;
12
13
    public function __construct($ShipmentItems, $type = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
14
    {
15
        // $ShipmentItems が Collection だったら toArray(); する
16
        $this->type = is_null($type) ? Order::class : $type;
17
        parent::__construct($ShipmentItems);
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
    public function getProductClasses()
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
27
    {
28
        return $this->filter(
29
            function(ItemInterface $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
30
                return $ShipmentItem->isProduct();
31
            });
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 $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
38
                return $ShipmentItem->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 $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
46
                return $ShipmentItem->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 $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
54
                return $ShipmentItem->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
    public function hasProductByName($productName)
64
    {
65
        $ShipmentItems = $this->filter(
66
            function (ItemInterface $ShipmentItem) use ($productName) {
67
                /* @var ShipmentItem $ShipmentItem */
68
                return $ShipmentItem->getProductName() == $productName;
69
            });
70
        return !$ShipmentItems->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
    public function hasItemByOrderItemType($OrderItemType)
79
    {
80
        $filteredItems = $this->filter(function(ItemInterface $ShipmentItem) use ($OrderItemType) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
81
            /* @var ShipmentItem $ShipmentItem */
82
            return $ShipmentItem->getOrderItemType() && $ShipmentItem->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