SettingsModal::init()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 6
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets;
12
13
use hipanel\base\Model;
14
use hipanel\helpers\FontIcon;
15
use yii\helpers\Html;
16
17
/**
18
 * Class SettingsModal. Render AjaxModal, created specially to render on view page.
19
 */
20
class SettingsModal extends AjaxModal
21
{
22
    /**
23
     * @var Model
24
     */
25
    public $model;
26
27
    /**
28
     * @var string text of toggle link
29
     */
30
    public $title;
31
32
    /**
33
     * @var string template for `label` attribute
34
     */
35
    public $labelTemplate = '{icon} {label}';
36
37
    /**
38
     * @var string icon class for toggle link
39
     * Will be passed through [[FontIcon::i()]] method
40
     */
41
    public $icon;
42
43
    public function init()
44
    {
45
        $this->header = Html::tag('h4', $this->title, ['class' => 'modal-title']);
46
        $this->actionUrl = [$this->scenario, 'id' => $this->model->id];
0 ignored issues
show
Bug introduced by
The property actionUrl does not seem to exist. Did you mean _actionUrl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Documentation introduced by
The property id does not exist on object<hipanel\base\Model>. 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...
47
        $this->toggleButton = array_merge([
48
            'tag' => 'a',
49
            'label' => strtr($this->labelTemplate, ['{icon}' => FontIcon::i($this->icon), '{label}' => $this->title]),
50
            'class' => 'clickable',
51
        ], is_array($this->toggleButton) ? $this->toggleButton : []);
52
        parent::init();
53
    }
54
}
55