Completed
Push — master ( 4aeceb...c161f7 )
by Dmitry
04:53
created

TemplatePricePresenter::renderPrice()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 13
nc 6
nop 1
1
<?php
2
3
namespace hipanel\modules\finance\grid\presenters\price;
4
5
use Yii;
6
use yii\base\InvalidConfigException;
7
use yii\helpers\Html;
8
9
/**
10
 * Class TemplatePricePresenter
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class TemplatePricePresenter extends PricePresenter
15
{
16
    /**
17
     * @param \hipanel\modules\finance\models\TemplatePrice $price
18
     * @return string
19
     */
20
    public function renderPrice($price): string
21
    {
22
        $formatter = Yii::$app->formatter;
23
24
        $unit = '';
25
        if ($price->getUnitLabel()) {
26
            $unit = ' ' . Yii::t('hipanel:finance', 'per {unit}', ['unit' => $price->getUnitLabel()]);
27
        }
28
29
        $result = [
30
            Html::tag('strong', $formatter->asCurrency($price->price, $price->currency) . $unit)
31
        ];
32
        foreach ($price->subprices as $currencyCode => $amount) {
33
            try {
34
                $result[] = $formatter->asCurrency($amount, $currencyCode);
35
            } catch (InvalidConfigException $e) {
36
                $result[] = $amount . ' ' . $currencyCode;
37
            }
38
        }
39
40
41
        return implode('&nbsp;&mdash;&nbsp;', $result);
42
    }
43
}
44