| @@ 95-108 (lines=14) @@ | ||
| 92 | * {@inheritdoc} |
|
| 93 | * Default sum calculation method: sum = price * usage. |
|
| 94 | */ |
|
| 95 | public function calculateSum(QuantityInterface $quantity) |
|
| 96 | { |
|
| 97 | $usage = $this->calculateUsage($quantity); |
|
| 98 | if ($usage === null) { |
|
| 99 | return null; |
|
| 100 | } |
|
| 101 | ||
| 102 | $price = $this->calculatePrice($quantity); |
|
| 103 | if ($price === null) { |
|
| 104 | return null; |
|
| 105 | } |
|
| 106 | ||
| 107 | return $price->multiply($usage->getQuantity()); |
|
| 108 | } |
|
| 109 | ||
| 110 | public static function create(array $data) |
|
| 111 | { |
|
| @@ 95-108 (lines=14) @@ | ||
| 92 | /** |
|
| 93 | * {@inheritdoc} |
|
| 94 | */ |
|
| 95 | public function calculatePrice(QuantityInterface $quantity) |
|
| 96 | { |
|
| 97 | $sum = $this->calculateSum($quantity); |
|
| 98 | if ($sum === null) { |
|
| 99 | return null; |
|
| 100 | } |
|
| 101 | ||
| 102 | $usage = $this->calculateUsage($quantity); |
|
| 103 | if ($usage === null) { |
|
| 104 | return null; |
|
| 105 | } |
|
| 106 | ||
| 107 | return $sum->divide($usage->getQuantity()); |
|
| 108 | } |
|
| 109 | ||
| 110 | /** |
|
| 111 | * {@inheritdoc} |
|