MultiplePrice::showPrice()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
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
The property prices does not exist on hipanel\modules\server\models\Consumption. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
            $prices[] = Yii::$app->formatter->asCurrency($amount, $currency);
42
        }
43
44
        return implode($this->delimiter, $prices);
45
    }
46
}
47