Completed
Push — master ( f7bdb9...8d2b6e )
by Andrii
10:42
created

models/decorators/server/HddResourceDecorator.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\models\decorators\server;
12
13
use Yii;
14
15 View Code Duplication
class HddResourceDecorator extends AbstractServerResourceDecorator
16
{
17
    public function displayTitle()
18
    {
19
        return Yii::t('hipanel:server:order', 'SSD');
20
    }
21
22
    public function displayPrepaidAmount()
23
    {
24
        return Yii::t('yii', '{nFormatted} GB', ['nFormatted' => $this->getPrepaidQuantity()]); // Gb
25
    }
26
27
    public function getOverusePrice()
28
    {
29
        return 0.2; // TODO: move to config
30
    }
31
32
    public function getPrepaidQuantity()
33
    {
34
        $part = $this->resource->part;
0 ignored issues
show
The property part does not exist on object<hipanel\modules\f...\models\ServerResource>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
35
        preg_match('/((\d{1,5}) GB)$/i', $part->partno, $matches);
36
37
        return (int) $matches[2];
38
    }
39
40
    public function displayUnit()
41
    {
42
        return Yii::t('hipanel', 'GB');
43
    }
44
}
45