Completed
Push — master ( e35889...138bca )
by Dmitry
11:39
created

CertificatePricePresenter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hipanel\modules\finance\grid\presenters\price;
4
5
use hipanel\modules\finance\models\Price;
6
use Money\Formatter\DecimalMoneyFormatter;
7
use Money\Formatter\IntlMoneyFormatter;
8
use Money\MoneyFormatter;
9
use Yii;
10
use yii\base\InvalidConfigException;
11
use yii\helpers\Html;
12
13
/**
14
 * Class CertificatePricePresenter
15
 *
16
 * @author Dmytro Naumenko <[email protected]>
17
 */
18
class CertificatePricePresenter extends PricePresenter
19
{
20
    /**
21
     * @var MoneyFormatter
22
     */
23
    private $moneyFormatter;
24
25
    public function __construct(MoneyFormatter $moneyFormatter)
26
    {
27
        $this->moneyFormatter = $moneyFormatter;
28
        parent::__construct();
29
    }
30
31
    /**
32
     * @param \hipanel\modules\finance\models\CertificatePrice $price
33
     * @return string
34
     */
35
    public function renderPrice(Price $price): string
36
    {
37
        $result = [];
38
        foreach ($price->sums as $period => $amount) {
0 ignored issues
show
Documentation introduced by
The property sums does not exist on object<hipanel\modules\finance\models\Price>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
            $result[] = $this->moneyFormatter->format($amount);
40
        }
41
42
43
        return implode('&nbsp;/&nbsp;', $result);
44
    }
45
}
46