Skip to content

Commit

Permalink
chore: fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Feb 5, 2025
1 parent b95cc21 commit 0d27fbb
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 51 deletions.
6 changes: 3 additions & 3 deletions examples/captures/create-capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* How to prepare a new payment with the Mollie API.
*/

use Mollie\Api\Http\Data\CreatePaymentCapturePayload;
use Mollie\Api\Http\Data\Money;
use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest;

Expand All @@ -22,10 +21,11 @@
* description Description of the capture.
* metadata Custom metadata that is stored with the payment.
*/
$response = $mollie->send(new CreatePaymentCaptureRequest('tr_WDqYK6vllg', new CreatePaymentCapturePayload(
$response = $mollie->send(new CreatePaymentCaptureRequest(
'tr_WDqYK6vllg',
'Order #12345',
new Money('EUR', '5.00')
)));
));

$capture = $response->toResource();

Expand Down
5 changes: 2 additions & 3 deletions examples/client-links/create-client-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/*
* How to create a new client link in the Mollie API.
*/

use Mollie\Api\Http\Data\CreateClientLinkPayload;
use Mollie\Api\Http\Data\Owner;
use Mollie\Api\Http\Data\OwnerAddress;
Expand All @@ -29,13 +28,13 @@
*/
$response = $mollie
->send(
new CreateClientLinkRequest(new CreateClientLinkPayload(
new CreateClientLinkRequest(
new Owner('[email protected]', 'foo', 'bar', 'nl_NL'),
'Foo Company',
new OwnerAddress('NL', 'Keizersgracht 313', '1016 EE', 'Amsterdam'),
'30204462',
'NL123456789B01',
))
)
);

$clientLink = $response->toResource();
Expand Down
24 changes: 10 additions & 14 deletions examples/customers/create-customer-first-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* How to create a first payment to allow recurring payments later.
*/

use Mollie\Api\Factories\CreatePaymentRequestFactory;
use Mollie\Api\Http\Data\Metadata;
use Mollie\Api\Http\Data\Money;
use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest;
use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest;
use Mollie\Api\Types\SequenceType;

try {
/*
Expand Down Expand Up @@ -40,19 +38,17 @@
*
* @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
*/
$payload = CreatePaymentRequestFactory::new([
'description' => "First payment - Order #{$orderId}",
'amount' => new Money('EUR', '10.00'),
'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}",
'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php",
'metadata' => new Metadata([
'order_id' => $orderId,
]),
'sequenceType' => SequenceType::FIRST,
])->create();

$payment = $mollie->send(
new CreateCustomerPaymentRequest($customer->id, $payload)
new CreateCustomerPaymentRequest(
$customer->id,
"First payment - Order #{$orderId}",
new Money('EUR', '10.00'),
"{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}",
"{$protocol}://{$hostname}/payments/webhook.php",
new Metadata([
'order_id' => $orderId,
])
)
);

/*
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ parameters:
count: 1
path: examples/subscriptions/update-subscription.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: src/Factories/Factory.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
Expand Down
5 changes: 4 additions & 1 deletion src/Contracts/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract, Testable
{
public function send(Request $request): ?object;
/**
* @return mixed
*/
public function send(Request $request);

public function resolveBaseUrl(): string;

Expand Down
1 change: 0 additions & 1 deletion src/EndpointCollection/InvoiceEndpointCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter
])
->create();

