Passed
Push — master ( 30d0f9...a8ef92 )
by Andrey
07:18
created

ActiveRecord::scenarios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace app\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 app\models
13
 */
14
class ActiveRecord extends \yii\db\ActiveRecord
15
{
16
    /**
17
     * Connect behavior to the basic model.
18
     *
19
     * @return array
20
     */
21
    public function behaviors()
22
    {
23
        $behaviors = parent::behaviors();
24
        $behaviors[] = [
25
            'class'              => TimestampBehavior::class,
26
            'createdAtAttribute' => 'created_at',
27
            'updatedAtAttribute' => 'updated_at',
28
            'value'              => new Expression('NOW()'),
29
        ];
30
        return $behaviors;
31
    }
32
33
    /**
34
     * Scenarios.
35
     *
36
     * @return array
37
     */
38
    public function scenarios()
39
    {
40
        return [
41
            ModelInterface::SCENARIO_CREATE => $this->attributes(),
42
            ModelInterface::SCENARIO_UPDATE => $this->attributes(),
43
            self::SCENARIO_DEFAULT => $this->attributes(),
44
        ];
45
    }
46
}
47