Completed
Push — master ( cdb114...273f6a )
by Abdelrahman
02:18
created

PasswordResetController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Frontend;
17
18
use Rinvex\Fort\Contracts\ResetBrokerContract;
19
use Rinvex\Fort\Http\Controllers\AbstractController;
20
use Rinvex\Fort\Http\Requests\Frontend\PasswordReset;
21
use Rinvex\Fort\Http\Requests\Frontend\PasswordResetRequest;
22
23
class PasswordResetController extends AbstractController
24
{
25
    /**
26
     * Create a new password reset controller instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct()
31
    {
32
        $this->middleware($this->getGuestMiddleware(), ['except' => $this->middlewareWhitelist]);
33
    }
34
35
    /**
36
     * Show the password reset request form.
37
     *
38
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40
    public function request()
41
    {
42
        return view('rinvex.fort::frontend.passwordreset.request');
43
    }
44
45
    /**
46
     * Process the password reset request form.
47
     *
48
     * @param \Rinvex\Fort\Http\Requests\Frontend\PasswordResetRequest $request
49
     *
50
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
51
     */
52
    public function send(PasswordResetRequest $request)
53
    {
54
        $result = app('rinvex.fort.resetter')->broker($this->getBroker())->sendResetLink($request->except(['_token']));
55
56
        switch ($result) {
57
            case ResetBrokerContract::LINK_SENT:
58
                return intend([
59
                    'intended' => url('/'),
60
                    'with'     => ['rinvex.fort.alert.success' => trans($result)],
61
                ]);
62
63
            case ResetBrokerContract::INVALID_USER:
64
            default:
65
                return intend([
66
                    'back'       => true,
67
                    'withInput'  => $request->only('email'),
68
                    'withErrors' => ['email' => trans($result)],
69
                ]);
70
        }
71
    }
72
73
    /**
74
     * Show the password reset form.
75
     *
76
     * @param \Rinvex\Fort\Http\Requests\Frontend\PasswordReset $request
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function reset(PasswordReset $request)
81
    {
82
        $email  = $request->get('email');
83
        $token  = $request->get('token');
84
        $result = app('rinvex.fort.resetter')->broker($this->getBroker())->validateReset($request->except(['_token']));
85
86
        switch ($result) {
87
            case ResetBrokerContract::INVALID_USER:
88
            case ResetBrokerContract::INVALID_TOKEN:
89
                return intend([
90
                    'intended'   => route('rinvex.fort.frontend.passwordreset.request'),
91
                    'withInput'  => $request->only('email'),
92
                    'withErrors' => ['email' => trans($result)],
93
                ]);
94
95
            case ResetBrokerContract::VALID_TOKEN:
96
            default:
97
                return view('rinvex.fort::frontend.passwordreset.reset')->with(compact('token', 'email'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
98
        }
99
    }
100
101
    /**
102
     * Process the password reset form.
103
     *
104
     * @param \Rinvex\Fort\Http\Requests\Frontend\PasswordReset $request
105
     *
106
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
107
     */
108
    public function process(PasswordReset $request)
109
    {
110
        $result = app('rinvex.fort.resetter')->broker($this->getBroker())->reset($request->except(['_token']));
111
112
        switch ($result) {
113
            case ResetBrokerContract::RESET_SUCCESS:
114
                return intend([
115
                    'intended' => url('/'),
116
                    'with'     => ['rinvex.fort.alert.success' => trans($result)],
117
                ]);
118
119
            case ResetBrokerContract::INVALID_USER:
120
            case ResetBrokerContract::INVALID_TOKEN:
121
            case ResetBrokerContract::INVALID_PASSWORD:
122
            default:
123
                return intend([
124
                    'intended'   => route('rinvex.fort.frontend.passwordreset.request'),
125
                    'withInput'  => $request->only('email'),
126
                    'withErrors' => ['email' => trans($result)],
127
                ]);
128
        }
129
    }
130
}
131