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