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

CompareContext::getStrategies()   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\CartComparator;
4
5
class CompareContext
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
6
{
7
    /** @var \Doctrine\Common\Collections\ArrayCollection */
8
    protected $compareStrategies;
9
10
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
introduced by
Missing function doc comment
Loading history...
introduced by
No scope modifier specified for function "__construct"
Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
11
    {
12
        $this->compareStrategies = new \Doctrine\Common\Collections\ArrayCollection();
13
    }
14
15
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$CartItem1" missing
Loading history...
introduced by
Doc comment for parameter "$CartItem2" missing
Loading history...
16
     * @param $CartItem1
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
17
     * @param $CartItem2
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
18
     * @return bool
19
     */
20
    public function compare($CartItem1, $CartItem2)
21
    {
22
        $result = !$this->compareStrategies->isEmpty();
23
24
        /** @var \Eccube\Service\CartComparator\Strategy\CartComparatorStrategyInterface $strategy */
25
        foreach ($this->compareStrategies as $strategy) {
26
            $result = $result && $strategy->compare($CartItem1, $CartItem2);
27
        }
28
29
        return $result;
30
    }
31
32
    /**
33
     * @param Strategy\CartComparatorStrategyInterface $strategy
34
     * @return $this
35
     */
36
    public function addStrategy(\Eccube\Service\CartComparator\Strategy\CartComparatorStrategyInterface $strategy)
37
    {
38
        $this->compareStrategies->add($strategy);
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return \Doctrine\Common\Collections\ArrayCollection
45
     */
46
    public function getStrategies()
47
    {
48
        return $this->compareStrategies;
49
    }
50
}
51