Completed
Push — master ( 83485f...ef2c0c )
by Dmitry
04:50
created

HddResourceDecorator::displayValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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