BaseRedisEntityModel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 95%

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 7
c 7
b 1
f 0
lcom 2
cbo 1
dl 0
loc 44
ccs 19
cts 20
cp 0.95
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 9 2
A attributes() 0 4 1
A primaryKey() 0 8 2
A init() 0 8 2
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link http://vistart.name/
9
 * @copyright Copyright (c) 2016 vistart
10
 * @license http://vistart.name/license/
11
 */
12
13
namespace vistart\Models\models;
14
15
use vistart\Models\queries\BaseRedisEntityQuery;
16
use vistart\Models\traits\EntityTrait;
17
18
/**
19
 * Description of BaseRedisEntityModel
20
 *
21
 * @version 2.0
22
 * @author vistart <[email protected]>
23
 */
24
abstract class BaseRedisEntityModel extends \yii\redis\ActiveRecord
25
{
26
    use EntityTrait;
27
28
    /**
29
     * Initialize new entity.
30
     */
31 7
    public function init()
32
    {
33 7
        if ($this->skipInit) {
34 1
            return;
35
        }
36 7
        $this->initEntityEvents();
37 7
        parent::init();
38 7
    }
39
40
    /**
41
     * @inheritdoc
42
     * @return \vistart\Models\queries\BaseRedisEntityQuery the newly created [[BaseEntityQuery]] or its sub-class instance.
43
     */
44 7
    public static function find()
45
    {
46 7
        $self = static::buildNoInitModel();
47 7
        if (!is_string($self->queryClass)) {
48 1
            $self->queryClass = BaseRedisEntityQuery::className();
49 1
        }
50 7
        $queryClass = $self->queryClass;
51 7
        return new $queryClass(get_called_class(), ['noInitModel' => $self]);
52
    }
53
54 7
    public function attributes()
55
    {
56 7
        return $this->enabledFields();
57
    }
58
59 5
    public static function primaryKey()
60
    {
61 5
        $model = static::buildNoInitModel();
62 5
        if (is_string($model->guidAttribute)) {
63 5
            return [$model->guidAttribute];
64
        }
65
        return [$model->idAttribute];
66
    }
67
}
68