Backup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 20.93 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 9
loc 43
ccs 0
cts 34
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 18 1
A attributeLabels() 0 7 1
A getObj() 9 9 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
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\models;
12
13
use hipanel\models\Obj;
14
use Yii;
15
16
class Backup extends \hipanel\base\Model
17
{
18
    use \hipanel\base\ModelTrait;
19
20
    /** {@inheritdoc} */
21
    public function rules()
22
    {
23
        return [
24
            [['id', 'service_id', 'object_id', 'server_id', 'account_id', 'client_id', 'state_id'], 'integer'],
25
            [['time'], 'date'],
26
            [['size'], 'integer'],
27
            [
28
                [
29
                    'title', 'size_gb', 'time', 'service',
30
                    'client', 'method', 'server', 'account',
31
                    'client', 'object', 'name', 'state', 'type',
32
                ],
33
                'safe',
34
            ],
35
            [['method_label', 'type_label', 'state_label'], 'safe'],
36
            [['id'], 'integer', 'on' => ['delete']],
37
        ];
38
    }
39
40
    /** {@inheritdoc} */
41
    public function attributeLabels()
42
    {
43
        return $this->mergeAttributeLabels([
44
            'method'    => Yii::t('hipanel:hosting', 'Method'),
45
            'size'      => Yii::t('hipanel:hosting', 'Size'),
46
        ]);
47
    }
48
49 View Code Duplication
    public function getObj()
0 ignored issues
show
Duplication introduced by
This method 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...
50
    {
51
        return Yii::createObject([
52
            'class' => Obj::class,
53
            'id' => $this->object_id,
0 ignored issues
show
Documentation introduced by
The property object_id does not exist on object<hipanel\modules\hosting\models\Backup>. 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...
54
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hipanel\modules\hosting\models\Backup>. 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...
55
            'class_name' => $this->object,
0 ignored issues
show
Documentation introduced by
The property object does not exist on object<hipanel\modules\hosting\models\Backup>. 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...
56
        ]);
57
    }
58
}
59