Skip to content

Commit 0d27fbb

Browse files
committed
chore: fix phpstan
1 parent b95cc21 commit 0d27fbb

19 files changed

+59
-51
lines changed

examples/captures/create-capture.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* How to prepare a new payment with the Mollie API.
55
*/
66

7-
use Mollie\Api\Http\Data\CreatePaymentCapturePayload;
87
use Mollie\Api\Http\Data\Money;
98
use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest;
109

@@ -22,10 +21,11 @@
2221
* description Description of the capture.
2322
* metadata Custom metadata that is stored with the payment.
2423
*/
25-
$response = $mollie->send(new CreatePaymentCaptureRequest('tr_WDqYK6vllg', new CreatePaymentCapturePayload(
24+
$response = $mollie->send(new CreatePaymentCaptureRequest(
25+
'tr_WDqYK6vllg',
2626
'Order #12345',
2727
new Money('EUR', '5.00')
28-
)));
28+
));
2929

3030
$capture = $response->toResource();
3131

examples/client-links/create-client-link.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/*
44
* How to create a new client link in the Mollie API.
55
*/
6-
76
use Mollie\Api\Http\Data\CreateClientLinkPayload;
87
use Mollie\Api\Http\Data\Owner;
98
use Mollie\Api\Http\Data\OwnerAddress;
@@ -29,13 +28,13 @@
2928
*/
3029
$response = $mollie
3130
->send(
32-
new CreateClientLinkRequest(new CreateClientLinkPayload(
31+
new CreateClientLinkRequest(
3332
new Owner('[email protected]', 'foo', 'bar', 'nl_NL'),
3433
'Foo Company',
3534
new OwnerAddress('NL', 'Keizersgracht 313', '1016 EE', 'Amsterdam'),
3635
'30204462',
3736
'NL123456789B01',
38-
))
37+
)
3938
);
4039

4140
$clientLink = $response->toResource();

examples/customers/create-customer-first-payment.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
* How to create a first payment to allow recurring payments later.
55
*/
66

7-
use Mollie\Api\Factories\CreatePaymentRequestFactory;
87
use Mollie\Api\Http\Data\Metadata;
98
use Mollie\Api\Http\Data\Money;
109
use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest;
1110
use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest;
12-
use Mollie\Api\Types\SequenceType;
1311

1412
try {
1513
/*
@@ -40,19 +38,17 @@
4038
*
4139
* @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
4240
*/
43-
$payload = CreatePaymentRequestFactory::new([
44-
'description' => "First payment - Order #{$orderId}",
45-
'amount' => new Money('EUR', '10.00'),
46-
'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}",
47-
'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php",
48-
'metadata' => new Metadata([
49-
'order_id' => $orderId,
50-
]),
51-
'sequenceType' => SequenceType::FIRST,
52-
])->create();
53-
5441
$payment = $mollie->send(
55-
new CreateCustomerPaymentRequest($customer->id, $payload)
42+
new CreateCustomerPaymentRequest(
43+
$customer->id,
44+
"First payment - Order #{$orderId}",
45+
new Money('EUR', '10.00'),
46+
"{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}",
47+
"{$protocol}://{$hostname}/payments/webhook.php",
48+
new Metadata([
49+
'order_id' => $orderId,
50+
])
51+
)
5652
);
5753

5854
/*

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ parameters:
270270
count: 1
271271
path: examples/subscriptions/update-subscription.php
272272

273+
-
274+
message: '#^Unsafe usage of new static\(\)\.$#'
275+
identifier: new.static
276+
count: 1
277+
path: src/Factories/Factory.php
278+
273279
-
274280
message: '#^Unsafe usage of new static\(\)\.$#'
275281
identifier: new.static

src/Contracts/Connector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract, Testable
99
{
10-
public function send(Request $request): ?object;
10+
/**
11+
* @return mixed
12+
*/
13+
public function send(Request $request);
1114

1215
public function resolveBaseUrl(): string;
1316

src/EndpointCollection/InvoiceEndpointCollection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter
6161
])
6262
->create();
6363

