1 | <?php |
||||||||
2 | |||||||||
3 | namespace Soved\Laravel\Magic\Auth\Links; |
||||||||
4 | |||||||||
5 | use Closure; |
||||||||
6 | use Illuminate\Http\Request; |
||||||||
0 ignored issues
–
show
|
|||||||||
7 | use UnexpectedValueException; |
||||||||
8 | use Illuminate\Support\Facades\URL; |
||||||||
9 | use Illuminate\Contracts\Auth\UserProvider; |
||||||||
10 | use Soved\Laravel\Magic\Auth\Contracts\LinkBroker as LinkBrokerContract; |
||||||||
11 | use Soved\Laravel\Magic\Auth\Contracts\CanMagicallyLogin as CanMagicallyLoginContract; |
||||||||
12 | |||||||||
13 | class LinkBroker implements LinkBrokerContract |
||||||||
14 | { |
||||||||
15 | /** |
||||||||
16 | * The user provider implementation. |
||||||||
17 | * |
||||||||
18 | * @var \Illuminate\Contracts\Auth\UserProvider |
||||||||
19 | */ |
||||||||
20 | protected $users; |
||||||||
21 | |||||||||
22 | /** |
||||||||
23 | * Create a new magic link broker instance. |
||||||||
24 | * |
||||||||
25 | * @param \Illuminate\Contracts\Auth\UserProvider $users |
||||||||
26 | * @return void |
||||||||
27 | */ |
||||||||
28 | public function __construct(UserProvider $users) |
||||||||
29 | { |
||||||||
30 | $this->users = $users; |
||||||||
31 | } |
||||||||
32 | |||||||||
33 | /** |
||||||||
34 | * Send a magic link to a user. |
||||||||
35 | * |
||||||||
36 | * @param array $credentials |
||||||||
37 | * @return string |
||||||||
38 | */ |
||||||||
39 | public function sendMagicLink(array $credentials) |
||||||||
40 | { |
||||||||
41 | $user = $this->getUser($credentials); |
||||||||
0 ignored issues
–
show
Are you sure the assignment to
$user is correct as $this->getUser($credentials) targeting Soved\Laravel\Magic\Auth...s\LinkBroker::getUser() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||||
42 | |||||||||
43 | if (is_null($user)) { |
||||||||
0 ignored issues
–
show
|
|||||||||
44 | return static::INVALID_USER; |
||||||||
45 | } |
||||||||
46 | |||||||||
47 | $user->sendMagicLinkNotification( |
||||||||
48 | $this->createMagicLink($user) |
||||||||
49 | ); |
||||||||
50 | |||||||||
51 | return static::MAGIC_LINK_SENT; |
||||||||
52 | } |
||||||||
53 | |||||||||
54 | /** |
||||||||
55 | * Log the user into the application. |
||||||||
56 | * |
||||||||
57 | * @param \Illuminate\Http\Request $request |
||||||||
58 | * @param \Closure $callback |
||||||||
59 | * @return string |
||||||||
60 | */ |
||||||||
61 | public function login( |
||||||||
62 | Request $request, |
||||||||
63 | Closure $callback |
||||||||
64 | ) { |
||||||||
65 | $user = $this->validateLogin($request); |
||||||||
66 | |||||||||
67 | if (!$user instanceof CanMagicallyLoginContract) { |
||||||||
0 ignored issues
–
show
|
|||||||||
68 | return $user; |
||||||||
69 | } |
||||||||
70 | |||||||||
71 | $callback($user); |
||||||||
72 | |||||||||
73 | return static::USER_AUTHENTICATED; |
||||||||
74 | } |
||||||||
75 | |||||||||
76 | /** |
||||||||
77 | * Validate a magic authentication request for the given user. |
||||||||
78 | * |
||||||||
79 | * @param \Illuminate\Http\Request $request |
||||||||
80 | * @return \Soved\Laravel\Magic\Auth\Traits\CanMagicallyLogin|string |
||||||||
81 | */ |
||||||||
82 | protected function validateLogin(Request $request) |
||||||||
83 | { |
||||||||
84 | $credentials = $request->only([ |
||||||||
85 | 'id', |
||||||||
86 | 'email', |
||||||||
87 | 'updated_at', |
||||||||
88 | ]); |
||||||||
89 | |||||||||
90 | if (is_null($user = $this->getUser($credentials))) { |
||||||||
0 ignored issues
–
show
Are you sure the assignment to
$user is correct as $this->getUser($credentials) targeting Soved\Laravel\Magic\Auth...s\LinkBroker::getUser() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||||
91 | return static::INVALID_USER; |
||||||||
92 | } |
||||||||
93 | |||||||||
94 | if (!$request->hasValidSignature()) { |
||||||||
95 | return static::INVALID_SIGNATURE; |
||||||||
96 | } |
||||||||
97 | |||||||||
98 | return $user; |
||||||||
99 | } |
||||||||
100 | |||||||||
101 | /** |
||||||||
102 | * Get the user for the given credentials. |
||||||||
103 | * |
||||||||
104 | * @param array $credentials |
||||||||
105 | * @return \Soved\Laravel\Magic\Auth\Traits\CanMagicallyLogin|null |
||||||||
106 | * |
||||||||
107 | * @throws \UnexpectedValueException |
||||||||
108 | */ |
||||||||
109 | public function getUser(array $credentials) |
||||||||
110 | { |
||||||||
111 | $user = $this->users->retrieveByCredentials($credentials); |
||||||||
112 | |||||||||
113 | if ($user && !$user instanceof CanMagicallyLoginContract) { |
||||||||
114 | throw new UnexpectedValueException('User must implement CanMagicallyLogin interface.'); |
||||||||
115 | } |
||||||||
116 | |||||||||
117 | return $user; |
||||||||
118 | } |
||||||||
119 | |||||||||
120 | /** |
||||||||
121 | * Create a new magic link. |
||||||||
122 | * |
||||||||
123 | * @param \Soved\Laravel\Magic\Auth\Traits\CanMagicallyLogin $user |
||||||||
124 | * @return string |
||||||||
125 | */ |
||||||||
126 | public function createMagicLink(CanMagicallyLoginContract $user) |
||||||||
127 | { |
||||||||
128 | $email = $user->getEmailForMagicLink(); |
||||||||
129 | |||||||||
130 | return URL::temporarySignedRoute( |
||||||||
131 | 'magic.login', |
||||||||
132 | now()->addMinutes(config('magic-auth.expiration')), |
||||||||
0 ignored issues
–
show
The function
config 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
![]() The function
now 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
![]() |
|||||||||
133 | [ |
||||||||
134 | 'id' => $user->id, |
||||||||
0 ignored issues
–
show
|
|||||||||
135 | 'email' => $email, |
||||||||
136 | 'updated_at' => $user->updated_at, |
||||||||
0 ignored issues
–
show
|
|||||||||
137 | ] |
||||||||
138 | ); |
||||||||
139 | } |
||||||||
140 | } |
||||||||
141 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths