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

MultiplePrice   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A showPrice() 0 8 2
A __construct() 0 3 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
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