1 | <?php |
||
21 | abstract class AbstractPrice implements PriceInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var integer |
||
25 | */ |
||
26 | protected $id; |
||
27 | |||
28 | /** |
||
29 | * @var Plan |
||
30 | */ |
||
31 | protected $plan; |
||
32 | |||
33 | /** |
||
34 | * @var Target |
||
35 | */ |
||
36 | protected $target; |
||
37 | |||
38 | /** |
||
39 | * @var Type |
||
40 | */ |
||
41 | protected $type; |
||
42 | |||
43 | 3 | public function __construct($id, TargetInterface $target, TypeInterface $type) |
|
44 | { |
||
45 | 3 | $this->id = $id; |
|
46 | 3 | $this->target = $target; |
|
|
|||
47 | 3 | $this->type = $type; |
|
48 | 3 | } |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 2 | public function getTarget() |
|
54 | { |
||
55 | 2 | return $this->target; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 2 | public function getType() |
|
62 | { |
||
63 | 2 | return $this->type; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | * Default sum calculation method: sum = price * usage. |
||
69 | */ |
||
70 | 1 | public function calculateSum(QuantityInterface $quantity) |
|
71 | { |
||
72 | 1 | $usage = $this->calculateUsage($quantity); |
|
73 | 1 | if ($usage === null) { |
|
74 | return null; |
||
75 | } |
||
76 | |||
77 | 1 | $price = $this->calculatePrice($quantity); |
|
78 | 1 | if ($price === null) { |
|
79 | return null; |
||
80 | } |
||
81 | |||
82 | 1 | return $price->multiply($usage->getQuantity()); |
|
83 | } |
||
84 | |||
85 | public static function create(array $data) |
||
86 | { |
||
87 | return new SinglePrice($data['id'], $data['target']); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | abstract public function calculateUsage(QuantityInterface $quantity); |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | abstract public function calculatePrice(QuantityInterface $action); |
||
99 | } |
||
100 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.