Completed
Push — master ( 7fc3f3...dbb6f1 )
by vistart
05:17
created

BaseMongoEntityModel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 1 Features 0
Metric Value
wmc 5
c 11
b 1
f 0
lcom 2
cbo 1
dl 0
loc 36
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 2
A find() 0 9 2
A attributes() 0 4 1
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\BaseMongoEntityQuery;
16
use vistart\Models\traits\EntityTrait;
17
18
/**
19
 * Description of BaseMongoEntityModel
20
 *
21
 * @version 2.0
22
 * @author vistart <[email protected]>
23
 */
24
abstract class BaseMongoEntityModel extends \yii\mongodb\ActiveRecord
25
{
26
    use EntityTrait;
27
28
    /**
29
     * Initialize new entity.
30
     */
31 1
    public function init()
32
    {
33 1
        if ($this->skipInit) {
34 1
            return;
35
        }
36 1
        $this->idAttribute = '_id';
37 1
        $this->initEntityEvents();
38 1
        parent::init();
39 1
    }
40
41
    /**
42
     * @inheritdoc
43
     * @return \vistart\Models\queries\BaseMongoEntityQuery the newly created [[BaseEntityQuery]] or its sub-class instance.
44
     */
45 1
    public static function find()
46
    {
47 1
        $self = static::buildNoInitModel();
48 1
        if (!is_string($self->queryClass)) {
49 1
            $self->queryClass = BaseMongoEntityQuery::className();
50 1
        }
51 1
        $queryClass = $self->queryClass;
52 1
        return new $queryClass(get_called_class(), ['noInitModel' => $self]);
53
    }
54
55 1
    public function attributes()
56
    {
57 1
        return $this->enabledFields();
58
    }
59
}
60