Execution works fine, but static analysis tools such as PHPStan complain about the variable type when a custom Model is used to decode the JSON payload into an object instead of an array.
This results in static analysis errors in the ProcessWebhookJob::handle() method because the Spatie ProcessWebhookJob class hard-codes the type of the Model in the constructor:
public function __construct(
public WebhookCall $webhookCall
) {
}
For example, the errors I get from PHPStan for my particular implementation of the WebhookCall Model and the ProcessWebhookJob class look like these:
------ -----------------------------------------------------------------------
Line MyApp/Jobs/MyWebhookJob.php
------ -----------------------------------------------------------------------
28 Cannot access property $type on array.
56 Parameter #1 $payload of callable
Domain\MyApp\ShipmentCreatedAction|Domain\MyApp\ShipmentLegDeli
veryAction expects object, array|null given.
------ -----------------------------------------------------------------------
One possible solution might be declare an interface as the type hint for the constructor to the base ProcessWebhookJob class, and have the Model implement it. There may be other, better solutions.
Execution works fine, but static analysis tools such as PHPStan complain about the variable type when a custom Model is used to decode the JSON payload into an object instead of an array.
The custom
MyWebhookCall
Model contains:Instead of the package
WebhookCall
Model which reads:This results in static analysis errors in the
ProcessWebhookJob::handle()
method because the SpatieProcessWebhookJob
class hard-codes the type of the Model in the constructor:For example, the errors I get from PHPStan for my particular implementation of the
WebhookCall
Model and theProcessWebhookJob
class look like these:One possible solution might be declare an
interface
as the type hint for the constructor to the baseProcessWebhookJob
class, and have the Model implement it. There may be other, better solutions.