Completed
Push — master ( 794b40...f53c10 )
by Andrey
01:20
created

ProfileController::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\RbacModule\controllers;
4
5
/**
6
 * Class ProfileController
7
 * ProfileController implements the CRUD actions for identityClass.
8
 *
9
 * @package Itstructure\RbacModule\controllers
10
 */
11
class ProfileController extends BaseController
12
{
13
    /**
14
     * Initialize.
15
     * Set validateComponent and additionFields.
16
     */
17
    public function init()
18
    {
19
        $this->viewPath = '@rbac/views/profiles';
20
21
        $this->validateComponent = $this->module->get('profile-validate-component');
0 ignored issues
show
Documentation introduced by
The property $validateComponent is declared private in Itstructure\RbacModule\controllers\BaseController. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
22
23
        parent::init();
24
    }
25
26
    /**
27
     * Returns addition fields.
28
     *
29
     * @return array
30
     */
31
    protected function getAdditionFields(): array
32
    {
33
        $additionFields = [];
34
35
        if ($this->action->id == 'update') {
36
            $additionFields['roles'] = $this->validateComponent->getAuthManager()->getRoles();
0 ignored issues
show
Documentation introduced by
The property $validateComponent is declared private in Itstructure\RbacModule\controllers\BaseController. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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
        return $additionFields;
40
    }
41
42
    /**
43
     * Returns identityClass model name.
44
     *
45
     * @return string
46
     */
47
    protected function getModelName(): string
48
    {
49
        return \Yii::$app->user->identityClass;
50
    }
51
52
    /**
53
     * Returns identityClass Search model name.
54
     *
55
     * @return string
56
     */
57
    protected function getSearchModelName(): string
58
    {
59
        return \Yii::$app->user->identityClass . 'Search';
60
    }
61
}
62