HddResourceDecorator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 35
loc 35
rs 10
c 0
b 0
f 0
ccs 0
cts 22
cp 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A displayTitle() 4 4 1
A displayPrepaidAmount() 4 4 1
A getOverusePrice() 4 4 1
A getPrepaidQuantity() 7 7 1
A displayUnit() 4 4 1
A toUnit() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
0 ignored issues
show
Duplication introduced by SilverFire - Dmitry Naumenko
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...
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;
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
    public function toUnit(): string
46
    {
47
        return 'gb';
48
    }
49
}
50