/** @var InvoiceCollection */
return $this->send(
$request
->useIterator()
Expand Down
2 changes: 1 addition & 1 deletion src/EndpointCollection/PaymentRefundEndpointCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function createFor(Payment $payment, array $data, $testmode = false): Ref
*/
public function createForId(string $paymentId, array $payload = [], $testmode = false): Refund
{
$testmode = Utility::extractBool($payload, 'testmode', false) ??
$testmode = Utility::extractBool($payload, 'testmode', false) ?:
Utility::extractBool($testmode, 'testmode', false);

$request = CreatePaymentRefundRequestFactory::new($paymentId)
Expand Down
5 changes: 2 additions & 3 deletions src/EndpointCollection/SessionEndpointCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Http\Data\AnyData;
use Mollie\Api\Http\Requests\CancelSessionRequest;
use Mollie\Api\Http\Requests\CreateSessionRequest;
use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest;
Expand Down Expand Up @@ -53,11 +52,11 @@ public function create(array $payload = [], array $query = []): Session
*
* Will throw a ApiException if the session id is invalid or the resource cannot be found.
*
* @param array|AnyData $payload
* @param array $payload
*
* @throws RequestException
*/
public function update(string $id, $payload = []): Session
public function update(string $id, array $payload = []): Session
{
$request = new UpdateSessionRequest($id);

Expand Down
2 changes: 1 addition & 1 deletion src/Factories/CreateCustomerPaymentRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function create(): CreateCustomerPaymentRequest
$this->payload('sequenceType'),
$this->payload('mandateId'),
$this->payload('profileId'),
$this->payload('additional') ?? Utility::filterByProperties(CreateCustomerPaymentRequest::class, $this->payload()) ?? [],
$this->payload('additional') ?: Utility::filterByProperties(CreateCustomerPaymentRequest::class, $this->payload()) ?: [],
$this->query('includeQrCode', false)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/CreatePaymentRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function create(): CreatePaymentRequest
$this->payload('mandateId'),
$this->payload('customerId'),
$this->payload('profileId'),
$this->payload('additional') ?? Utility::filterByProperties(CreatePaymentRequest::class, $this->payload()) ?? [],
$this->payload('additional') ?: Utility::filterByProperties(CreatePaymentRequest::class, $this->payload()) ?: [],
$this->query('includeQrCode', false)
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function __construct($data = null)
}
}

public static function new(...$args): self
/**
* @return static
*/
public static function new(...$args)
{
return new static(...$args);
}
Expand All @@ -37,7 +40,7 @@ protected function get($key = null, $default = null, $data = null, $backupKey =
$keys = (array) $key;

if (empty($keys)) {
return $data ?? $default;
return empty($data) ? $default : $data;
}

if ($backupKey !== null) {
Expand Down Expand Up @@ -71,8 +74,8 @@ protected function includes($key, $value, $data = null, $backupKey = 'filters.')
* Map a value to a new form if it is not null.
*
* @param string|array<string> $key The key to retrieve the value from the data array.
* @param callable|string $composable A callable function to transform the value, or the name of a class to instantiate.
* @param string $backupKey The key to retrieve the value from the data array if the first key is null.
* @param callable|string $resolver A callable function to transform the value, or the name of a class to instantiate.
* @param string $composableClass The class to instantiate if the resolver is a string.
* @return mixed The transformed value, a new class instance, or null if the value is null.
*/
protected function transformIfNotNull($key, $resolver, $composableClass = null)
Expand Down
10 changes: 8 additions & 2 deletions src/Factories/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ abstract class RequestFactory extends Factory

private array $query = [];

public function withPayload(array $payload): self
/**
* @return static
*/
public function withPayload(array $payload)
{
$this->payload = $payload;

return $this;
}

public function withQuery(array $query): self
/**
* @return static
*/
public function withQuery(array $query)
{
$this->query = $query;

Expand Down
5 changes: 0 additions & 5 deletions src/Factories/SortablePaginatedQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

class SortablePaginatedQueryFactory extends RequestFactory
{
public static function new(...$args): self
{
return new static(...$args);
}

public function create(): SortablePaginatedQuery
{
return new SortablePaginatedQuery(
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Requests/CreatePaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Mollie\Api\Http\Data\DataCollection;
use Mollie\Api\Http\Data\Metadata;
use Mollie\Api\Http\Data\Money;
use Mollie\Api\Http\Data\OrderLine;
use Mollie\Api\Http\Data\PaymentRoute;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Traits\HasJsonPayload;
use Mollie\Api\Types\Method;
Expand Down
3 changes: 0 additions & 3 deletions src/Http/Requests/CreateSubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Mollie\Api\Contracts\HasPayload;
use Mollie\Api\Contracts\SupportsTestmodeInPayload;
use Mollie\Api\Http\Data\ApplicationFee;
use Mollie\Api\Http\Data\CreateSubscriptionPayload;
use Mollie\Api\Http\Data\Metadata;
use Mollie\Api\Http\Data\Money;
use Mollie\Api\Resources\Subscription;
Expand Down Expand Up @@ -53,8 +52,6 @@ class CreateSubscriptionRequest extends ResourceHydratableRequest implements Has

private ?string $profileId;

private CreateSubscriptionPayload $payload;

public function __construct(
string $customerId,
Money $amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement

private string $subscriptionId;

public function __construct(string $customerId, string $subscriptionId, ?string $from = null, ?string $limit = null)
public function __construct(string $customerId, string $subscriptionId, ?string $from = null, ?int $limit = null)
{
$this->customerId = $customerId;
$this->subscriptionId = $subscriptionId;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/GetPaginatedSubscriptionsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte

private string $customerId;

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

Expand Down
10 changes: 6 additions & 4 deletions src/Resources/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,15 @@ public function refund($data): Refund
/**
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update(): ?Payment
public function update(): Payment
{
$additional = [];
if ($this->method === PaymentMethod::BANKTRANSFER) {
$additional['dueDate'] = $this->dueDate;
}

$payload = new UpdatePaymentPayload(
$updateRequest = (new UpdatePaymentRequest(
$this->id,
$this->description,
$this->redirectUrl,
$this->cancelUrl,
Expand All @@ -725,11 +726,12 @@ public function update(): ?Payment
$this->locale,
$this->restrictPaymentMethodsToCountry,
$additional
);
))->test($this->isInTestmode());

/** @var null|Payment */
return $this
->connector
->send((new UpdatePaymentRequest($this->id, $payload))->test($this->isInTestmode()));
->send($updateRequest);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/Http/Requests/UpdateSessionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function it_can_update_session()
UpdateSessionRequest::class => MockResponse::ok('session'),
]);

$request = new UpdateSessionRequest('ses_LQNz4v4Qvk', [
$request = new UpdateSessionRequest('ses_LQNz4v4Qvk');

$request->payload()->set([
'status' => 'completed',
'metadata' => [
'order_id' => '12345',
Expand All @@ -36,8 +38,7 @@ public function it_can_update_session()
/** @test */
public function it_resolves_correct_resource_path()
{
$sessionId = 'ses_LQNz4v4Qvk';
$request = new UpdateSessionRequest($sessionId, []);
$request = new UpdateSessionRequest($sessionId = 'ses_LQNz4v4Qvk');

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

0 comments on commit 0d27fbb

Please sign in to comment.