Reauthenticates::postReauthenticate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Mpociot\Reauthenticate;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Lang;
7
use Illuminate\Support\Facades\Redirect;
8
use Illuminate\Support\Facades\View;
9
10
trait Reauthenticates
11
{
12
    /**
13
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
14
     */
15
    public function getReauthenticate()
16
    {
17
        return View::make('auth.reauthenticate');
18
    }
19
20
    /**
21
     * Handle the reauthentication request to the application.
22
     *
23
     * @param \Illuminate\Http\Request $request
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function postReauthenticate(Request $request)
28
    {
29
        $this->validate($request, [
0 ignored issues
show
Bug introduced by
It seems like validate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30
            'password' => 'required',
31
        ]);
32
33
        $reauth = new ReauthLimiter($request);
34
35
        if (!$reauth->attempt($request->password)) {
36
            return Redirect::back()
37
                ->withErrors([
38
                    'password' => $this->getFailedLoginMessage(),
39
                ]);
40
        }
41
42
        return Redirect::intended();
43
    }
44
45
    /**
46
     * Get the failed login message.
47
     *
48
     * @return string
49
     */
50
    protected function getFailedLoginMessage()
51
    {
52
        return Lang::has('auth.failed')
53
            ? Lang::get('auth.failed')
54
            : 'These credentials do not match our records.';
55
    }
56
}
57