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.
Completed
Push — master ( f34d5d...b9feb0 )
by Vadim
33:50
created

ActiveRecord::is_closure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: vadim
5
 * Date: 22.01.15
6
 * Time: 13:47
7
 */
8
9
namespace sibds\components;
10
11
use Yii;
12
use yii\behaviors\TimestampBehavior;
13
use sibds\behaviors\UserDataBehavior;
14
use sibds\behaviors\TrashBehavior;
15
use yii\helpers\ArrayHelper;
16
use yii\db\Expression;
17
18
class ActiveRecord extends \yii\db\ActiveRecord
19
{
20
    use BeforeQueryTrait;
21
22
    //Status state
23
    const STATUS_UNLOCK = 0;
24
    const STATUS_LOCK = 1; //Blocking records
25
26
    public static $BEFORE_QUERY = ['locked' => self::STATUS_UNLOCK];
27
28
29
    // Dynamical fields for behaviors
30
    /**
31
     * @var string the attribute that will receive timestamp value
32
     * Set this property to false if you do not want to record the creation time.
33
     */
34
    public $createdAtAttribute = 'created_at';
35
    /**
36
     * @var string the attribute that will receive timestamp value.
37
     * Set this property to false if you do not want to record the update time.
38
     */
39
    public $updatedAtAttribute = 'updated_at';
40
41
    /**
42
     * @var string the attribute that will receive current user ID value
43
     * Set this property to false if you do not want to record the creator ID.
44
     */
45
    public $createdByAttribute = 'created_by';
46
    /**
47
     * @var string the attribute that will receive current user ID value
48
     * Set this property to false if you do not want to record the updater ID.
49
     */
50
    public $updatedByAttribute = 'updated_by';
51
52
    public $lockedAttribute = 'locked';
53
54
    public $removedAttribute = 'removed';
55
56
57
    public function behaviors()
58
    {
59
        /*Sources:
60
         * https://yii2framework.wordpress.com/2014/11/15/yii-2-behaviors-blameable-and-timestamp/comment-page-1/
61
         * https://toster.ru/q/82962
62
         * */
63
        // If table not have fields, then behavior not use
64
        $behaviors = [];
65
        //Check timestamp
66 View Code Duplication
        if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) {
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...
67
                    $behaviors['timestamp'] = [
68
                'class' => TimestampBehavior::className(),
69
                'attributes' => [
70
                    ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdAtAttribute, $this->updatedAtAttribute],
71
                    ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedAtAttribute,
72
                ],
73
                'value' => new Expression('NOW()'), //TODO: need to change for different DB
74
            ];
75
        }
76
77
        //Check blameable
78 View Code Duplication
        if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) {
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...
79
                    $behaviors['blameable'] = [
80
                'class' => UserDataBehavior::className(),
81
                'attributes' => [
82
                    ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdByAttribute, $this->updatedByAttribute],
83
                    ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedByAttribute,
84
                ],
85
            ];
86
        }
87
88
        //Check trash
89
        if ($this->hasAttribute($this->removedAttribute)) {
90
            $behaviors['trash'] = [
91
                'class' => TrashBehavior::className(),
92
                'trashAttribute' => $this->removedAttribute,
93
            ];
94
        }
95
96
        //Check locked
97
        if ($this->hasAttribute($this->lockedAttribute)) {
98
            $behaviors['locked'] = [
99
                'class' => LockedBehavior::className(),
100
                'lockedAttribute' => $this->lockedAttribute,
101
            ];
102
        }
103
        
104
        if($this->isNestedSet()){
105
            $behaviors['tree'] = ArrayHelper::merge([
106
                'class' => \creocoder\nestedsets\NestedSetsBehavior::className(),
107
                'leftAttribute' => 'lft',
108
                'rightAttribute' => 'rgt',
109
                'depthAttribute' => 'depth',
110
            ], ($this->hasAttribute('tree')?['treeAttribute' => 'tree']:[]));
111
        }
112
113
        return $behaviors;
114
    }
115
116
    public function isNestedSet(){
117
        return $this->hasAttribute('lft')&&$this->hasAttribute('rgt')&&$this->hasAttribute('depth');
118
    }
119
120
    /**
121
     * Duplicate entries in the table.
122
     * @return $this|null
123
     */
124
    public function duplicate() {
125
        $this->isNewRecord = true;
126
127
        foreach ($this->primaryKey() as $key) {
128
                    $this->$key = null;
129
        }
130
131
        if ($this->save()) {
132
            return $this;
133
        }
134
        return null;
135
    }
136
    
137
    
138
    /**
139
     * @author Vitaly Voskobovich <[email protected]>
140
     */ 
141
    public static function listAll($keyField = 'id', $valueField = 'name', $asArray = true)
142
    {
143
        $query = static::find();        
144
        if ($asArray&&!self::is_closure($valueField)) {
145
            $query->select([$keyField, $valueField])->asArray();
146
        }
147
148
        return ArrayHelper::map($query->all(), $keyField, $valueField);
149
    }
150
151
    public static function is_closure($t) {
152
        return is_object($t) && ($t instanceof Closure);
0 ignored issues
show
Bug introduced by
The class sibds\components\Closure does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
153
    }
154
}
155