ActiveRecord   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 12
c 2
b 1
f 1
dl 0
loc 30
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 10 1
A scenarios() 0 6 1
1
<?php
2
3
namespace Itstructure\AdminModule\models;
4
5
use yii\behaviors\TimestampBehavior;
6
use yii\db\Expression;
7
use Itstructure\AdminModule\interfaces\ModelInterface;
8
9
/**
10
 * Class ActiveRecord
11
 *
12
 * @package Itstructure\AdminModule\models
13
 *
14
 * @author Andrey Girnik <[email protected]>
15
 */
16
class ActiveRecord extends \yii\db\ActiveRecord
17
{
18
    /**
19
     * Connect behavior to the basic model.
20
     *
21
     * @return array
22
     */
23
    public function behaviors()
24
    {
25
        $behaviors = parent::behaviors();
26
        $behaviors[] = [
27
            'class'              => TimestampBehavior::class,
28
            'createdAtAttribute' => 'created_at',
29
            'updatedAtAttribute' => 'updated_at',
30
            'value'              => new Expression('NOW()'),
31
        ];
32
        return $behaviors;
33
    }
34
35
    /**
36
     * Scenarios.
37
     *
38
     * @return array
39
     */
40
    public function scenarios()
41
    {
42
        return [
43
            ModelInterface::SCENARIO_CREATE => $this->attributes(),
44
            ModelInterface::SCENARIO_UPDATE => $this->attributes(),
45
            self::SCENARIO_DEFAULT => $this->attributes(),
46
        ];
47
    }
48
}
49