Failed Conditions
Push — experimental/3.1 ( 0c67c0...62371a )
by chihiro
51:52
created

ShipmentItemCollection::getDeliveryFees()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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\ShipmentItem;
7
8
class ShipmentItemCollection extends \ArrayIterator
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
9
{
10
    public function __construct($ShipmentItems, $flags = 0)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
11
    {
12
        // $ShipmentItems が Collection だったら toArray(); する
13
        parent::__construct($ShipmentItems, $flags);
14
    }
15
16
    // 明細種別ごとに返すメソッド作る
17
    public function getProductClasses()
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
18
    {
19
        return $this->subCollection(OrderItemType::PRODUCT);
20
    }
21
22
    public function getDeliveryFees()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
23
    {
24
        return $this->subCollection(OrderItemType::DELIVERY_FEE);
25
    }
26
27
    /**
28
     * 指定した受注明細区分だけの明細を取得.
29
     * @param int $orderItemTypeId 受注明細区分ID
30
     * @return ShipmentItemCollection
31
     */
32
    private function subCollection($orderItemTypeId)
33
    {
34
        return new self(array_filter($this->getArrayCopy(), function($ShipmentItem) use ($orderItemTypeId) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
35
            /* @var ShipmentItem $ShipmentItem */
36
            return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $orderItemTypeId;
37
        }));
38
    }
39
40
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$productName" missing
Loading history...
41
     * 同名の明細が存在するかどうか.
42
     *
43
     * TODO 暫定対応. 本来は明細種別でチェックする.
44
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
45
    public function hasProductByName($productName)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
46
    {
47
        $ShipmentItems = array_filter($this->getArrayCopy(),
48
                                     function ($ShipmentItem) use ($productName) {
49
                                         /* @var ShipmentItem $ShipmentItem */
50
                                         return $ShipmentItem->getProductName() == $productName;
51
                                     });
52
        return !empty($ShipmentItems);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
53
    }
54
    // map, filter, reduce も実装したい
55
56
    /**
57
     * 指定した受注明細区分の明細が存在するかどうか
58
     * @param OrderItemType $OrderItemType 受注区分
59
     * @return boolean
60
     */
61
    public function hasItemByOrderItemType($OrderItemType)
62
    {
63
        $filteredItems = array_filter($this->getArrayCopy(), function($ShipmentItem) use ($OrderItemType) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
64
            /* @var ShipmentItem $ShipmentItem */
65
            return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $OrderItemType->getId();
66
        });
67
        return !empty($filteredItems);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
68
    }
69
}
70