Completed
Push — master ( 3f0650...a210b6 )
by Ryan
02:07
created

CompleteResetFormBuilder::onReady()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 4
nop 2
1
<?php namespace Anomaly\UsersModule\User\Reset;
2
3
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
4
use Illuminate\Contracts\Encryption\Encrypter;
5
use Illuminate\Http\Request;
6
7
/**
8
 * Class CompleteResetFormBuilder
9
 *
10
 * @link          http://anomaly.is/streams-platform
11
 * @author        AnomalyLabs, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 * @package       Anomaly\UsersModule\User\Reset
14
 */
15
class CompleteResetFormBuilder extends FormBuilder
16
{
17
18
    /**
19
     * The reset code.
20
     *
21
     * @var null|string
22
     */
23
    protected $code = null;
24
25
    /**
26
     * The user email.
27
     *
28
     * @var null|string
29
     */
30
    protected $email = null;
31
32
    /**
33
     * No model.
34
     *
35
     * @var bool
36
     */
37
    protected $model = false;
38
39
    /**
40
     * The form actions.
41
     *
42
     * @var array
43
     */
44
    protected $actions = [
45
        'submit'
46
    ];
47
48
    /**
49
     * Fired just before building.
50
     *
51
     * @param Encrypter $encrypter
52
     * @param Request   $request
53
     */
54
    public function onReady(Encrypter $encrypter, Request $request)
55
    {
56
        if (!$this->getCode()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getCode() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
57
            $this->setCode($encrypter->decrypt($request->get('code')));
58
        }
59
60
        if (!$this->getEmail()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getEmail() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
61
            $this->setEmail($encrypter->decrypt($request->get('email')));
62
        }
63
    }
64
65
    /**
66
     * Get the email.
67
     *
68
     * @return null|string
69
     */
70
    public function getEmail()
71
    {
72
        return $this->email;
73
    }
74
75
    /**
76
     * Set the email.
77
     *
78
     * @param $email
79
     * @return $this
80
     */
81
    public function setEmail($email)
82
    {
83
        $this->email = $email;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Get the code.
90
     *
91
     * @return null|string
92
     */
93
    public function getCode()
94
    {
95
        return $this->code;
96
    }
97
98
    /**
99
     * Set the code.
100
     *
101
     * @param $code
102
     * @return $this
103
     */
104
    public function setCode($code)
105
    {
106
        $this->code = $code;
107
108
        return $this;
109
    }
110
}
111