Completed
Push — master ( 93e8e1...4666a2 )
by vistart
03:17
created

Organization::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.032
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\organization;
14
15
use rhosocial\organization\queries\OrganizationQuery;
16
use yii\behaviors\AttributeBehavior;
17
18
/**
19
 * @version 1.0
20
 * @author vistart <[email protected]>
21
 */
22
class Organization extends BaseOrganization
23
{
24
    public $parentAttribute = 'parent';
25
26 8
    public function init()
27
    {
28 8
        if (!is_string($this->queryClass)) {
29
            $this->queryClass = OrganizationQuery::class;
30
        }
31 8
        parent::init();
32 8
    }
33
34 8
    protected function typeAttributeBehavior()
35
    {
36
        return [
37
            [
38
                'class' => AttributeBehavior::class,
39
                'attributes' => [
40 8
                    self::EVENT_BEFORE_INSERT => 'type',
41 8
                    self::EVENT_BEFORE_UPDATE => 'type',
42
                ],
43 8
                'value' => self::TYPE_ORGANIZATION,
44
            ]
45 8
        ];
46
    }
47
48
    /**
49
     * The default value of `type` attribute is `ORGANIZATION`(1).
50
     * @return array Rules associated with `type` attribute.
51
     */
52 8
    protected function getTypeRules()
53
    {
54
        return [
55 8
            ['type', 'default', 'value' => self::TYPE_ORGANIZATION],
56
            ['type', 'required'],
57 8
            ['type', 'in', 'range' => [self::TYPE_ORGANIZATION]],
58
        ];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 8
    public static function find()
65
    {
66 8
        return parent::find()->andWhere(['type' => self::TYPE_ORGANIZATION]);
67
    }
68
}