WebhookController::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fenerum\Webhooks\Http\Controllers;
6
7
use Fenerum\Webhooks\Http\Requests\WebhookRequest;
8
use Fenerum\Webhooks\WebhookProcessor;
9
10
class WebhookController
11
{
12
    /**
13
     * @param \Fenerum\Webhooks\Http\Requests\WebhookRequest $request
14
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
15
     */
16
    public function handle(WebhookRequest $request)
17
    {
18
        $result = WebhookProcessor::handle($request->input('event'), $request->input('data'));
19
        if ($result) {
20
            return response()->json('OK', 200);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\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...
21
        }
22
23
        return response()->json(['error' => 'Webhook not found'], 404);
24
    }
25
}
26