64-
/** @var InvoiceCollection */
6564
return $this->send(
6665
$request
6766
->useIterator()

src/EndpointCollection/PaymentRefundEndpointCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function createFor(Payment $payment, array $data, $testmode = false): Ref
3535
*/
3636
public function createForId(string $paymentId, array $payload = [], $testmode = false): Refund
3737
{
38-
$testmode = Utility::extractBool($payload, 'testmode', false) ??
38+
$testmode = Utility::extractBool($payload, 'testmode', false) ?:
3939
Utility::extractBool($testmode, 'testmode', false);
4040

4141
$request = CreatePaymentRefundRequestFactory::new($paymentId)

src/EndpointCollection/SessionEndpointCollection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Mollie\Api\Exceptions\RequestException;
66
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
7-
use Mollie\Api\Http\Data\AnyData;
87
use Mollie\Api\Http\Requests\CancelSessionRequest;
98
use Mollie\Api\Http\Requests\CreateSessionRequest;
109
use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest;
@@ -53,11 +52,11 @@ public function create(array $payload = [], array $query = []): Session
5352
*
5453
* Will throw a ApiException if the session id is invalid or the resource cannot be found.
5554
*
56-
* @param array|AnyData $payload
55+
* @param array $payload
5756
*
5857
* @throws RequestException
5958
*/
60-
public function update(string $id, $payload = []): Session
59+
public function update(string $id, array $payload = []): Session
6160
{
6261
$request = new UpdateSessionRequest($id);
6362

src/Factories/CreateCustomerPaymentRequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function create(): CreateCustomerPaymentRequest
5050
$this->payload('sequenceType'),
5151
$this->payload('mandateId'),
5252
$this->payload('profileId'),
53-
$this->payload('additional') ?? Utility::filterByProperties(CreateCustomerPaymentRequest::class, $this->payload()) ?? [],
53+
$this->payload('additional') ?: Utility::filterByProperties(CreateCustomerPaymentRequest::class, $this->payload()) ?: [],
5454
$this->query('includeQrCode', false)
5555
);
5656
}

src/Factories/CreatePaymentRequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function create(): CreatePaymentRequest
4343
$this->payload('mandateId'),
4444
$this->payload('customerId'),
4545
$this->payload('profileId'),
46-
$this->payload('additional') ?? Utility::filterByProperties(CreatePaymentRequest::class, $this->payload()) ?? [],
46+
$this->payload('additional') ?: Utility::filterByProperties(CreatePaymentRequest::class, $this->payload()) ?: [],
4747
$this->query('includeQrCode', false)
4848
);
4949
}

src/Factories/Factory.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public function __construct($data = null)
1919
}
2020
}
2121

