Completed
Push — master ( f57b87...cd81f9 )
by Andrii
27:21 queued 12:20
created

MultiplePrice::showPrice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace hipanel\modules\server\helpers\consumptionPriceFormatter;
4
5
6
use hipanel\modules\server\models\Consumption;
7
use Yii;
8
use yii\helpers\Html;
9
10
class MultiplePrice implements PriceFormatterStrategy
11
{
12
    /**
13
     * @var string
14
     */
15
    private $delimiter;
16
17
    /**
18
     * @param string $delimiter
19
     */
20
    public function __construct(?string $delimiter = null)
21
    {
22
        $this->delimiter = $delimiter ?? Html::tag('br');
23
    }
24
25
    /**
26
     * @param Consumption $consumption
27
     * @return string
28
     * @throws \yii\base\InvalidConfigException
29
     */
30
    public function showPrice(Consumption $consumption): string
31
    {
32
        $prices = [];
33
        foreach ($consumption->prices as $currency => $amount) {
0 ignored issues
show
Bug Best Practice introduced by Andrey Klochok
The property prices does not exist on hipanel\modules\server\models\Consumption. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            $prices[] = Yii::$app->formatter->asCurrency($amount, $currency);
35
        }
36
37
        return implode($this->delimiter, $prices);
38
    }
39
}
40