Setting   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 7 1
A findOneByKey() 0 7 1
1
<?php
2
3
namespace andmemasin\myabstract;
4
5
use andmemasin\myabstract\interfaces\SettingInterface;
6
7
/**
8
 * Class Setting
9
 * @package app\modules\andmemasin\myabstract\src
10
 * @author Tõnis Ormisson <[email protected]>
11
 * @property string $key
12
 * @property string $value
13
 */
14
class Setting extends MyActiveRecord implements SettingInterface
15
{
16
17
    /** @var string  */
18
    public $keyColumn = 'key';
19
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function rules()
25
    {
26
        return array_merge(parent::rules(), [
27
            [[$this->keyColumn], 'required'],
28
            [['value'], 'string'],
29
            [['key'], 'string', 'max' => 128],
30
            [[$this->keyColumn], 'unique']
31
        ]);
32
    }
33
34
35
    /**
36
     * @param $key string
37
     * @return static
38
     */
39
    public function findOneByKey($key){
40
        /** @var static $model */
41
        $model = static::find()
42
            ->andWhere([$this->keyColumn => $key])
43
            ->limit(1)
44
            ->one();
45
        return $model;
46
    }
47
48
}
49