Completed
Push — master ( c2bc12...ef5bc2 )
by Dmitry
04:55
created

presenters/price/CertificatePricePresenter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\grid\presenters\price;
12
13
use hipanel\modules\finance\models\Price;
14
use Money\MoneyFormatter;
15
16
/**
17
 * Class CertificatePricePresenter.
18
 *
19
 * @author Dmytro Naumenko <[email protected]>
20
 */
21
class CertificatePricePresenter extends PricePresenter
22
{
23
    /**
24
     * @var MoneyFormatter
25
     */
26
    private $moneyFormatter;
27
28
    public function __construct(MoneyFormatter $moneyFormatter)
29
    {
30
        $this->moneyFormatter = $moneyFormatter;
31
        parent::__construct();
32
    }
33
34
    /**
35
     * @param \hipanel\modules\finance\models\CertificatePrice $price
36
     * @return string
37
     */
38
    public function renderPrice(Price $price): string
39
    {
40
        $result = [];
41
        foreach ($price->sums as $period => $amount) {
0 ignored issues
show
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...
42
            $result[] = $this->moneyFormatter->format($amount);
43
        }
44
45
        return implode('&nbsp;/&nbsp;', $result);
46
    }
47
}
48