Completed
Push — master ( a76360...3b8ebd )
by Manuel
04:51 queued 03:32
created

IssueTokenController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
1
<?php
2
3
namespace Oscer\Cms\Api\Http\Controllers;
4
5
use Illuminate\Http\Exceptions\HttpResponseException;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Support\Facades\Hash;
8
use Oscer\Cms\Api\Http\Requests\IssueTokenRequest;
9
use Oscer\Cms\Core\Users\Models\User;
10
11
class IssueTokenController
12
{
13
    public function __invoke(IssueTokenRequest $request)
14
    {
15
        /** @var \Oscer\Cms\Core\Users\Models\User $user */
16
        $user = User::query()->where('email', $request->input('email'))->first();
17
18
        if (! $user || ! Hash::check($request->input('password'), $user->getAuthPassword())) {
19
            throw new HttpResponseException(response()->json([
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
20
                'errors' => [
21
                    'email' => ['The provided credentials are incorrect.'],
22
                ],
23
            ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY));
24
        }
25
26
        return response()->json(['token' => $user->createToken('admin_ui')->plainTextToken], 201);
27
    }
28
}
29