Completed
Push — master ( 5ee4c9...308b6a )
by Antonio
05:05
created

TokenFactory::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
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
17
class TokenFactory
18
{
19
    /**
20
     * @param $userId
21
     *
22
     * @return Token
23
     */
24
    public static function makeConfirmationToken($userId)
25
    {
26
        $token = self::make($userId, Token::TYPE_CONFIRMATION);
27
28
        $token->save(false);
29
30
        return $token;
31
    }
32
33
    /**
34
     * @param $userId
35
     *
36
     * @return Token
37
     */
38
    public static function makeConfirmNewMailToken($userId)
39
    {
40
        $token = self::make($userId, Token::TYPE_CONFIRM_NEW_EMAIL);
41
42
        $token->save(false);
43
44
        return $token;
45
    }
46
47
    /**
48
     * @param $userId
49
     *
50
     * @return Token
51
     */
52
    public static function makeConfirmOldMailToken($userId)
53
    {
54
        $token = self::make($userId, Token::TYPE_CONFIRM_OLD_EMAIL);
55
56
        $token->save(false);
57
58
        return $token;
59
    }
60
61
    /**
62
     * @param $userId
63
     *
64
     * @return Token
65
     */
66
    public static function makeRecoveryToken($userId)
67
    {
68
        $token = self::make($userId, Token::TYPE_RECOVERY);
69
70
        $token->save(false);
71
72
        return $token;
73
    }
74
75
    /**
76
     * @param $userId
77
     * @param $type
78
     *
79
     * @return Token
80
     */
81
    protected static function make($userId, $type)
82
    {
83
        return Yii::createObject(['class' => Token::class, 'user_id' => $userId, 'type' => $type]);
84
    }
85
}
86