Completed
Push — master ( 3f24f8...42984c )
by Andrey
01:17
created

RbacValidateComponent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 5
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setModel() 5 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Itstructure\RbacModule\components;
4
5
use yii\base\{Model, InvalidConfigException};
6
use Itstructure\RbacModule\{
7
    interfaces\ModelInterface,
8
    interfaces\ValidateComponentInterface
9
};
10
11
/**
12
 * Class RbacValidateComponent
13
 * Component class for RBAC.
14
 *
15
 * @package Itstructure\RbacModule\components
16
 */
17
class RbacValidateComponent extends BaseValidateComponent implements ValidateComponentInterface
18
{
19
    /**
20
     * Sets Rbac model.
21
     *
22
     * @param Model $model
23
     *
24
     * @throws InvalidConfigException
25
     *
26
     * @return ModelInterface
27
     */
28
    public function setModel(Model $model): ModelInterface
29
    {
30 View Code Duplication
        if (!($model instanceof ModelInterface)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
31
32
            $modelClass = (new\ReflectionClass($model));
33
34
            throw new InvalidConfigException($modelClass->getNamespaceName() .
35
                '\\' . $modelClass->getShortName().' class  must be implemented from 
36
                Itstructure\RbacModule\interfaces\ModelInterface.');
37
        }
38
39
        $model->setAuthManager($this->authManager);
0 ignored issues
show
Documentation introduced by
The property $authManager is declared private in Itstructure\RbacModule\c...s\BaseValidateComponent. 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...
40
41
        return $model;
42
    }
43
}
44