From 356dbb67fb3bc979f37d012c00a6f45d670bd0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Fri, 28 Oct 2022 19:13:44 +0000 Subject: [PATCH] Improve PHPStan usage --- composer.json | 3 +- composer.lock | 112 ++++++++++++------ phpstan.neon.dist | 36 ++---- .../Plugins/PaymentGateways/PayPal.php | 2 + 4 files changed, 94 insertions(+), 59 deletions(-) diff --git a/composer.json b/composer.json index b946654..6d9295c 100644 --- a/composer.json +++ b/composer.json @@ -43,9 +43,10 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "friendsofphp/php-cs-fixer": "^3.12", + "php-stubs/woocommerce-stubs": ">=4.3", "phpcompatibility/phpcompatibility-wp": "^2.0", "phpmd/phpmd": "^2.13", - "szepeviktor/phpstan-wordpress": "^0.7", + "szepeviktor/phpstan-wordpress": "^1.0", "wp-coding-standards/wpcs": "^2.1", "wpackagist-plugin/woocommerce": ">=4.3", "wpackagist-plugin/woocommerce-gateway-stripe": "6.4.1", diff --git a/composer.lock b/composer.lock index 66f9f40..f667553 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b5ca5b6272c973d9e4f3d979fa0c169e", + "content-hash": "45c1cb151b5ed86f1c36c96a3b185bc5", "packages": [ { "name": "composer/installers", @@ -894,18 +894,62 @@ ], "time": "2022-09-08T19:30:37+00:00" }, + { + "name": "php-stubs/woocommerce-stubs", + "version": "v7.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/woocommerce-stubs.git", + "reference": "2bbe0ba67081cfad17d33ac503883fdc6e68a386" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/2bbe0ba67081cfad17d33ac503883fdc6e68a386", + "reference": "2bbe0ba67081cfad17d33ac503883fdc6e68a386", + "shasum": "" + }, + "require": { + "php-stubs/wordpress-stubs": "^5.3 || ^6.0" + }, + "require-dev": { + "php": "~7.1 || ~8.0", + "php-stubs/generator": "^0.8.0" + }, + "suggest": { + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WooCommerce function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/woocommerce-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "woocommerce", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v7.0.0" + }, + "time": "2022-10-12T08:25:57+00:00" + }, { "name": "php-stubs/wordpress-stubs", - "version": "v5.9.4", + "version": "v6.0.2", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "3e481f4c8195fb3ca9e3e4e52e5305bf59c74cdb" + "reference": "165b84f082db851e76ec51bebcde550d03976893" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/3e481f4c8195fb3ca9e3e4e52e5305bf59c74cdb", - "reference": "3e481f4c8195fb3ca9e3e4e52e5305bf59c74cdb", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/165b84f082db851e76ec51bebcde550d03976893", + "reference": "165b84f082db851e76ec51bebcde550d03976893", "shasum": "" }, "replace": { @@ -937,9 +981,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v5.9.4" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.0.2" }, - "time": "2022-09-30T17:45:35+00:00" + "time": "2022-09-30T17:46:11+00:00" }, { "name": "phpcompatibility/php-compatibility", @@ -1198,20 +1242,20 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.99", + "version": "1.8.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7" + "reference": "46e223dd68a620da18855c23046ddb00940b4014" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", + "reference": "46e223dd68a620da18855c23046ddb00940b4014", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1221,11 +1265,6 @@ "phpstan.phar" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -1236,9 +1275,13 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.99" + "source": "https://github.com/phpstan/phpstan/tree/1.8.11" }, "funding": [ { @@ -1249,16 +1292,12 @@ "url": "https://github.com/phpstan", "type": "github" }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, { "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", "type": "tidelift" } ], - "time": "2021-09-12T20:09:55+00:00" + "time": "2022-10-24T15:45:13+00:00" }, { "name": "psr/cache", @@ -3035,29 +3074,30 @@ }, { "name": "szepeviktor/phpstan-wordpress", - "version": "v0.7.7", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/szepeviktor/phpstan-wordpress.git", - "reference": "bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72" + "reference": "e644df734e1bbe95810e0f617d17df091048a94e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72", - "reference": "bdbea69b2ba4a69998c3b6fe2b7106d78a23bd72", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/e644df734e1bbe95810e0f617d17df091048a94e", + "reference": "e644df734e1bbe95810e0f617d17df091048a94e", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", - "php-stubs/wordpress-stubs": "^4.7 || ^5.0", - "phpstan/phpstan": "^0.12.26", + "php": "^7.2 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", + "phpstan/phpstan": "^1.6", "symfony/polyfill-php73": "^1.12.0" }, "require-dev": { - "composer/composer": "^1.10.22", + "composer/composer": "^2.1.14", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.1", - "phpstan/phpstan-strict-rules": "^0.12", + "phpstan/phpstan-strict-rules": "^1.2", + "phpunit/phpunit": "^8 || ^9", "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.6" }, "type": "phpstan-extension", @@ -3087,15 +3127,19 @@ ], "support": { "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", - "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v0.7.7" + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.1.3" }, "funding": [ { "url": "https://www.paypal.me/szepeviktor", "type": "custom" + }, + { + "url": "https://github.com/szepeviktor", + "type": "github" } ], - "time": "2021-07-14T09:19:15+00:00" + "time": "2022-09-22T13:14:50+00:00" }, { "name": "wp-coding-standards/wpcs", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5da3924..674b6d4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,9 +2,7 @@ # https://phpstan.org/config-reference includes: - # @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon - - phar://phpstan.phar/conf/bleedingEdge.neon - # Include this extension + # Include extension for WordPress - wme-sitebuilder/vendor/szepeviktor/phpstan-wordpress/extension.neon parameters: @@ -13,38 +11,30 @@ parameters: # Define global constants. bootstrapFiles: - - %currentWorkingDirectory%/tests/phpstan-bootstrap.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/vendor/autoload.php + - tests/phpstan-bootstrap.php + - wme-sitebuilder/vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php + - wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-paypal-payments/vendor/autoload.php # Files that aren't autoloaded but should be considered. scanFiles: - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/includes/abstracts/abstract-wc-data.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/includes/abstracts/abstract-wc-product.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/includes/class-wc-customer.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/includes/legacy/abstract-wc-legacy-product.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce/includes/legacy/class-wc-legacy-customer.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-gateway-stripe/woocommerce-gateway-stripe.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-gateway-stripe/includes/connect/class-wc-stripe-connect.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-paypal-payments/modules/ppcp-button/src/Endpoint/EndpointInterface.php - - %currentWorkingDirectory%/wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-paypal-payments/modules/ppcp-onboarding/src/Endpoint/LoginSellerEndpoint.php + - wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-gateway-stripe/woocommerce-gateway-stripe.php + - wme-sitebuilder/vendor/wpackagist-plugin/woocommerce-gateway-stripe/includes/connect/class-wc-stripe-connect.php # Paths to be analyzed. paths: - - %currentWorkingDirectory%/wme-sitebuilder.php - - %currentWorkingDirectory%/wme-sitebuilder/ - excludes_analyse: - - %currentWorkingDirectory%/wme-sitebuilder/vendor/* + - wme-sitebuilder.php + - wme-sitebuilder/ + excludePaths: + - wme-sitebuilder/vendor/ # Additional checks. polluteScopeWithLoopInitialAssignments: true polluteScopeWithAlwaysIterableForeach: true - polluteCatchScopeWithTryAssignments: true checkAlwaysTrueCheckTypeFunctionCall: true checkAlwaysTrueInstanceof: true checkAlwaysTrueStrictComparison: true checkExplicitMixedMissingReturn: true checkFunctionNameCase: true - checkMissingClosureNativeReturnTypehintRule: false reportMaybesInMethodSignatures: true reportStaticMethodSignatures: true checkTooWideReturnTypesInProtectedAndPublicMethods: true @@ -57,7 +47,5 @@ parameters: # Error patterns that should be ignored. ignoreErrors: # WordPress coding standards dictate that we *not* use @return void - - '#Method .+ has no return typehint specified#' - - # WooCommerce classes will be loaded externally. - - '#Function (WC\S*|get_woocommerce_\S+) not found\.#i' + # TODO One can still add @phpstan-return void + - '#has no return type specified\.$#' diff --git a/wme-sitebuilder/Plugins/PaymentGateways/PayPal.php b/wme-sitebuilder/Plugins/PaymentGateways/PayPal.php index 677d4df..c94a6f9 100644 --- a/wme-sitebuilder/Plugins/PaymentGateways/PayPal.php +++ b/wme-sitebuilder/Plugins/PaymentGateways/PayPal.php @@ -134,7 +134,9 @@ public function action__woocommerce_paypal_payments_built_container( $container return; } + /** @var \WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer $onboarding */ $onboarding = $container->get( 'onboarding.render' ); + /** @var \WooCommerce\PayPalCommerce\WcGateway\Settings\Settings $settings */ $settings = $container->get( 'wcgateway.settings' ); $this->connected = ( $settings->has( 'client_id' ) && ! empty( $settings->get( 'client_id' ) ) );