Completed
Branch dev (794b40)
by Andrey
04:12
created

ProfileValidateComponent   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A setModel() 0 11 1
1
<?php
2
3
namespace Itstructure\RbacModule\components;
4
5
use Yii;
6
use yii\base\{Model, InvalidConfigException};
7
use Itstructure\RbacModule\{
8
    interfaces\ModelInterface,
9
    interfaces\ValidateComponentInterface,
10
    models\ProfileValidate
11
};
12
13
/**
14
 * Class ProfileValidateComponent
15
 * Component class for validation user fields.
16
 *
17
 * @package Itstructure\RbacModule\components
18
 */
19
class ProfileValidateComponent extends BaseValidateComponent implements ValidateComponentInterface
20
{
21
    /**
22
     * Set a user model for ProfileValidateComponent validation model.
23
     *
24
     * @param Model $model
25
     *
26
     * @throws InvalidConfigException
27
     *
28
     * @return ModelInterface
29
     */
30
    public function setModel(Model $model): ModelInterface
31
    {
32
        /** @var ModelInterface $object */
33
        $object = Yii::createObject([
34
            'class' => ProfileValidate::class,
35
            'profileModel' => $model,
36
            'authManager' => $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...
37
        ]);
38
39
        return $object;
40
    }
41
}
42