Product::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 12/19/17
6
 * Time: 5:49 PM
7
 */
8
9
namespace execut\import\example\models;
10
11
12
use yii\behaviors\TimestampBehavior;
13
use yii\db\ActiveRecord;
14
use yii\db\Expression;
15
16
class Product extends ActiveRecord
17
{
18
    public function behaviors()
19
    {
20
        return [
21
            'date' => [
22
                'class' => TimestampBehavior::class,
23
                'createdAtAttribute' => 'created',
24
                'updatedAtAttribute' => 'updated',
25
                'value' => new Expression('NOW()'),
26
            ],
27
        ];
28
    }
29
30
    public function rules()
31
    {
32
        return [
33
            ['price', 'filter', 'filter' => function ($value) {
34
                return (double) $value;
35
            }],
36
            ['id', 'safe'],
37
            [['name', 'price',
38
                'example_article_id'
39
            ], 'required'],
40
        ];
41
    }
42
43
    public function getExampleArticle() {
44
        return $this->hasOne(Article::class, [
45
            'id' => 'example_article_id',
46
        ]);
47
    }
48
49
    public static function tableName()
50
    {
51
        return 'example_products';
52
    }
53
}