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

PermissionController::getSearchModelName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\RbacModule\controllers;
4
5
use Itstructure\RbacModule\models\{Permission, PermissionSearch};
6
7
/**
8
 * Class PermissionController
9
 * PermissionController implements the CRUD actions for Permission model.
10
 *
11
 * @package Itstructure\RbacModule\controllers
12
 */
13 View Code Duplication
class PermissionController extends BaseController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * Initialize.
17
     * Set viewPath and validateComponent.
18
     */
19
    public function init()
20
    {
21
        $this->viewPath = '@rbac/views/permissions';
22
23
        $this->validateComponent = $this->module->get('rbac-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...
24
25
        parent::init();
26
    }
27
28
    /**
29
     * Returns Permission model name.
30
     *
31
     * @return string
32
     */
33
    protected function getModelName():string
34
    {
35
        return Permission::class;
36
    }
37
38
    /**
39
     * Returns PermissionSearch model name.
40
     *
41
     * @return string|null
42
     */
43
    protected function getSearchModelName():string
44
    {
45
        return PermissionSearch::class;
46
    }
47
48
    /**
49
     * Returns new object of search main model.
50
     *
51
     * @return mixed
52
     */
53
    protected function getNewSearchModel()
54
    {
55
        return parent::getNewSearchModel()->setAuthManager($this->validateComponent->getAuthManager());
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...
56
    }
57
}
58