Passed
Push — master ( a90c1b...36c150 )
by Razon
02:16
created

CreatorBehavior::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace App\Behavior;
3
4
use Yii;
5
use yii\behaviors\AttributesBehavior;
6
use yii\db\ActiveRecord;
7
8
class CreatorBehavior extends AttributesBehavior
9
{
10
    public $creatorAttribute = 'creator';
11
12
    public function init()
13
    {
14
        parent::init();
15
16
        $this->attributes = [
17
            $this->creatorAttribute => [
18
                ActiveRecord::EVENT_BEFORE_INSERT => Yii::$app->getUser()->getId(),
19
            ],
20
        ];
21
    }
22
}
23