22-
public static function new(...$args): self
22+
/**
23+
* @return static
24+
*/
25+
public static function new(...$args)
2326
{
2427
return new static(...$args);
2528
}
@@ -37,7 +40,7 @@ protected function get($key = null, $default = null, $data = null, $backupKey =
3740
$keys = (array) $key;
3841

3942
if (empty($keys)) {
40-
return $data ?? $default;
43+
return empty($data) ? $default : $data;
4144
}
4245

4346
if ($backupKey !== null) {
@@ -71,8 +74,8 @@ protected function includes($key, $value, $data = null, $backupKey = 'filters.')
7174
* Map a value to a new form if it is not null.
7275
*
7376
* @param string|array<string> $key The key to retrieve the value from the data array.
74-
* @param callable|string $composable A callable function to transform the value, or the name of a class to instantiate.
75-
* @param string $backupKey The key to retrieve the value from the data array if the first key is null.
77+
* @param callable|string $resolver A callable function to transform the value, or the name of a class to instantiate.
78+
* @param string $composableClass The class to instantiate if the resolver is a string.
7679
* @return mixed The transformed value, a new class instance, or null if the value is null.
7780
*/
7881
protected function transformIfNotNull($key, $resolver, $composableClass = null)

src/Factories/RequestFactory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ abstract class RequestFactory extends Factory
1010

1111
private array $query = [];
1212

13-
public function withPayload(array $payload): self
13+
/**
14+
* @return static
15+
*/
16+
public function withPayload(array $payload)
1417
{
1518
$this->payload = $payload;
1619

1720
return $this;
1821
}
1922

20-
public function withQuery(array $query): self
23+
/**
24+
* @return static
25+
*/
26+
public function withQuery(array $query)
2127
{
2228
$this->query = $query;
2329

src/Factories/SortablePaginatedQueryFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
class SortablePaginatedQueryFactory extends RequestFactory
88
{
9-
public static function new(...$args): self
10-
{
11-
return new static(...$args);
12-
}
13-
149
public function create(): SortablePaginatedQuery
1510
{
1611
return new SortablePaginatedQuery(

src/Http/Requests/CreatePaymentRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Mollie\Api\Http\Data\DataCollection;
1010
use Mollie\Api\Http\Data\Metadata;
1111
use Mollie\Api\Http\Data\Money;
12+
use Mollie\Api\Http\Data\OrderLine;
13+
use Mollie\Api\Http\Data\PaymentRoute;
1214
use Mollie\Api\Resources\Payment;
1315
use Mollie\Api\Traits\HasJsonPayload;
1416
use Mollie\Api\Types\Method;

src/Http/Requests/CreateSubscriptionRequest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Mollie\Api\Contracts\HasPayload;
77
use Mollie\Api\Contracts\SupportsTestmodeInPayload;
88
use Mollie\Api\Http\Data\ApplicationFee;
9-
use Mollie\Api\Http\Data\CreateSubscriptionPayload;
109
use Mollie\Api\Http\Data\Metadata;
1110
use Mollie\Api\Http\Data\Money;
1211
use Mollie\Api\Resources\Subscription;
@@ -53,8 +52,6 @@ class CreateSubscriptionRequest extends ResourceHydratableRequest implements Has
5352

5453
private ?string $profileId;
5554

56-
private CreateSubscriptionPayload $payload;
57-
5855
public function __construct(
5956
string $customerId,
6057
Money $amount,

src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement
2020

2121
private string $subscriptionId;
2222

23-
public function __construct(string $customerId, string $subscriptionId, ?string $from = null, ?string $limit = null)
23+
public function __construct(string $customerId, string $subscriptionId, ?string $from = null, ?int $limit = null)
2424
{
2525
$this->customerId = $customerId;
2626
$this->subscriptionId = $subscriptionId;

src/Http/Requests/GetPaginatedSubscriptionsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte
1818

1919
private string $customerId;
2020

21-
public function __construct(string $customerId, ?string $limit = null, ?string $from = null)
21+
public function __construct(string $customerId, ?string $from = null, ?int $limit = null)
2222
{
2323
$this->customerId = $customerId;
2424

src/Resources/Payment.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,15 @@ public function refund($data): Refund
708708
/**
709709
* @throws \Mollie\Api\Exceptions\ApiException
710710
*/
711-
public function update(): ?Payment
711+
public function update(): Payment
712712
{
713713
$additional = [];
714714
if ($this->method === PaymentMethod::BANKTRANSFER) {
715715
$additional['dueDate'] = $this->dueDate;
716716
}
717717

718-
$payload = new UpdatePaymentPayload(
718+
$updateRequest = (new UpdatePaymentRequest(
719+
$this->id,
719720
$this->description,
720721
$this->redirectUrl,
721722
$this->cancelUrl,
@@ -725,11 +726,12 @@ public function update(): ?Payment
725726
$this->locale,
726727
$this->restrictPaymentMethodsToCountry,
727728
$additional
728-
);
729+
))->test($this->isInTestmode());
729730

731+
/** @var null|Payment */
730732
return $this
731733
->connector
732-
->send((new UpdatePaymentRequest($this->id, $payload))->test($this->isInTestmode()));
734+
->send($updateRequest);
733735
}
734736

735737
/**

tests/Http/Requests/UpdateSessionRequestTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public function it_can_update_session()
1717
UpdateSessionRequest::class => MockResponse::ok('session'),
1818
]);
1919

20-
$request = new UpdateSessionRequest('ses_LQNz4v4Qvk', [
20+
$request = new UpdateSessionRequest('ses_LQNz4v4Qvk');
21+
22+
$request->payload()->set([
2123
'status' => 'completed',
2224
'metadata' => [
2325
'order_id' => '12345',
@@ -36,8 +38,7 @@ public function it_can_update_session()
3638
/** @test */
3739
public function it_resolves_correct_resource_path()
3840
{
39-
$sessionId = 'ses_LQNz4v4Qvk';
40-
$request = new UpdateSessionRequest($sessionId, []);
41+
$request = new UpdateSessionRequest($sessionId = 'ses_LQNz4v4Qvk');
4142

4243
$this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath());
4344
}

0 commit comments

Comments
 (0)