Completed
Push — development ( b0aa59...26b42c )
by Claudio
02:36
created

ClientController::getInterstitial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Response;
7
use Illuminate\Support\Facades\Config;
8
use Laravel\Lumen\Routing\Controller as BaseController;
9
10
/**
11
 * Class ClientController
12
 * @package App\Http\Controllers
13
 */
14
class ClientController extends BaseController
15
{
16
    /**
17
     * Returns the Client URL
18
     *
19
     * @param Request $request
20
     * @return Response
21
     */
22
    public function getUrl(Request $request)
23
    {
24
        $hotelUrl = Config::get('chocolatey.url');
25
26
        $accountType = in_array('NEW_USER', $request->user()->traits)
27
            ? 'habbo-client-new-user' : 'habbo-client-user';
28
29
        return response()->json(['clienturl' => "{$hotelUrl}client/{$accountType}"],
0 ignored issues
show
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...
30
            200, [], JSON_UNESCAPED_SLASHES);
31
    }
32
33
    /**
34
     * Get HabboWEB Ads Interstitial
35
     *
36
     * @param string $interstitialType
37
     * @return Response
38
     */
39
    public function getInterstitial(string $interstitialType): Response
0 ignored issues
show
Unused Code introduced by
The parameter $interstitialType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        return response(view('habbo-web-ads.interstitial'));
42
    }
43
}
44