NuxController::selectName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Facades\Nux;
6
use App\Facades\User as UserFacade;
7
use App\Facades\Validation;
8
use App\Models\NuxValidation;
9
use App\Models\User;
10
use Illuminate\Http\JsonResponse;
11
use Illuminate\Http\Request;
12
use Illuminate\Http\Response;
13
use Laravel\Lumen\Routing\Controller as BaseController;
14
15
/**
16
 * Class NuxController.
17
 */
18
class NuxController extends BaseController
19
{
20
    /**
21
     * Check an User Name.
22
     *
23
     * @param Request $request
24
     *
25
     * @return JsonResponse
26
     */
27
    public function checkName(Request $request): JsonResponse
28
    {
29
        if (User::where('username', $request->json()->get('name'))->where('id', '<>', UserFacade::getUser()->uniqueId)->count() > 0) {
30
            return response()->json(new NuxValidation('NAME_IN_USE'));
0 ignored issues
show
Documentation introduced by
new \App\Models\NuxValidation('NAME_IN_USE') is of type object<App\Models\NuxValidation>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
The method json does only exist in Laravel\Lumen\Http\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...
31
        }
32
33
        if (!Validation::filterUserName($request->json()->get('name'))) {
34
            return response()->json(new NuxValidation('INVALID_NAME', ['resultType' => 'VALIDATION_ERROR_ILLEGAL_WORDS']));
0 ignored issues
show
Documentation introduced by
new \App\Models\NuxValid..._ERROR_ILLEGAL_WORDS')) is of type object<App\Models\NuxValidation>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
        }
36
37
        return response()->json(new NuxValidation());
0 ignored issues
show
Documentation introduced by
new \App\Models\NuxValidation() is of type object<App\Models\NuxValidation>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
40
    /**
41
     * Select an User Name.
42
     *
43
     * @param Request $request
44
     *
45
     * @return JsonResponse
46
     */
47
    public function selectName(Request $request): JsonResponse
48
    {
49
        UserFacade::updateSession(['username' => $request->json()->get('name')]);
50
51
        return response()->json(new NuxValidation());
0 ignored issues
show
Documentation introduced by
new \App\Models\NuxValidation() is of type object<App\Models\NuxValidation>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
The method json does only exist in Laravel\Lumen\Http\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...
52
    }
53
54
    /**
55
     * Select a Room.
56
     *
57
     * @param Request $request
58
     *
59
     * @return Response
60
     */
61
    public function selectRoom(Request $request): Response
62
    {
63
        if (!in_array($request->json()->get('roomIndex'), [1, 2, 3])) {
64
            return response('', 400);
65
        }
66
67
        Nux::generateRoom($request);
68
69
        UserFacade::getUser()->traits = ['USER'];
70
71
        return response(null, 200);
72
    }
73
}
74