GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 83af07...e40910 )
by Freek
02:00
created

CookieConsentMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\CookieConsent;
4
5
use Closure;
6
use Illuminate\Http\Response;
7
use Illuminate\Contracts\Foundation\Application;
8
9
class CookieConsentMiddleware
10
{
11
    /**
12
     * The application implementation.
13
     *
14
     * @var \Illuminate\Contracts\Foundation\Application
15
     */
16
    protected $app;
17
18
    /**
19
     * Create a new middleware instance.
20
     *
21
     * @param  \Illuminate\Contracts\Foundation\Application $app
22
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
23
     */
24
    public function __construct(Application $app)
25
    {
26
        $this->app = $app;
27
    }
28
29
    /**
30
     * Handle an incoming request.
31
     *
32
     * @param  \Illuminate\Http\Request $request
33
     * @param  \Closure $next
34
     * @return mixed
35
     *
36
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
37
     */
38
    public function handle($request, Closure $next)
39
    {
40
        $response = $next($request);
41
42
        if ($response instanceof Response) {
43
            $content = $response->getContent();
44
45
            $cookieConsentHTML = view('cookieConsent::index')->render();
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
46
47
            if (($bodyPosition = strripos($content, '</body>')) !== false) {
48
                $content = ''
49
                    .substr($content, 0, $bodyPosition)
50
                    .$cookieConsentHTML
51
                    .substr($content, $bodyPosition);
52
            }
53
54
            $response->setContent($content);
55
        }
56
57
        return $response;
58
    }
59
}
60