1 | <?php |
||
2 | /** |
||
3 | * Server module for HiPanel |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/hipanel-module-server |
||
6 | * @package hipanel-module-server |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hipanel\modules\server\helpers\consumptionPriceFormatter; |
||
12 | |||
13 | use hipanel\modules\server\models\Consumption; |
||
14 | use Yii; |
||
15 | use yii\helpers\Html; |
||
16 | |||
17 | class MultiplePrice implements PriceFormatterStrategy |
||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $delimiter; |
||
23 | |||
24 | /** |
||
25 | * @param string $delimiter |
||
26 | */ |
||
27 | public function __construct(?string $delimiter = null) |
||
28 | { |
||
29 | $this->delimiter = $delimiter ?? Html::tag('br'); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param Consumption $consumption |
||
34 | * @throws \yii\base\InvalidConfigException |
||
35 | * @return string |
||
36 | */ |
||
37 | public function showPrice(Consumption $consumption): string |
||
38 | { |
||
39 | $prices = []; |
||
40 | foreach ($consumption->prices as $currency => $amount) { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
41 | $prices[] = Yii::$app->formatter->asCurrency($amount, $currency); |
||
42 | } |
||
43 | |||
44 | return implode($this->delimiter, $prices); |
||
45 | } |
||
46 | } |
||
47 |