Completed
Push — master ( 6a485a...18c4f3 )
by Andrii
04:57
created

ObjLinkWidget::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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-2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets\obj;
12
13
use hipanel\models\Obj;
14
use Yii;
15
use yii\helpers\Html;
16
17
class ObjLinkWidget extends \yii\base\Widget
18
{
19
    /**
20
     * @var Obj
21
     */
22
    public $model;
23
24
    protected $_label;
25
26
    public function run()
27
    {
28
        return $this->renderLink();
29
    }
30
31
    protected function renderLink()
32
    {
33
        $alias = $this->model->getObjClass()->getAlias();
34
    
35
        return $this->getLabel() . '&nbsp;' .
36
            Html::a($this->model->name, ["@$alias/view", 'id' => $this->model->id], ['data-pjax' => 0]);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hipanel\models\Obj>. 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\models\Obj>. 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...
37
    }
38
39
    public function setLabel($label)
40
    {
41
        $this->_label = $label;
42
    }
43
44
    public function getLabel()
45
    {
46
        if ($this->_label === null) {
47
            $this->_label = ObjLabelWidget::widget(['model' => $this->model]);
48
        }
49
50
        return $this->_label;
51
    }
52
}
53