Issues (43)

src/Http/Middleware/AuthenticateWithMagicLink.php (5 issues)

Labels
Severity
1
<?php
2
3
namespace Soved\Laravel\Magic\Auth\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
0 ignored issues
show
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Auth\AuthenticationException;
0 ignored issues
show
The type Illuminate\Auth\AuthenticationException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Soved\Laravel\Magic\Auth\Links\LinkBroker;
10
11
class AuthenticateWithMagicLink
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param  \Illuminate\Http\Request  $request
17
     * @param  \Closure  $next
18
     * @param  string|null  $guard
19
     * @return mixed
20
     */
21
    public function handle(
22
        $request,
23
        Closure $next,
24
        $guard = null
25
    ) {
26
        if (!Auth::guard($guard)->check()) {
27
            throw new AuthenticationException;
28
        }
29
30
        if (!Auth::guard($guard)->user()->viaMagicLink()) {
31
            $response = $this->sendMagicLinkEmail($request);
32
33
            Auth::guard($guard)->logout();
34
35
            return redirect()
0 ignored issues
show
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
            return /** @scrutinizer ignore-call */ redirect()
Loading history...
36
                ->guest(route('login'))
0 ignored issues
show
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
                ->guest(/** @scrutinizer ignore-call */ route('login'))
Loading history...
37
                ->with('status', __($response));
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
                ->with('status', /** @scrutinizer ignore-call */ __($response));
Loading history...
38
        }
39
40
        return $next($request);
41
    }
42
43
    /**
44
     * Send a magic link to the given user.
45
     *
46
     * @param  \Illuminate\Http\Request  $request
47
     * @return string
48
     */
49
    private function sendMagicLinkEmail(Request $request)
50
    {
51
        return $this->broker()->sendMagicLink(
52
            [
53
                'email' => $request->user()->email,
54
            ]
55
        );
56
    }
57
58
    /**
59
     * Get the broker to be used during magic authentication.
60
     *
61
     * @return \Soved\Laravel\Magic\Auth\Links\LinkBroker
62
     */
63
    private function broker()
64
    {
65
        $userProvider = Auth::getProvider();
66
67
        return new LinkBroker($userProvider);
68
    }
69
}
70