Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PHPStan usage #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
112 changes: 78 additions & 34 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 12 additions & 24 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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\.$#'
2 changes: 2 additions & 0 deletions wme-sitebuilder/Plugins/PaymentGateways/PayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Comment on lines +137 to +139
Copy link
Author

@szepeviktor szepeviktor Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more advanced solutions than adding individual @var tags.

Although it takes only a few minutes to add them all!

$settings = $container->get( 'wcgateway.settings' );

$this->connected = ( $settings->has( 'client_id' ) && ! empty( $settings->get( 'client_id' ) ) );
Expand Down