Completed
Push — master ( d7dffa...54ccfb )
by Zhengchao
07:51
created

CheckReferral   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
1
<?php
2
3
/*
4
 * This file is part of questocat/laravel-referral package.
5
 *
6
 * (c) questocat <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Questocat\Referral\Http\Middleware;
13
14
use Closure;
15
16
class CheckReferral
17
{
18
    public function handle($request, Closure $next)
19
    {
20
        if ($request->hasCookie('referral')) {
21
            return $next($request);
22
        }
23
24
        if (($ref = $request->query('ref')) && app(config('referral.user_model', 'App\User'))->referralExists($ref)) {
25
            return redirect($request->fullUrl())->withCookie(cookie()->forever('referral', $ref));
0 ignored issues
show
Bug introduced by
The method forever does only exist in Illuminate\Cookie\CookieJar, but not in Symfony\Component\HttpFoundation\Cookie.

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...
26
        }
27
28
        return $next($request);
29
    }
30
}
31