Skip to content

Commit 5c50a18

Browse files
committed
Iterative updates to reduce the number of baseline issues
1 parent 6c38871 commit 5c50a18

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

.github/workflows/php-lint-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: "Set up PHP"
3131
uses: ./.github/actions/setup-php
3232
# install dependencies and run linter
33-
- run: composer self-update && composer install --no-progress && ./vendor/bin/phpcs --standard=phpcs.xml.dist $(git ls-files | grep .php$) && ./vendor/bin/psalm
33+
- run: composer self-update && composer install --no-progress && ./vendor/bin/phpcs --standard=phpcs.xml.dist $(git ls-files | grep .php$) && composer run phpstan
3434

3535
generate-test-matrix:
3636
name: "Generate the matrix for php tests dynamically"

dev/phpstan-wcpay-constants.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Custom WordPress constants stub file for PHPStan
4+
* This file provides definitions for common WordPress constants that are missing from the official stubs
5+
*/
6+
7+
define( 'WCPAY_VERSION_NUMBER', '10.2.0' );
8+
define( 'WC_ADMIN_VERSION_NUMBER', '' );

includes/class-payment-information.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ public function __construct(
165165
$this->payment_method = $payment_method;
166166
$this->order = $order;
167167
$this->token = $token;
168-
$this->payment_initiated_by = $payment_initiated_by ?? Payment_Initiated_By::CUSTOMER();
169-
$this->manual_capture = $manual_capture ?? Payment_Capture_Type::AUTOMATIC();
170-
$this->payment_type = $payment_type ?? Payment_Type::SINGLE();
168+
$this->payment_initiated_by = $payment_initiated_by ?? Payment_Initiated_By::CUSTOMER;
169+
$this->manual_capture = $manual_capture ?? Payment_Capture_Type::AUTOMATIC;
170+
$this->payment_type = $payment_type ?? Payment_Type::SINGLE;
171171
$this->cvc_confirmation = $cvc_confirmation;
172172
$this->fingerprint = $fingerprint;
173173
$this->payment_method_stripe_id = $payment_method_stripe_id;
@@ -180,7 +180,7 @@ public function __construct(
180180
* @return bool True if payment was initiated by the merchant, false otherwise.
181181
*/
182182
public function is_merchant_initiated(): bool {
183-
return $this->payment_initiated_by->equals( Payment_Initiated_By::MERCHANT() );
183+
return $this->payment_initiated_by->equals( Payment_Initiated_By::MERCHANT );
184184
}
185185

186186
/**

phpstan.neon

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ includes:
66

77
parameters:
88
level: 5
9+
phpVersion: 70400 # PHP 7.4
10+
dynamicConstantNames:
11+
- 'WCPAY_VERSION_NUMBER'
12+
- 'WC_ADMIN_VERSION_NUMBER'
913

1014
# Files and directories to analyze
1115
paths:
@@ -18,32 +22,27 @@ parameters:
1822
- includes/in-person-payments/templates
1923
- includes/subscriptions
2024
- includes/compat/subscriptions
21-
- vendor
22-
- client
23-
- docker
24-
- release
25-
- tests
26-
- bin
27-
- assets
28-
- languages
29-
- i18n
3025

3126
# Bootstrap files
3227
bootstrapFiles:
3328
- psalm-loader.php
3429

3530
scanFiles:
36-
- phpstan-wordpress-constants.php
31+
- dev/phpstan-wordpress-constants.php
32+
- dev/phpstan-wcpay-constants.php
33+
34+
scanDirectories:
35+
- docker/wordpress/wp-content/plugins/woocommerce/
3736

3837
# Handle undefined constants gracefully
3938
reportUnmatchedIgnoredErrors: false
40-
41-
# Allow dynamic properties for WordPress classes
42-
dynamicConstantNames:
43-
- 'true'
39+
# While PHP 7.3 is the lowest supported version we need to not rely on the argument types
40+
treatPhpDocTypesAsCertain: false
4441

4542
# Ignore common WordPress patterns that cause false positives
4643
ignoreErrors:
4744
- '#Call to function (is_admin|is_user_logged_in|current_user_can|__|_e|esc_attr|esc_html|wp_kses|get_option|update_option|do_action|apply_filters|add_action|add_filter|wp_enqueue_script|wp_enqueue_style|wp_localize_script|wp_redirect|wp_safe_redirect|wp_die|wp_mail|get_transient|set_transient|plugin_dir_path|plugin_dir_url|get_plugin_data)#'
4845
-
4946
identifier: missingType.iterableValue
47+
-
48+
identifier: missingType.voidReturn

0 commit comments

Comments
 (0)