Completed
Push — master ( 16ed10...af0efe )
by Freek
01:45
created

StripeWebhooksController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\StripeWebhooks;
4
5
use Illuminate\Http\Request;
6
use Spatie\WebhookClient\Models\WebhookCall;
7
use Spatie\WebhookClient\WebhookConfig;
8
use Spatie\WebhookClient\WebhookProcessor;
9
use Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile;
10
11
class StripeWebhooksController
12
{
13
    public function __invoke(Request $request, string $configKey = null)
14
    {
15
        $webhookConfig = new WebhookConfig([
16
            'name' => 'stripe',
17
            'signing_secret' => ($configKey) ?
18
                config('stripe-webhooks.signing_secret_'.$configKey) :
19
                config('stripe-webhooks.signing_secret'),
20
            'signature_header_name' => 'Stripe-Signature',
21
            'signature_validator' => StripeSignatureValidator::class,
22
            'webhook_profile' => ProcessEverythingWebhookProfile::class,
23
            'webhook_model' => WebhookCall::class,
24
            'process_webhook_job' => config('stripe-webhooks.model'),
25
        ]);
26
27
        (new WebhookProcessor($request, $webhookConfig))->process();
28
29
        return response()->json(['message' => 'ok']);
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...
30
    }
31
}
32