GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UserDataBehavior::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
     * Created by PhpStorm.
4
     * User: vadim
5
     * Date: 26.05.15
6
     * Time: 15:12
7
     */
8
9
namespace sibds\behaviors;
10
11
12
use yii\behaviors\BlameableBehavior;
13
14
class UserDataBehavior extends BlameableBehavior {
15
16
    public $userClass = null;
17
18
    public function init()
19
    {
20
        if (is_null($this->userClass)) {
21
                    $this->userClass = \Yii::$app->user->className();
22
        }
23
    }
24
25
    /**
26
     * @getCreateUser
27
     * @return null|\yii\db\ActiveQuery
28
     */
29
    public function getCreateUser()
30
    {
31
        /* @var $owner BaseActiveRecord */
32
        $owner = $this->owner;
33
34
        if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) {
35
                    return $owner->hasOne($this->userClass, ['id' => $this->createdByAttribute]);
36
        }
37
38
        return null;
39
    }
40
41
    /**
42
     * @getCreateUserName
43
     * @return null|\yii\db\ActiveQuery
44
     */
45 View Code Duplication
    public function getCreateUserName()
0 ignored issues
show
Duplication introduced by
This method 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...
46
    {
47
        /* @var $owner BaseActiveRecord */
48
        $owner = $this->owner;
49
50
        if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) {
51
                    return $this->createUser ? $this->createUser->username : '- no user -';
0 ignored issues
show
Documentation introduced by
The property createUser does not exist on object<sibds\behaviors\UserDataBehavior>. 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...
52
        }
53
54
        return null;
55
    }
56
57
    /**
58
     * @getUpdateUser
59
     * @return null|\yii\db\ActiveQuery
60
     */
61
    public function getUpdateUser()
62
    {
63
        /* @var $owner BaseActiveRecord */
64
        $owner = $this->owner;
65
66
        if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) {
67
                    return $this->hasOne($this->userClass, ['id' => $this->updatedByAttribute]);
0 ignored issues
show
Documentation Bug introduced by
The method hasOne does not exist on object<sibds\behaviors\UserDataBehavior>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
68
        }
69
70
        return null;
71
    }
72
73
    /**
74
     * @getUpdateUserName
75
     * @return null|\yii\db\ActiveQuery
76
     */
77 View Code Duplication
    public function getUpdateUserName()
0 ignored issues
show
Duplication introduced by
This method 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...
78
    {
79
        /* @var $owner BaseActiveRecord */
80
        $owner = $this->owner;
81
82
        if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) {
83
                    return $this->createUser ? $this->updateUser->username : '- no user -';
0 ignored issues
show
Documentation introduced by
The property createUser does not exist on object<sibds\behaviors\UserDataBehavior>. 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...
Documentation introduced by
The property updateUser does not exist on object<sibds\behaviors\UserDataBehavior>. 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...
84
        }
85
86
        return null;
87
    }
88
}