Completed
Push — master ( 03b333...573f2e )
by Abdelrahman
02:45
created

ResetPasswordController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 70
rs 10
wmc 10
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A showResetPassword() 0 20 4
B processResetPassword() 0 22 5
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 Illuminate\Support\Facades\Lang;
19
use Rinvex\Fort\Http\Requests\PasswordReset;
20
use Rinvex\Fort\Contracts\ResetBrokerContract;
21
use Rinvex\Fort\Http\Controllers\AbstractController;
22
23
class ResetPasswordController extends AbstractController
24
{
25
    /**
26
     * Create a new reset password 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 form.
37
     *
38
     * @param \Rinvex\Fort\Http\Requests\PasswordReset $request
39
     *
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function showResetPassword(PasswordReset $request)
43
    {
44
        $email  = $request->get('email');
45
        $token  = $request->get('token');
46
        $result = app('rinvex.fort.resetter')->broker($this->getBroker())->validateReset($request->except(['_token']));
47
48
        switch ($result) {
49
            case ResetBrokerContract::INVALID_USER:
50
            case ResetBrokerContract::INVALID_TOKEN:
51
                return intend([
52
                    'intended'   => route('rinvex.fort.password.forgot'),
53
                    'withInput'  => $request->only('email'),
54
                    'withErrors' => ['email' => Lang::get($result)],
55
                ]);
56
57
            case ResetBrokerContract::VALID_TOKEN:
58
            default:
59
                return view('rinvex.fort::password.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...
60
        }
61
    }
62
63
    /**
64
     * Process the password reset form.
65
     *
66
     * @param \Rinvex\Fort\Http\Requests\PasswordReset $request
67
     *
68
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
69
     */
70
    public function processResetPassword(PasswordReset $request)
71
    {
72
        $result = app('rinvex.fort.resetter')->broker($this->getBroker())->reset($request->except(['_token']));
73
74
        switch ($result) {
75
            case ResetBrokerContract::RESET_SUCCESS:
76
                return intend([
77
                    'intended' => route('home'),
78
                    'with'     => ['rinvex.fort.alert.success' => Lang::get($result)],
79
                ]);
80
81
            case ResetBrokerContract::INVALID_USER:
82
            case ResetBrokerContract::INVALID_TOKEN:
83
            case ResetBrokerContract::INVALID_PASSWORD:
84
            default:
85
                return intend([
86
                    'intended'   => route('rinvex.fort.password.forgot'),
87
                    'withInput'  => $request->only('email'),
88
                    'withErrors' => ['email' => Lang::get($result)],
89
                ]);
90
        }
91
    }
92
}
93