Test Failed
Push — master ( fde873...dc1916 )
by vistart
05:54
created

Registration::init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 9.6666
cc 3
eloc 6
nc 3
nop 0
crap 3.0261
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\user\models\invitation\registration;
14
15
use rhosocial\user\models\invitation\Invitation;
16
use rhosocial\user\User;
17
use yii\base\InvalidConfigException;
18
19
/**
20
 * Class Registration
21
 * @package rhosocial\user\models\invitation\registration
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class Registration extends Invitation
26
{
27
    const INVITATION_REGISTRATION = 0x01;
28
    public $allowRepeated = false;
29
30
    /**
31
     * @inheritdoc
32
     */
33 1
    public function init()
34
    {
35 1
        parent::init();
36 1
        if ($this->getIsNewRecord()) {
37 1
            $this->content = self::INVITATION_REGISTRATION;
38 1
        } elseif ($this->content != self::INVITATION_REGISTRATION) {
39
            throw new InvalidConfigException("This invitation is not being used for registration.");
40
        }
41 1
    }
42
43
    /**
44
     * @return BaseBlameableQuery
45
     */
46 1
    public static function find()
47
    {
48 1
        return parent::find()->content(self::INVITATION_REGISTRATION);
49
    }
50
51
    /**
52
     * @param User|string $invitee
53
     * @return BaseBlameableQuery
54
     */
55
    public static function findByInvitee($invitee)
56
    {
57
        return parent::findByInvitee($invitee)->content(self::INVITATION_REGISTRATION);
58
    }
59
}
60