Completed
Push — master ( 287fd3...85b31d )
by Dmitry
03:56
created

BackupGridRow::generateBackupingEnableLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Hosting Plugin for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-hosting
7
 * @package   hipanel-module-hosting
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\hosting\widgets\backup;
13
14
use hipanel\modules\hosting\models\Backuping;
15
use hipanel\modules\hosting\models\Hdomain;
16
use Yii;
17
use yii\base\Widget;
18
use yii\helpers\Html;
19
20
class BackupGridRow extends Widget
21
{
22
    /**
23
     * @var \hipanel\base\Model
24
     */
25
    public $model;
26
27
    public function run()
28
    {
29
        if ($this->model->backuping_exists) {
30
            return $this->generateBackupingLink();
31
        } else {
32
            return $this->generateBackupingEnableLink();
33
        }
34
    }
35
36
    protected function getRealObjectId()
37
    {
38
        $id = $this->model->id;
39
40
        if ($this->model instanceof Hdomain) {
41
            $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...
42
        }
43
44
        return $id;
45
    }
46
47
    protected function generateBackupingLink()
48
    {
49
        $id = $this->getRealObjectId();
50
51
        $linkToBackup = Html::a('<i class="fa fa-archive" aria-hidden="true"></i>&nbsp;&nbsp;' .
52
            Yii::t('hipanel/hosting', 'Backup settings'), ['@backuping/view', 'id' => $id]);
53
54
        return $linkToBackup;
55
    }
56
57
    protected function generateBackupingEnableLink()
58
    {
59
        $text = '<i class="fa fa-check" aria-hidden="true"></i>&nbsp;&nbsp;';
60
        $text .= Yii::t('hipanel/hosting', 'Enable backuping');
61
62
        $linkToBackup = Html::a($text, ['@hdomain/enable-backuping'], [
63
            'data-method' => 'POST',
64
            'data-params' => [
65
                'Hdomain[id]' => $this->getRealObjectId()
66
            ]
67
        ]);
68
69
        return $linkToBackup;
70
    }
71
}
72