Account   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 1
Metric Value
eloc 46
dl 0
loc 166
rs 10
c 5
b 2
f 1
wmc 19

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getAccountCategories() 0 3 1
A getCategories() 0 3 1
A tableName() 0 3 1
A getInvalidationType() 0 3 1
A getLastAccountStats() 0 5 1
A getAccountNotes() 0 3 1
A attributeLabels() 0 15 1
A getMediaMediaAccounts() 0 4 1
A getAccounts() 0 4 1
A getMediaAccounts() 0 3 1
A getAccountStats() 0 3 1
A find() 0 3 1
A attributeHints() 0 4 1
A behaviors() 0 5 1
A getMedia() 0 3 1
A getUsernamePrefixed() 0 3 1
A rules() 0 10 1
A getDisplayName() 0 3 2
1
<?php
2
3
namespace app\models;
4
5
use app\components\UidAttributeBehavior;
6
use yii\behaviors\TimestampBehavior;
7
use yii\db\ActiveRecord;
8
use yii\helpers\ArrayHelper;
9
10
/**
11
 * This is the model class for table "account".
12
 *
13
 * @property int $id
14
 * @property string $uid
15
 * @property string $name
16
 * @property string $username
17
 * @property string $profile_pic_url
18
 * @property string $full_name
19
 * @property string $biography
20
 * @property string $external_url
21
 * @property string $instagram_id
22
 * @property string $updated_at
23
 * @property string $created_at
24
 * @property bool $monitoring
25
 * @property bool $is_valid [tinyint(1)]
26
 * @property int $invalidation_type_id [int(11)]
27
 * @property int $invalidation_count [int(11)]
28
 * @property string $update_stats_after [datetime]
29
 * @property int $followed_by [int(11)]
30
 * @property int $follows [int(11)]
31
 * @property string $er [decimal(19,4)]
32
 * @property string $avg_likes [decimal(19,4)]
33
 * @property string $avg_comments [decimal(19,4)]
34
 * @property string $stats_updated_at [datetime]
35
 * @property bool $is_verified [tinyint(1)]
36
 * @property bool $is_business [tinyint(1)]
37
 * @property string $business_category [varchar(255)]
38
 * @property string $last_post_taken_at [datetime]
39
 *
40
 * @property string $usernamePrefixed
41
 * @property string $displayName
42
 *
43
 * @property AccountStats $lastAccountStats
44
 *
45
 * @property AccountInvalidationType $invalidationType
46
 * @property AccountCategory[] $accountCategories
47
 * @property Category[] $categories
48
 * @property AccountNote[] $accountNotes
49
 * @property AccountStats[] $accountStats
50
 * @property Media[] $media
51
 * @property MediaAccount[] $mediaAccounts
52
 * @property \app\models\Account[] $accounts
53
 */
54
class Account extends ActiveRecord
55
{
56
    public $occurs;
57
58
    public function behaviors()
59
    {
60
        return ArrayHelper::merge(parent::behaviors(), [
61
            'time' => TimestampBehavior::class,
62
            'uid' => UidAttributeBehavior::class,
63
        ]);
64
    }
65
66
    public function getDisplayName()
67
    {
68
        return $this->name ?: $this->getUsernamePrefixed();
69
    }
70
71
    public function getUsernamePrefixed()
72
    {
73
        return "@{$this->username}";
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public static function tableName()
80
    {
81
        return 'account';
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function rules()
88
    {
89
        return [
90
            [['username'], 'required'],
91
            [['updated_at', 'created_at', 'stats_updated_at', 'last_post_taken_at'], 'safe'],
92
            [['occurs', 'followed_by', 'follows', 'media'], 'integer'],
93
            [['er', 'avg_likes', 'avg_comments'], 'number'],
94
            [['name', 'username', 'profile_pic_url', 'full_name', 'biography', 'external_url', 'instagram_id', '!uid', 'business_category'], 'string', 'max' => 255],
95
            [['monitoring', 'is_valid', 'is_valid', 'is_business'], 'boolean'],
96
            [['username'], 'unique'],
97
        ];
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function attributeLabels()
104
    {
105
        return [
106
            'id' => 'ID',
107
            'name' => 'Name',
108
            'username' => 'Username',
109
            'profile_pic_url' => 'Profile Pic Url',
110
            'full_name' => 'Full Name',
111
            'biography' => 'Biography',
112
            'external_url' => 'External Url',
113
            'instagram_id' => 'Instagram ID',
114
            'updated_at' => 'Updated At',
115
            'created_at' => 'Created At',
116
            'monitoring' => 'Monitoring',
117
            'er' => 'Engagement',
118
        ];
119
    }
120
121
    public function attributeHints()
122
    {
123
        return [
124
            'name' => 'The name displayed in the lists, if empty, the \'username\' will be used.',
125
        ];
126
    }
127
128
    /**
129
     * @return \yii\db\ActiveQuery
130
     */
131
    public function getInvalidationType()
132
    {
133
        return $this->hasOne(AccountInvalidationType::class, ['id' => 'invalidation_type_id']);
134
    }
135
136
    /**
137
     * @return \yii\db\ActiveQuery
138
     */
139
    public function getAccountCategories()
140
    {
141
        return $this->hasMany(AccountCategory::class, ['account_id' => 'id']);
142
    }
143
144
    /**
145
     * @return \yii\db\ActiveQuery
146
     * @throws \yii\base\InvalidConfigException
147
     */
148
    public function getCategories()
149
    {
150
        return $this->hasMany(Category::class, ['id' => 'category_id'])->viaTable('account_category', ['account_id' => 'id']);
151
    }
152
153
    /**
154
     * @return \yii\db\ActiveQuery
155
     */
156
    public function getAccountNotes()
157
    {
158
        return $this->hasMany(AccountNote::class, ['account_id' => 'id']);
159
    }
160
161
    /**
162
     * @return \yii\db\ActiveQuery
163
     */
164
    public function getAccountStats()
165
    {
166
        return $this->hasMany(AccountStats::class, ['account_id' => 'id']);
167
    }
168
169
    /**
170
     * @return \yii\db\ActiveQuery
171
     */
172
    public function getLastAccountStats()
173
    {
174
        return $this->hasOne(AccountStats::class, ['account_id' => 'id'])
175
            ->orderBy('account_stats.id DESC')
176
            ->limit(1);
177
    }
178
179
    /**
180
     * @return \yii\db\ActiveQuery
181
     */
182
    public function getMedia()
183
    {
184
        return $this->hasMany(Media::class, ['account_id' => 'id']);
185
    }
186
187
    /**
188
     * @return \yii\db\ActiveQuery
189
     */
190
    public function getMediaMediaAccounts()
191
    {
192
        return $this->hasMany(MediaAccount::class, ['media_id' => 'id'])
193
            ->via('media');
194
    }
195
196
    /**
197
     * @return \yii\db\ActiveQuery
198
     */
199
    public function getAccounts()
200
    {
201
        return $this->hasMany(Account::class, ['id' => 'account_id'])
202
            ->via('mediaMediaAccounts');
203
    }
204
205
    /**
206
     * @return \yii\db\ActiveQuery
207
     */
208
    public function getMediaAccounts()
209
    {
210
        return $this->hasMany(MediaAccount::class, ['account_id' => 'id']);
211
    }
212
213
    /**
214
     * @inheritdoc
215
     * @return AccountQuery the active query used by this AR class.
216
     */
217
    public static function find()
218
    {
219
        return new AccountQuery(get_called_class());
220
    }
221
}
222