Completed
Push — master ( 5e0ad4...117a3a )
by Dmitry
10:56
created

PricePresenter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\grid\presenters\price;
4
5
use hipanel\modules\finance\models\Price;
6
use Yii;
7
use yii\bootstrap\Html;
8
9
/**
10
 * Class PricePresenter contains methods that present price properties.
11
 * You can override this class to add custom presentations support.
12
 *
13
 * @author Dmytro Naumenko <[email protected]>
14
 */
15
class PricePresenter
16
{
17
    /**
18
     * @var \yii\i18n\Formatter
19
     */
20
    private $formatter;
21
22
    public function __construct()
23
    {
24
        $this->formatter = Yii::$app->formatter;
25
    }
26
27
    /**
28
     * @param Price $price
29
     * @return string
30
     * @throws \yii\base\InvalidConfigException
31
     */
32
    public function renderPrice($price): string
33
    {
34
        $unit = '';
35 View Code Duplication
        if ($price->getUnitLabel()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            $unit = ' ' . Yii::t('hipanel:finance', 'per {unit}', ['unit' => $price->getUnitLabel()]);
37
        }
38
39
        if ($price->isOveruse()) {
40
            $prepaid = ', ' . Yii::t('hipanel:finance', 'prepaid {amount,number}', ['amount' => $price->quantity]);
41
        } else {
42
            $prepaid = ' ' . Yii::t('hipanel:finance', 'monthly');
43
        }
44
45
        return Html::tag('strong', $this->formatter->asCurrency($price->price, $price->currency)) . $unit . $prepaid;
46
    }
47
}
48