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

BaseMongoEntityModel::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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