From 25aefc7b28afafd99a4fab69f5ddc64cc1a23c7f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 13:37:11 +0100 Subject: [PATCH] fix all phpstan errors, this time for sure :fire: --- composer.json | 2 +- phpstan-baseline.neon | 211 +++++++++++++----- src/Http/Adapter/CurlMollieHttpAdapter.php | 4 - src/MollieApiClient.php | 4 - src/Resources/Payment.php | 2 +- src/Traits/HasDefaultFactories.php | 2 +- .../Adapter/GuzzleMollieHttpAdapterTest.php | 1 - tests/Http/Middleware/GuardResponseTest.php | 3 - 8 files changed, 163 insertions(+), 66 deletions(-) diff --git a/composer.json b/composer.json index 81790c52..fb2fce4e 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.6" }, "suggest": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0bb3ae84..6bc67aa4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,246 +1,355 @@ parameters: ignoreErrors: - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/create-capture.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/get-capture.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/list-captures.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/client-links/create-client-link.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-first-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-recurring-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/delete-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/list-customer-payments.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/update-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/invoices/list-invoices.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/create-mandate.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/list-mandates.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/revoke-mandate.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/pagination/backwards.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/pagination/basic_usage.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payment-links/create-payment-link.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payment-links/list-payment-links.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/create-capturable-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/payments/create-ideal-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/payments/create-payment-oauth.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/create-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/list-methods.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/list-payments.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/refund-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/return.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/update-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/webhook.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/create-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/delete-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/list-profiles.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/update-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/cancel-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/create-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/list-sessions.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/update-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/settlements/list-settlements.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/cancel-subscription.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/create-subscription.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/update-subscription.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 1 path: src/CompatibilityChecker.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 1 path: src/Http/Payload/CreateRefundPaymentPayload.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 5 path: src/Http/Payload/DataCollection.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$_links\\.$#" + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/CustomerEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/MandateEndpointCollectionTest.php + + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$_links\.$#' + identifier: property.notFound + count: 1 + path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php + + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$description\.$#' + identifier: property.notFound count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$description\\.$#" + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$status\.$#' + identifier: property.notFound count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$status\\.$#" + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Unsafe access to private property Tests\\\\Fixtures\\\\MockResponse\\:\\:\\$factories through static\\:\\:\\.$#" - count: 4 + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/ProfileEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 2 + path: tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/SessionEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/SubscriptionEndpointCollectionTest.php + + - + message: '#^Unsafe access to private property Tests\\Fixtures\\MockResponse\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 path: tests/Fixtures/MockResponse.php - - message: "#^Unsafe access to private property Tests\\\\Http\\\\Adapter\\\\MockMollieHttpAdapter\\:\\:\\$factories through static\\:\\:\\.$#" - count: 4 + message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 path: tests/Http/Adapter/MockMollieHttpAdapter.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Http/Middleware/GuardResponseTest.php diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index dc394df3..8a0a1dd8 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -53,10 +53,6 @@ public function sendRequest(PendingRequest $pendingRequest): Response return $this->createResponse($pendingRequest, 504, [], null, $e); } } - - throw new CurlConnectTimeoutException( - 'Unable to connect to Mollie. Maximum number of retries ('.self::MAX_RETRIES.') reached.' - ); } protected function createResponse(PendingRequest $pendingRequest, int $statusCode, $headers = [], $body = null, ?Throwable $error = null): Response diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 77b75bbc..02747e76 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -19,8 +19,6 @@ use Mollie\Api\EndpointCollection\MethodEndpointCollection; use Mollie\Api\EndpointCollection\MethodIssuerEndpointCollection; use Mollie\Api\EndpointCollection\OnboardingEndpointCollection; -use Mollie\Api\EndpointCollection\OrderEndpointCollection; -use Mollie\Api\EndpointCollection\OrderShipmentEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationPartnerEndpointCollection; use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; @@ -73,7 +71,6 @@ * @property MethodEndpointCollection $methods * @property MethodIssuerEndpointCollection $methodIssuers * @property OnboardingEndpointCollection $onboarding - * @property OrderEndpointCollection $orders * @property OrganizationEndpointCollection $organizations * @property OrganizationPartnerEndpointCollection $organizationPartners * @property PaymentEndpointCollection $payments @@ -92,7 +89,6 @@ * @property SettlementChargebackEndpointCollection $settlementChargebacks * @property SettlementPaymentEndpointCollection $settlementPayments * @property SettlementRefundEndpointCollection $settlementRefunds - * @property OrderShipmentEndpointCollection $shipments * @property SubscriptionEndpointCollection $subscriptions * @property SubscriptionPaymentEndpointCollection $subscriptionPayments * @property TerminalEndpointCollection $terminals diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index f7934057..fa4f7e89 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -289,7 +289,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract /** * Used to restrict the payment methods available to your customer to those from a single country. * - * @var string|null; + * @var string|null */ public $restrictPaymentMethodsToCountry; diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php index cf2a4716..5dc03e21 100644 --- a/src/Traits/HasDefaultFactories.php +++ b/src/Traits/HasDefaultFactories.php @@ -11,7 +11,7 @@ trait HasDefaultFactories public function factories(): Factories { - if (isset(static::$factories) && static::$factories !== null) { + if (static::$factories) { return static::$factories; } diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index 0ef3d921..a3b93d31 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -20,7 +20,6 @@ class GuzzleMollieHttpAdapterTest extends TestCase public function test_debugging_is_supported() { $adapter = GuzzleMollieHttpAdapter::createDefault(); - $this->assertTrue($adapter instanceof SupportsDebuggingContract); $this->assertFalse($adapter->debuggingIsActive()); $adapter->enableDebugging(); diff --git a/tests/Http/Middleware/GuardResponseTest.php b/tests/Http/Middleware/GuardResponseTest.php index ed4b1ecf..148e4572 100644 --- a/tests/Http/Middleware/GuardResponseTest.php +++ b/tests/Http/Middleware/GuardResponseTest.php @@ -57,9 +57,6 @@ public function it_does_not_throw_exception_if_http_no_content(): void // No exception should be thrown $guardResponse($responseMock); - - // If the test reaches here without exceptions, it passes - $this->assertTrue(true); } /**