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

TemplatePricePresenter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B renderPrice() 0 23 4
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