File   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 0
loc 53
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A behaviors() 0 11 1
A beforeSave() 0 13 5
A find() 0 4 1
1
<?php
2
3
namespace app\models\entity;
4
5
use Yii;
6
use yii\behaviors\TimestampBehavior;
7
8
/**
9
 * This is the model class for table "{{%file}}"
10
 *
11
 * @property integer $id
12
 * @property integer $user_id
13
 * @property string $title
14
 * @property string $name
15
 * @property string $date_create
16
 * @property string $date_update
17
 * @property integer $ip
18
 */
19
class File extends \yii\db\ActiveRecord
20
{
21
    /**
22
     * @inheritdoc
23
     * @internal
24
     */
25
    public static function tableName()
26
    {
27
        return '{{%file}}';
28
    }
29
30
    /**
31
     * @inheritdoc
32
     * @internal
33
     */
34
    public function behaviors()
35
    {
36
        return [
37
            [
38
                'class' => TimestampBehavior::class,
39
                'createdAtAttribute' => 'date_create',
40
                'updatedAtAttribute' => 'date_update',
41
                'value' => new \yii\db\Expression('NOW()'),
42
            ],
43
        ];
44
    }
45
46
    /**
47
     * @internal
48
     */
49
    public function beforeSave($insert)
50
    {
51
        if (parent::beforeSave($insert)) {
52
            if ($insert) {
53
                if (!Yii::$app instanceof \yii\console\Application) {
54
                    $this->user_id = Yii::$app->user->isGuest ? 0 : Yii::$app->user->id;
55
                    $this->ip = ip2long(Yii::$app->request->getUserIP());
56
                }
57
            }
58
            return true;
59
        }
60
        return false;
61
    }
62
63
    /**
64
     * @inheritdoc
65
     * @return \app\models\query\FileQuery The active query used by this AR class
66
     */
67
    public static function find()
68
    {
69
        return new \app\models\query\FileQuery(get_called_class());
70
    }
71
}
72