Skip to content

V3 typing #789

@bobvandevijver

Description

@bobvandevijver

First of all, thanks for the new release!

I'm confused by the new typing introduced with V3 as it seems to be incomplete. Lets take a look at the following snippet (I will use the create payment endpoint for the rest of this description):

$typedPaymentObject = $mollieApiClient->payments->create([...]); // 2.x
$mixedObject = $mollieApiClient->send(new CreatePaymentRequest(...)); // 3.x

The first one is from V2, where you passed an untyped array of properties, but you did get back a typed object for further processing. The latter one, documented as the new typed method, returns a mixed object where the developer needs to explicitly add an annotation with the returned type. From my view both methods are partially untyped, but you can argue that with the request payload now being typed most the bulk is typed.

The v2 method uses a factory to create the CreatePaymentRequest based on the passed array and forwards it to the connector; wouldn't it be nice to be able to pass the CreatePaymentRequest object directly to that method to be able to get a fully typed interface, like in the following example? This would be a BC-break as the method signatures need to be adjusted.

$typedPaymentObject = $mollieApiClient->payments->create(new CreatePaymentRequest(...));

Or, maybe even better, why not a typed send method to the request object? This can be done with BC-break.

$typedPaymentObject = new CreatePaymentRequest(...)->send($mollieApiClient);

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions