Completed
Push — master ( 958dbc...2d3a59 )
by Dmitry
05:33
created

ModelGroupPricePresenter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderPrice() 0 17 3
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 ModelGroupPricePresenter
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class ModelGroupPricePresenter extends PricePresenter
15
{
16
    /**
17
     * @param \hipanel\modules\finance\models\ModelGroupPrice $price
18
     * @return string
19
     */
20
    public function renderPrice($price): string
21
    {
22
        $formatter = Yii::$app->formatter;
23
24
        $result = [
25
            Html::tag('strong', $formatter->asCurrency($price->price, $price->currency))
26
        ];
27
        foreach ($price->subprices as $currencyCode => $amount) {
28
            try {
29
                $result[] = $formatter->asCurrency($amount, $currencyCode);
30
            } catch (InvalidConfigException $e) {
31
                $result[] = $amount . ' ' . $currencyCode;
32
            }
33
        }
34
35
        return implode('&nbsp;&mdash;&nbsp;', $result);
36
    }
37
}
38