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

Fix/php 8 compatibility errors warnings #9719

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions changelog/fix-php-8-compatibility-errors-warnings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: These changes fix some PHP compatibility errors that don't impact WooPayments behaviour.


4 changes: 2 additions & 2 deletions includes/admin/class-wc-rest-payments-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ private function update_is_stripe_billing_enabled( WP_REST_Request $request ) {
*
* @return WP_REST_Response|null The response object, if this is a REST request.
*/
public function schedule_stripe_billing_migration( WP_REST_Request $request = null ) {
public function schedule_stripe_billing_migration( ?WP_REST_Request $request = null ) {

if ( class_exists( 'WC_Payments_Subscriptions' ) ) {
$stripe_billing_migrator = WC_Payments_Subscriptions::get_stripe_billing_migrator();
Expand All @@ -1065,7 +1065,7 @@ public function schedule_stripe_billing_migration( WP_REST_Request $request = nu
*
* @return WP_REST_Response|WP_Error The response object, if this is a REST request.
*/
public function request_capability( WP_REST_Request $request = null ) {
public function request_capability( ?WP_REST_Request $request = null ) {
$request_result = null;
$id = $request->get_param( 'id' );
$capability_key_map = $this->wcpay_gateway->get_payment_method_capability_key_map();
Expand Down
26 changes: 13 additions & 13 deletions includes/class-payment-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ class Payment_Information {
*/
public function __construct(
string $payment_method,
\WC_Order $order = null,
Payment_Type $payment_type = null,
\WC_Payment_Token $token = null,
Payment_Initiated_By $payment_initiated_by = null,
Payment_Capture_Type $manual_capture = null,
string $cvc_confirmation = null,
?\WC_Order $order = null,
?Payment_Type $payment_type = null,
?\WC_Payment_Token $token = null,
?Payment_Initiated_By $payment_initiated_by = null,
?Payment_Capture_Type $manual_capture = null,
?string $cvc_confirmation = null,
string $fingerprint = '',
string $payment_method_stripe_id = null,
string $customer_id = null
?string $payment_method_stripe_id = null,
?string $customer_id = null
) {
if ( empty( $payment_method ) && empty( $token ) && ! \WC_Payments::is_network_saved_cards_enabled() ) {
// If network-wide cards are enabled, a payment method or token may not be specified and the platform default one will be used.
Expand Down Expand Up @@ -259,11 +259,11 @@ public function is_using_manual_capture(): bool {
*/
public static function from_payment_request(
array $request,
\WC_Order $order = null,
Payment_Type $payment_type = null,
Payment_Initiated_By $payment_initiated_by = null,
Payment_Capture_Type $manual_capture = null,
string $payment_method_stripe_id = null
?\WC_Order $order = null,
?Payment_Type $payment_type = null,
?Payment_Initiated_By $payment_initiated_by = null,
?Payment_Capture_Type $manual_capture = null,
?string $payment_method_stripe_id = null
): Payment_Information {
$payment_method = self::get_payment_method_from_request( $request );
$token = self::get_token_from_request( $request );
Expand Down
8 changes: 4 additions & 4 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ class WC_Payment_Gateway_WCPay extends WC_Payment_Gateway_CC {
* @param WC_Payments_Action_Scheduler_Service $action_scheduler_service - Action Scheduler service instance.
* @param UPE_Payment_Method $payment_method - Specific UPE_Payment_Method instance for gateway.
* @param array $payment_methods - Array of UPE payment methods.
* @param Session_Rate_Limiter|null $failed_transaction_rate_limiter - Rate Limiter for failed transactions.
* @param WC_Payments_Order_Service $order_service - Order class instance.
* @param Duplicate_Payment_Prevention_Service $duplicate_payment_prevention_service - Service for preventing duplicate payments.
* @param WC_Payments_Localization_Service $localization_service - Localization service instance.
* @param WC_Payments_Fraud_Service $fraud_service - Fraud service instance.
* @param Duplicates_Detection_Service $duplicate_payment_methods_detection_service - Service for finding duplicate enabled payment methods.
* @param Session_Rate_Limiter|null $failed_transaction_rate_limiter - Rate Limiter for failed transactions.
*/
public function __construct(
WC_Payments_API_Client $payments_api_client,
Expand All @@ -286,12 +286,12 @@ public function __construct(
WC_Payments_Action_Scheduler_Service $action_scheduler_service,
UPE_Payment_Method $payment_method,
array $payment_methods,
Session_Rate_Limiter $failed_transaction_rate_limiter = null,
WC_Payments_Order_Service $order_service,
Duplicate_Payment_Prevention_Service $duplicate_payment_prevention_service,
WC_Payments_Localization_Service $localization_service,
WC_Payments_Fraud_Service $fraud_service,
Duplicates_Detection_Service $duplicate_payment_methods_detection_service
Duplicates_Detection_Service $duplicate_payment_methods_detection_service,
?Session_Rate_Limiter $failed_transaction_rate_limiter = null
) {
$this->payment_methods = $payment_methods;
$this->payment_method = $payment_method;
Expand Down Expand Up @@ -3809,7 +3809,7 @@ public function schedule_order_tracking( $order_id, $order = null ) {
*
* @throws Exception - When an error occurs in intent creation.
*/
public function create_intent( WC_Order $order, array $payment_methods, string $capture_method = 'automatic', array $metadata = [], string $customer_id = null ) {
public function create_intent( WC_Order $order, array $payment_methods, string $capture_method = 'automatic', array $metadata = [], ?string $customer_id = null ) {
$currency = strtolower( $order->get_currency() );
$converted_amount = WC_Payments_Utils::prepare_amount( $order->get_total(), $currency );
$order_number = $order->get_order_number();
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-payments-customer-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function clear_cached_payment_methods_for_user( $user_id ) {
*
* @return array Customer data.
*/
public static function map_customer_data( WC_Order $wc_order = null, WC_Customer $wc_customer = null ): array {
public static function map_customer_data( ?WC_Order $wc_order = null, ?WC_Customer $wc_customer = null ): array {
if ( null === $wc_customer && null === $wc_order ) {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-payments-explicit-price-formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function unregister_formatted_woocommerce_price_filter() {
*
* @return string
*/
public static function get_explicit_price( string $price, WC_Abstract_Order $order = null ) {
public static function get_explicit_price( string $price, ?WC_Abstract_Order $order = null ) {
if ( null === $order ) {
$currency_code = get_woocommerce_currency();
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ public static function get_explicit_price_with_currency( string $price, ?string
return $price;
}

$price_to_check = html_entity_decode( wp_strip_all_tags( $price ) );
$price_to_check = html_entity_decode( wp_strip_all_tags( $price ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );

if ( false === strpos( $price_to_check, trim( $currency_code ) ) ) {
return $price . ' ' . $currency_code;
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-payments-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public static function array_map_recursive( array $array, callable $callback ):
*
* @return array The filtered array.
*/
public static function array_filter_recursive( array $array, callable $callback = null ): array {
public static function array_filter_recursive( array $array, ?callable $callback = null ): array {
foreach ( $array as $key => &$value ) { // Mind the use of a reference.
if ( \is_array( $value ) ) {
$value = self::array_filter_recursive( $value, $callback );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public static function init() {
foreach ( $payment_methods as $payment_method ) {
self::$payment_method_map[ $payment_method->get_id() ] = $payment_method;

$split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$failed_transaction_rate_limiter, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service, self::$duplicates_detection_service );
$split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service, self::$duplicates_detection_service, self::$failed_transaction_rate_limiter );

// Card gateway hooks are registered once below.
if ( 'card' !== $payment_method->get_id() ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/core/server/request/class-generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function create( $id = null ) {
* @param array $parameters The parameters for the request.
* @throws Invalid_Request_Parameter_Exception An exception if there are invalid properties.
*/
public function __construct( string $api, string $method, array $parameters = null ) {
public function __construct( string $api, string $method, ?array $parameters = null ) {
if ( ! defined( \WC_Payments_Utils::get_wpcore_request_class() . "::$method" ) ) {
throw new Invalid_Request_Parameter_Exception( 'Invalid generic request method', 'wcpay_core_invalid_request_parameter_method_not_defined' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function get_instance(): self {
*
* @param Buyer_Fingerprinting_Service|null $instance Instance of self.
*/
public static function set_instance( self $instance = null ) {
public static function set_instance( ?self $instance = null ) {
self::$instance = $instance;
}

Expand Down
4 changes: 2 additions & 2 deletions includes/fraud-prevention/class-fraud-prevention-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function is_pay_for_order_page() {
*
* @param Fraud_Prevention_Service|null $instance Instance of self.
*/
public static function set_instance( self $instance = null ) {
public static function set_instance( ?self $instance = null ) {
self::$instance = $instance;
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public function regenerate_token(): string {
* @param string|null $token Token sent in request.
* @return bool
*/
public function verify_token( string $token = null ): bool {
public function verify_token( ?string $token = null ): bool {
$session_token = $this->session->get( self::TOKEN_NAME );

// Check if the tokens are both strings.
Expand Down
2 changes: 1 addition & 1 deletion includes/multi-currency/MultiCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class MultiCurrency {
* @param MultiCurrencyCacheInterface $cache Cache instance.
* @param Utils|null $utils Optional Utils instance.
*/
public function __construct( MultiCurrencySettingsInterface $settings_service, MultiCurrencyApiClientInterface $payments_api_client, MultiCurrencyAccountInterface $payments_account, MultiCurrencyLocalizationInterface $localization_service, MultiCurrencyCacheInterface $cache, Utils $utils = null ) {
public function __construct( MultiCurrencySettingsInterface $settings_service, MultiCurrencyApiClientInterface $payments_api_client, MultiCurrencyAccountInterface $payments_account, MultiCurrencyLocalizationInterface $localization_service, MultiCurrencyCacheInterface $cache, ?Utils $utils = null ) {
$this->settings_service = $settings_service;
$this->payments_api_client = $payments_api_client;
$this->payments_account = $payments_account;
Expand Down
4 changes: 2 additions & 2 deletions includes/payment-methods/class-afterpay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct( $token_service ) {
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( string $account_country = null, $payment_details = false ) {
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( 'GB' === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}
Expand All @@ -60,7 +60,7 @@ public function get_title( string $account_country = null, $payment_details = fa
* @param string|null $account_country Country of merchants account.
* @return string|null
*/
public function get_icon( string $account_country = null ) {
public function get_icon( ?string $account_country = null ) {
if ( 'GB' === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/payment-methods/class-cc-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct( $token_service ) {
* @param array|false $payment_details Payment details.
* @return string
*/
public function get_title( string $account_country = null, $payment_details = false ) {
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( ! $payment_details ) {
return $this->title;
}
Expand Down
8 changes: 4 additions & 4 deletions includes/payment-methods/class-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function get_id() {
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( string $account_country = null, $payment_details = false ) {
public function get_title( ?string $account_country = null, $payment_details = false ) {
return $this->title;
}

Expand Down Expand Up @@ -283,7 +283,7 @@ abstract public function get_testing_instructions( string $account_country );
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_icon( string $account_country = null ) {
public function get_icon( ?string $account_country = null ) {
return isset( $this->icon_url ) ? $this->icon_url : '';
}

Expand All @@ -293,7 +293,7 @@ public function get_icon( string $account_country = null ) {
* @param string|null $account_country Optional account country.
* @return string
*/
public function get_dark_icon( string $account_country = null ) {
public function get_dark_icon( ?string $account_country = null ) {
return isset( $this->dark_icon_url ) ? $this->dark_icon_url : $this->get_icon( $account_country );
}

Expand All @@ -305,7 +305,7 @@ public function get_dark_icon( string $account_country = null ) {
* @param string $account_country Optional account country.
* @return string
*/
public function get_payment_method_icon_for_location( string $location = 'checkout', bool $is_blocks = true, string $account_country = null ) {
public function get_payment_method_icon_for_location( string $location = 'checkout', bool $is_blocks = true, ?string $account_country = null ) {
$appearance_theme = WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, $is_blocks ? 'blocks' : 'classic' );

if ( 'night' === $appearance_theme ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ public function register_domain( $domain_name ) {
*
* @throws API_Exception If an error occurs.
*/
public function register_terminal_reader( string $location, string $registration_code, string $label = null, array $metadata = null ) {
public function register_terminal_reader( string $location, string $registration_code, ?string $label = null, ?array $metadata = null ) {
$request = [
'location' => $location,
'registration_code' => $registration_code,
Expand Down
2 changes: 1 addition & 1 deletion lib/packages/League/Container/Argument/LiteralArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LiteralArgument implements LiteralArgumentInterface
*/
protected $value;

public function __construct($value, string $type = null)
public function __construct($value, ?string $type = null)
{
if (
null === $type
Expand Down
8 changes: 4 additions & 4 deletions lib/packages/League/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Container implements DefinitionContainerInterface
protected $delegates = [];

public function __construct(
DefinitionAggregateInterface $definitions = null,
ServiceProviderAggregateInterface $providers = null,
InflectorAggregateInterface $inflectors = null
?DefinitionAggregateInterface $definitions = null,
?ServiceProviderAggregateInterface $providers = null,
?InflectorAggregateInterface $inflectors = null
) {
$this->definitions = $definitions ?? new DefinitionAggregate();
$this->providers = $providers ?? new ServiceProviderAggregate();
Expand Down Expand Up @@ -139,7 +139,7 @@ public function has($id): bool
return false;
}

public function inflector(string $type, callable $callback = null): InflectorInterface
public function inflector(string $type, ?callable $callback = null): InflectorInterface
{
return $this->inflectors->add($type, $callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public function addServiceProvider(ServiceProviderInterface $provider): self;
public function addShared(string $id, $concrete = null): DefinitionInterface;
public function extend(string $id): DefinitionInterface;
public function getNew($id);
public function inflector(string $type, callable $callback = null): InflectorInterface;
public function inflector(string $type, ?callable $callback = null): InflectorInterface;
}
2 changes: 1 addition & 1 deletion lib/packages/League/Container/Inflector/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Inflector implements ArgumentResolverInterface, InflectorInterface
*/
protected $properties = [];

public function __construct(string $type, callable $callback = null)
public function __construct(string $type, ?callable $callback = null)
{
$this->type = $type;
$this->callback = $callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InflectorAggregate implements InflectorAggregateInterface
*/
protected $inflectors = [];

public function add(string $type, callable $callback = null): Inflector
public function add(string $type, ?callable $callback = null): Inflector
{
$inflector = new Inflector($type, $callback);
$this->inflectors[] = $inflector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

interface InflectorAggregateInterface extends ContainerAwareInterface, IteratorAggregate
{
public function add(string $type, callable $callback = null): Inflector;
public function add(string $type, ?callable $callback = null): Inflector;
public function inflect(object $object);
}
3 changes: 3 additions & 0 deletions phpcs-compat.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@

<!-- Debug functions are rarely used in our extensions, and are simply there for logging. -->
<exclude name="PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection" />

<!-- Disable rule that forces to define by default new HTML entities flags introduced in PHP 8.1 to keep code compatible with earlier versions -->
<exclude name="PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault" />
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Container implements ContainerInterface {
* @param WooContainer $woo_container Delegate container for WooCommerce (Optional).
*/
public function __construct(
LegacyContainer $legacy_container = null,
WooContainer $woo_container = null
?LegacyContainer $legacy_container = null,
?WooContainer $woo_container = null
) {
$this->container = new ExtendedContainer();

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Payment/PaymentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function get_metadata(): ?array {
*
* @param string $cvc_confirmation The confirmation.
*/
public function set_cvc_confirmation( string $cvc_confirmation = null ) {
public function set_cvc_confirmation( ?string $cvc_confirmation = null ) {
$this->set( 'cvc_confirmation', $cvc_confirmation );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Payment/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PaymentRequest {
* @param LegacyProxy $legacy_proxy Legacy proxy.
* @param array|null $request Request data, this can be $_POST, or WP_REST_Request::get_params().
*/
public function __construct( LegacyProxy $legacy_proxy, array $request = null ) {
public function __construct( LegacyProxy $legacy_proxy, ?array $request = null ) {
$this->legacy_proxy = $legacy_proxy;
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$this->request = $request ?? $_POST;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function set_payment_method_id( int $order_id, string $payment_method_id
* @return array The metadat athat will be sent to the server.
* @throws Order_Not_Found_Exception
*/
public function get_payment_metadata( int $order_id, Payment_Type $payment_type = null ) {
public function get_payment_metadata( int $order_id, ?Payment_Type $payment_type = null ) {
$order = $this->get_order( $order_id );

$name = sanitize_text_field( $order->get_billing_first_name() ) . ' ' . sanitize_text_field( $order->get_billing_last_name() );
Expand Down
Loading
Loading