Completed
Push — master ( ef2c0c...0622f1 )
by Dmitry
17:35
created

HddResourceDecorator::displayTitle()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\models\decorators\server;
4
5
use Yii;
6
7
class HddResourceDecorator extends AbstractServerResourceDecorator
8
{
9
    public function displayTitle()
10
    {
11
        return Yii::t('hipanel/server/order', 'SSD');
12
    }
13
14
    public function displayPrepaidAmount()
15
    {
16
        return Yii::t('yii', '{nFormatted} GB', ['nFormatted' => $this->getPrepaidQuantity()]); // Gb
17
    }
18
19
    public function getOverusePrice()
20
    {
21
        return 0.2; // TODO: move to config
22
    }
23
24
    public function getPrepaidQuantity()
25
    {
26
        $part = $this->resource->part;
0 ignored issues
show
Documentation introduced by
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...
27
        preg_match('/((\d{1,5}) GB)$/i', $part->partno, $matches);
28
        return (int) $matches[2];
29
    }
30
31
    public function displayUnit()
32
    {
33
        return Yii::t('hipanel', 'GB');
34
    }
35
}
36