Completed
Pull Request — master (#251)
by
unknown
02:45
created

TokenFactory::makeRecoveryToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Factory;
13
14
use Da\User\Model\Token;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
18
class TokenFactory
19
{
20
    /**
21
     * @param $userId
22
     *
23
     * @throws InvalidConfigException
24
     * @return Token
25
     */
26 3
    public static function makeConfirmationToken($userId)
27
    {
28 3
        $token = self::make($userId, Token::TYPE_CONFIRMATION);
0 ignored issues
show
Bug Compatibility introduced by
The expression self::make($userId, \Da\...en::TYPE_CONFIRMATION); of type Da\User\Model\Token|object adds the type object to the return on line 32 which is incompatible with the return type documented by Da\User\Factory\TokenFac...::makeConfirmationToken of type Da\User\Model\Token.
Loading history...
29
30 3
        $token->save(false);
31
32 3
        return $token;
33
    }
34
35
    /**
36
     * @param $userId
37
     *
38
     * @return Token
39
     */
40 1
    public static function makeConfirmNewMailToken($userId)
41
    {
42 1
        $token = self::make($userId, Token::TYPE_CONFIRM_NEW_EMAIL);
0 ignored issues
show
Bug Compatibility introduced by
The expression self::make($userId, \Da\...YPE_CONFIRM_NEW_EMAIL); of type Da\User\Model\Token|object adds the type object to the return on line 46 which is incompatible with the return type documented by Da\User\Factory\TokenFac...makeConfirmNewMailToken of type Da\User\Model\Token.
Loading history...
43
44 1
        $token->save(false);
45
46 1
        return $token;
47
    }
48
49
    /**
50
     * @param $userId
51
     *
52
     * @throws InvalidConfigException
53
     * @return Token
54
     */
55
    public static function makeConfirmOldMailToken($userId)
56
    {
57
        $token = self::make($userId, Token::TYPE_CONFIRM_OLD_EMAIL);
0 ignored issues
show
Bug Compatibility introduced by
The expression self::make($userId, \Da\...YPE_CONFIRM_OLD_EMAIL); of type Da\User\Model\Token|object adds the type object to the return on line 61 which is incompatible with the return type documented by Da\User\Factory\TokenFac...makeConfirmOldMailToken of type Da\User\Model\Token.
Loading history...
58
59
        $token->save(false);
60
61
        return $token;
62
    }
63
64
    /**
65
     * @param $userId
66
     *
67
     * @throws InvalidConfigException
68
     * @return Token
69
     */
70 1
    public static function makeRecoveryToken($userId)
71
    {
72 1
        $token = self::make($userId, Token::TYPE_RECOVERY);
0 ignored issues
show
Bug Compatibility introduced by
The expression self::make($userId, \Da\...\Token::TYPE_RECOVERY); of type Da\User\Model\Token|object adds the type object to the return on line 76 which is incompatible with the return type documented by Da\User\Factory\TokenFactory::makeRecoveryToken of type Da\User\Model\Token.
Loading history...
73
74 1
        $token->save(false);
75
76 1
        return $token;
77
    }
78
79
    /**
80
     * @param $userId
81
     * @param $type
82
     *
83
     * @throws InvalidConfigException
84
     * @return Token|\object
85
     */
86 5
    protected static function make($userId, $type)
87
    {
88 5
        return Yii::createObject(['class' => Token::class, 'user_id' => $userId, 'type' => $type]);
89
    }
90
}
91