BackupGridRow   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 52
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 2
A getRealObjectId() 0 10 3
A generateBackupingLink() 0 9 1
A generateBackupingEnableLink() 0 14 1
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\widgets\backup;
12
13
use hipanel\modules\hosting\models\Hdomain;
14
use Yii;
15
use yii\base\Widget;
16
use yii\helpers\Html;
17
18
class BackupGridRow extends Widget
19
{
20
    /**
21
     * @var \hipanel\base\Model
22
     */
23
    public $model;
24
25
    public function run()
26
    {
27
        if ($this->model->backuping_exists) {
28
            return $this->generateBackupingLink();
29
        } else {
30
            return $this->generateBackupingEnableLink();
31
        }
32
    }
33
34
    protected function getRealObjectId()
35
    {
36
        $id = $this->model->id;
37
38
        if ($this->model instanceof Hdomain) {
39
            $id = $this->model->isAlias() ? $this->model->vhost_id : $this->model->id;
0 ignored issues
show
Documentation introduced by
The property vhost_id does not exist on object<hipanel\modules\hosting\models\Hdomain>. 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...
Documentation introduced by
The property id does not exist on object<hipanel\modules\hosting\models\Hdomain>. 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...
40
        }
41
42
        return $id;
43
    }
44
45
    protected function generateBackupingLink()
46
    {
47
        $id = $this->getRealObjectId();
48
49
        $linkToBackup = Html::a('<i class="fa fa-archive" aria-hidden="true"></i>&nbsp;&nbsp;' .
50
            Yii::t('hipanel:hosting', 'Backup settings'), ['@backuping/view', 'id' => $id]);
51
52
        return $linkToBackup;
53
    }
54
55
    protected function generateBackupingEnableLink()
56
    {
57
        $text = '<i class="fa fa-check" aria-hidden="true"></i>&nbsp;&nbsp;';
58
        $text .= Yii::t('hipanel:hosting', 'Enable backuping');
59
60
        $linkToBackup = Html::a($text, [sprintf('@%s/enable-backuping', $this->model->tableName())], [
61
            'data-method' => 'POST',
62
            'data-params' => [
63
                sprintf('%s[id]', ucfirst($this->model->tableName())) => $this->getRealObjectId(),
64
            ],
65
        ]);
66
67
        return $linkToBackup;
68
    }
69
}
70