Failed Conditions
Pull Request — experimental/3.1 (#2273)
by
unknown
41:30
created

CartCompareService::getContext()   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;
4
5
use Eccube\Entity\Cart;
6
7
class CartCompareService
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
8
{
9
    /** @var Cart  */
10
    protected $Cart;
11
12
    /** @var \Eccube\Service\CartComparator\CompareContext */
13
    protected $context;
14
15
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Cart" missing
Loading history...
16
     * @param $Cart
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
17
     */
18
    public function __construct($Cart)
19
    {
20
        $this->Cart = $Cart;
21
    }
22
23
    /**
24
     * @param \Eccube\Service\CartComparator\CompareContext $context
25
     * @return $this
26
     */
27
    public function setContext($context)
28
    {
29
        $this->context = $context;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @return \Eccube\Service\CartComparator\CompareContext
36
     */
37
    public function getContext()
38
    {
39
        return $this->context;
40
    }
41
42
    /**
43
     * CompareContext::compare()のエイリアス
44
     *
45
     * @param \Eccube\Entity\CartItem $CartItem1
46
     * @param \Eccube\Entity\CartItem $CartItem2
47
     * @return bool
48
     */
49
    public function compare($CartItem1, $CartItem2)
50
    {
51
        return $this->context->compare($CartItem1, $CartItem2);
52
    }
53
54
    /**
55
     * カート内商品と比較し、既に存在する商品を取得する
56
     *
57
     * @param \Eccube\Entity\CartItem $CartItem
58
     * @return \Eccube\Entity\CartItem|null 存在しない場合はnull
59
     */
60
    public function getExistsCartItem($CartItem)
61
    {
62
        $result = null;
63
64
        foreach ($this->Cart->getCartItems() as $CompareCartItem) {
65
            if ($this->context->compare($CartItem, $CompareCartItem)) {
66
                $result = $CompareCartItem;
67
                break;
68
            }
69
        }
70
71
        return $result;
72
    }
73
}
74