Completed
Push — master ( 9c1cd5...e7beb0 )
by Tõnis
03:00
created

Setting   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneByKey() 0 5 1
A rules() 0 7 1
A behaviors() 0 7 1
1
<?php
2
3
namespace andmemasin\myabstract;
4
5
/**
6
 * Class Setting
7
 * @package app\modules\andmemasin\myabstract\src
8
 * @author Tõnis Ormisson <[email protected]>
9
 * @property string $key
10
 * @property string $value
11
 */
12
class Setting extends MyActiveRecord
13
{
14
15
    /** @var string  */
16
    public $keyColumn = 'key';
17
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function rules()
23
    {
24
        return array_merge(parent::rules(), [
25
            [[$this->keyColumn], 'required'],
26
            [['value'], 'string'],
27
            [['key'], 'string', 'max' => 128],
28
            [[$this->keyColumn], 'unique']
29
        ]);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function behaviors()
36
    {
37
        return array_merge([
38
            'actionlog' => [
39
                'class' => 'andmemasin\actionlog\behaviors\ActionLogBehavior',
40
            ],
41
        ], parent::behaviors());
42
    }
43
44
    /**
45
     * @param $key string
46
     * @return static
47
     */
48
    public function findOneByKey($key){
49
        $model = static::find()
50
            ->andWhere([$this->keyColumn => $key])
51
            ->one();
52
        return $model;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model also could return the type array which is incompatible with the documented return type andmemasin\myabstract\Setting.
Loading history...
53
    }
54
55
}