TrackOpensController::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\EmailCampaigns\Http\Controllers;
4
5
use Spatie\EmailCampaigns\Support\WebBeacon;
6
use Spatie\EmailCampaigns\Jobs\RegisterOpenJob;
7
8
class TrackOpensController
9
{
10
    public function __invoke(string $campaignSendUuid)
11
    {
12
        if (! is_null($campaignSendUuid)) {
13
            dispatch(new RegisterOpenJob($campaignSendUuid));
14
        }
15
16
        $webBeaconContent = WebBeacon::content();
17
18
        return response($webBeaconContent)->withHeaders([
0 ignored issues
show
Bug introduced by
The method withHeaders does only exist in Illuminate\Http\Response, but not in Illuminate\Contracts\Routing\ResponseFactory.

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...
19
            'Content-type' => 'image/gif',
20
            'Content-Length' => strlen($webBeaconContent),
21
            'Cache-Control' => 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate',
22
            'Expires' => 'Wed, 11 Jan 2000 12:59:00 GMT',
23
            'Last-Modified' => 'Wed, 11 Jan 2006 12:59:00 GMT',
24
            'Pragma' => 'no-cache',
25
        ]);
26
    }
27
}
28