From 6a57a81b71878d26d29ff1f7e64f31247b09a4cd Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 11 Jul 2023 19:18:49 +0000 Subject: [PATCH 1/2] fix!: update deps to required versions --- README.txt | 6 +++--- composer.json | 6 +++--- composer.lock | 38 +++++++++++++++++++------------------- phpcs.xml.dist | 4 ++-- wp-graphql-woocommerce.php | 4 ++-- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.txt b/README.txt index af185ff56..484e6575e 100644 --- a/README.txt +++ b/README.txt @@ -1,10 +1,10 @@ === WP GraphQL WooCommerce === Contributors: kidunot89, ranaaterning, jasonbahl, saleebm Tags: GraphQL, WooCommerce, WPGraphQL -Requires at least: 4.9 +Requires at least: 5.9 Tested up to: 6.2 -Requires PHP: 7.1 -Requires WooCommerce: 4.8.0 +Requires PHP: 7.2 +Requires WooCommerce: 7.5.0 Requires WPGraphQL: 1.14.0+ Works with WPGraphQL-JWT-Authentication: 0.7.0+ Stable tag: 0.14.1 diff --git a/composer.json b/composer.json index 3e8f3927b..09a61a6a5 100644 --- a/composer.json +++ b/composer.json @@ -21,13 +21,13 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=7.2", "firebase/php-jwt": "^6.1.0" }, "require-dev": { "automattic/vipwpcs": "^2.3", - "axepress/wp-graphql-stubs": "^1.14", - "php-stubs/woocommerce-stubs": "^7.7", + "axepress/wp-graphql-stubs": "1.14.0", + "php-stubs/woocommerce-stubs": "7.5.0", "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.5", diff --git a/composer.lock b/composer.lock index abb1ab90b..0c0d54d66 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": "fb3dcd97101e5ff66f9f812e417aa977", + "content-hash": "1fe0d1a5418403ab97ed669378c504f9", "packages": [ { "name": "firebase/php-jwt", @@ -125,16 +125,16 @@ }, { "name": "axepress/wp-graphql-stubs", - "version": "v1.14.4", + "version": "v1.14.0", "source": { "type": "git", "url": "https://github.com/AxeWP/wp-graphql-stubs.git", - "reference": "1c5b0cb3ce978d1e88a828c158383877ba7c223a" + "reference": "1455a46043f758b77a49337c9520cb79c5a0a31f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/AxeWP/wp-graphql-stubs/zipball/1c5b0cb3ce978d1e88a828c158383877ba7c223a", - "reference": "1c5b0cb3ce978d1e88a828c158383877ba7c223a", + "url": "https://api.github.com/repos/AxeWP/wp-graphql-stubs/zipball/1455a46043f758b77a49337c9520cb79c5a0a31f", + "reference": "1455a46043f758b77a49337c9520cb79c5a0a31f", "shasum": "" }, "require": { @@ -165,7 +165,7 @@ ], "support": { "issues": "https://github.com/AxeWP/wp-graphql-stubs/issues", - "source": "https://github.com/AxeWP/wp-graphql-stubs/tree/v1.14.4" + "source": "https://github.com/AxeWP/wp-graphql-stubs/tree/v1.14.0" }, "funding": [ { @@ -173,7 +173,7 @@ "type": "github" } ], - "time": "2023-06-14T01:39:23+00:00" + "time": "2023-03-09T01:45:16+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -252,16 +252,16 @@ }, { "name": "php-stubs/woocommerce-stubs", - "version": "v7.8.0", + "version": "v7.5.0", "source": { "type": "git", "url": "https://github.com/php-stubs/woocommerce-stubs.git", - "reference": "1e9180bbac115884bf41bf1d2ee0f72338c0a566" + "reference": "9a735c3a66fb3eab4bdbb9e998db00b1fbd268d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/1e9180bbac115884bf41bf1d2ee0f72338c0a566", - "reference": "1e9180bbac115884bf41bf1d2ee0f72338c0a566", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/9a735c3a66fb3eab4bdbb9e998db00b1fbd268d7", + "reference": "9a735c3a66fb3eab4bdbb9e998db00b1fbd268d7", "shasum": "" }, "require": { @@ -290,9 +290,9 @@ ], "support": { "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", - "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v7.8.0" + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v7.5.0" }, - "time": "2023-06-13T20:06:40+00:00" + "time": "2023-03-14T14:19:48+00:00" }, { "name": "php-stubs/wordpress-stubs", @@ -385,16 +385,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.21", + "version": "1.10.25", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5" + "reference": "578f4e70d117f9a90699324c555922800ac38d8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", - "reference": "b2a30186be2e4d97dce754ae4e65eb0ec2f04eb5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/578f4e70d117f9a90699324c555922800ac38d8c", + "reference": "578f4e70d117f9a90699324c555922800ac38d8c", "shasum": "" }, "require": { @@ -443,7 +443,7 @@ "type": "tidelift" } ], - "time": "2023-06-21T20:07:58+00:00" + "time": "2023-07-06T12:11:37+00:00" }, { "name": "sirbrillig/phpcs-variable-analysis", @@ -756,7 +756,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1.0" + "php": ">=7.2" }, "platform-dev": [], "platform-overrides": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index edaa4ea8c..edd855dd6 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,7 +14,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index fb4c2b1d0..5953b2afb 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -10,8 +10,8 @@ * Domain Path: /languages * License: GPL-3 * License URI: https://www.gnu.org/licenses/gpl-3.0.html - * WC requires at least: 4.8.0 - * WC tested up to: 7.5.1 + * WC requires at least: 7.5.0 + * WC tested up to: 7.8.2 * WPGraphQL requires at least: 1.14.0+ * WPGraphQL-JWT-Authentication requires at least: 0.7.0+ * From f977862396a906e7c7a7cdd09d8a5d47193a2dbb Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 11 Jul 2023 19:57:13 +0000 Subject: [PATCH 2/2] fix: use static closures when possible --- includes/admin/class-general.php | 10 +- includes/class-core-schema-filters.php | 4 +- includes/class-jwt-auth-schema-filters.php | 8 +- includes/class-wp-graphql-woocommerce.php | 2 +- includes/connection/class-comments.php | 10 +- includes/connection/class-coupons.php | 2 +- includes/connection/class-customers.php | 4 +- includes/connection/class-orders.php | 8 +- .../connection/class-payment-gateways.php | 2 +- includes/connection/class-posts.php | 2 +- .../connection/class-product-attributes.php | 2 +- includes/connection/class-products.php | 24 ++--- .../connection/class-shipping-methods.php | 2 +- includes/connection/class-tax-rates.php | 2 +- .../connection/class-variation-attributes.php | 2 +- includes/connection/class-wc-terms.php | 8 +- .../class-cart-item-connection-resolver.php | 2 +- ...-downloadable-item-connection-resolver.php | 6 +- .../class-order-item-connection-resolver.php | 2 +- ...-product-attribute-connection-resolver.php | 4 +- ...ss-shipping-method-connection-resolver.php | 2 +- .../class-tax-rate-connection-resolver.php | 2 +- includes/data/loader/class-wc-cpt-loader.php | 4 +- .../data/mutation/class-cart-mutation.php | 2 +- includes/functions.php | 2 +- includes/mutation/class-cart-add-fee.php | 4 +- includes/mutation/class-cart-add-item.php | 4 +- includes/mutation/class-cart-add-items.php | 6 +- includes/mutation/class-cart-apply-coupon.php | 4 +- includes/mutation/class-cart-empty.php | 4 +- includes/mutation/class-cart-fill.php | 10 +- .../mutation/class-cart-remove-coupons.php | 2 +- includes/mutation/class-cart-remove-items.php | 4 +- .../mutation/class-cart-restore-items.php | 2 +- .../class-cart-update-item-quantities.php | 10 +- .../class-cart-update-shipping-method.php | 2 +- includes/mutation/class-checkout.php | 10 +- includes/mutation/class-coupon-create.php | 4 +- includes/mutation/class-coupon-delete.php | 2 +- includes/mutation/class-customer-register.php | 6 +- includes/mutation/class-customer-update.php | 4 +- includes/mutation/class-order-create.php | 6 +- .../mutation/class-order-delete-items.php | 4 +- includes/mutation/class-order-delete.php | 4 +- includes/mutation/class-order-update.php | 4 +- .../mutation/class-payment-method-delete.php | 4 +- .../class-payment-method-set-default.php | 6 +- .../mutation/class-review-delete-restore.php | 8 +- includes/mutation/class-review-update.php | 2 +- includes/mutation/class-review-write.php | 6 +- includes/mutation/class-update-session.php | 6 +- includes/type/enum/class-countries.php | 2 +- includes/type/interface/class-attribute.php | 6 +- includes/type/interface/class-cart-error.php | 6 +- .../type/interface/class-payment-token.php | 12 +-- .../interface/class-product-attribute.php | 18 ++-- includes/type/interface/class-product.php | 8 +- .../type/object/class-cart-error-types.php | 16 ++-- includes/type/object/class-cart-type.php | 96 +++++++++---------- .../type/object/class-country-state-type.php | 4 +- .../object/class-customer-address-type.php | 22 ++--- includes/type/object/class-customer-type.php | 38 ++++---- .../object/class-downloadable-item-type.php | 16 ++-- includes/type/object/class-meta-data-type.php | 14 +-- .../type/object/class-order-item-type.php | 20 ++-- includes/type/object/class-order-type.php | 22 ++--- .../object/class-payment-gateway-type.php | 8 +- .../type/object/class-payment-token-types.php | 10 +- .../object/class-product-attribute-types.php | 18 ++-- .../object/class-product-category-type.php | 6 +- .../object/class-product-download-type.php | 16 ++-- includes/type/object/class-product-types.php | 10 +- .../object/class-product-variation-type.php | 8 +- includes/type/object/class-refund-type.php | 2 +- includes/type/object/class-root-query.php | 26 ++--- .../object/class-shipping-package-type.php | 6 +- .../type/object/class-shipping-rate-type.php | 10 +- .../object/class-variation-attribute-type.php | 10 +- includes/utils/class-ql-session-handler.php | 2 +- wp-graphql-woocommerce.php | 2 +- 80 files changed, 340 insertions(+), 340 deletions(-) diff --git a/includes/admin/class-general.php b/includes/admin/class-general.php index be0b00042..c761529f6 100644 --- a/includes/admin/class-general.php +++ b/includes/admin/class-general.php @@ -102,7 +102,7 @@ public static function get_fields() { ), 'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ), 'disabled' => $enable_auth_urls_hardcoded ? true : false, - 'sanitize_callback' => function( $value ) { + 'sanitize_callback' => static function( $value ) { if ( empty( $value ) ) { return []; } @@ -131,7 +131,7 @@ public static function get_fields() { 'type' => 'text', 'value' => $cart_url_hardcoded ? CART_URL_NONCE_PARAM : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ), 'disabled' => defined( 'CART_URL_NONCE_PARAM' ) || ! in_array( 'cart_url', $enabled_authorizing_url_fields, true ), - 'sanitize_callback' => function ( $value ) { + 'sanitize_callback' => static function ( $value ) { $other_nonces = self::get_other_nonce_values( 'cart_url' ); if ( in_array( $value, $other_nonces, true ) ) { add_settings_error( @@ -155,7 +155,7 @@ public static function get_fields() { 'type' => 'text', 'value' => $checkout_url_hardcoded ? CHECKOUT_URL_NONCE_PARAM : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ), 'disabled' => defined( 'CHECKOUT_URL_NONCE_PARAM' ) || ! in_array( 'checkout_url', $enabled_authorizing_url_fields, true ), - 'sanitize_callback' => function ( $value ) { + 'sanitize_callback' => static function ( $value ) { $other_nonces = self::get_other_nonce_values( 'checkout_url' ); if ( in_array( $value, $other_nonces, true ) ) { add_settings_error( @@ -179,7 +179,7 @@ public static function get_fields() { 'type' => 'text', 'value' => $account_url_hardcoded ? ACCOUNT_URL_NONCE_PARAM : woographql_setting( 'account_url_nonce_param', '_wc_account' ), 'disabled' => defined( 'ACCOUNT_URL_NONCE_PARAM' ) || ! in_array( 'account_url', $enabled_authorizing_url_fields, true ), - 'sanitize_callback' => function ( $value ) { + 'sanitize_callback' => static function ( $value ) { $other_nonces = self::get_other_nonce_values( 'account_url' ); if ( in_array( $value, $other_nonces, true ) ) { add_settings_error( @@ -203,7 +203,7 @@ public static function get_fields() { 'type' => 'text', 'value' => $add_payment_method_url_hardcoded ? ADD_PAYMENT_METHOD_URL_NONCE_PARAM : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ), 'disabled' => defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) || ! in_array( 'add_payment_method_url', $enabled_authorizing_url_fields, true ), - 'sanitize_callback' => function ( $value ) { + 'sanitize_callback' => static function ( $value ) { $other_nonces = self::get_other_nonce_values( 'add_payment_method_url' ); if ( in_array( $value, $other_nonces, true ) ) { add_settings_error( diff --git a/includes/class-core-schema-filters.php b/includes/class-core-schema-filters.php index d36d1ff98..8fa0cb672 100644 --- a/includes/class-core-schema-filters.php +++ b/includes/class-core-schema-filters.php @@ -306,7 +306,7 @@ public static function inject_union_types( $config, $wp_union ) { $config['typeNames'] = array_merge( array_filter( $config['typeNames'], - function( $type ) { + static function( $type ) { return 'Product' !== $type; } ), @@ -318,7 +318,7 @@ function( $type ) { // Update 'types' callback. if ( $refresh_callback ) { - $config['types'] = function () use ( $config, $wp_union ) { + $config['types'] = static function () use ( $config, $wp_union ) { $prepared_types = []; foreach ( $config['typeNames'] as $type_name ) { $prepared_types[] = $wp_union->type_registry->get_type( $type_name ); diff --git a/includes/class-jwt-auth-schema-filters.php b/includes/class-jwt-auth-schema-filters.php index 40a746f4c..f8512ea15 100644 --- a/includes/class-jwt-auth-schema-filters.php +++ b/includes/class-jwt-auth-schema-filters.php @@ -61,7 +61,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) 'authToken' => [ 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); if ( ! $user ) { @@ -85,7 +85,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) 'refreshToken' => [ 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); if ( ! $user ) { @@ -124,7 +124,7 @@ public static function add_customer_to_login_payload() { [ 'type' => 'Customer', 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $id = $payload['id']; return new Customer( $id ); }, @@ -138,7 +138,7 @@ public static function add_customer_to_login_payload() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { /** * Session Handler. * diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index 14bbdde52..e3844dd80 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -360,7 +360,7 @@ private function includes() { if ( ! class_exists( 'Firebase\JWT\JWT' ) ) { add_action( 'admin_notices', - function () { + static function () { if ( ! current_user_can( 'manage_options' ) ) { return; } diff --git a/includes/connection/class-comments.php b/includes/connection/class-comments.php index a1a46eac9..88e62bc2e 100644 --- a/includes/connection/class-comments.php +++ b/includes/connection/class-comments.php @@ -34,7 +34,7 @@ public static function register_connections() { 'averageRating' => [ 'type' => 'Float', 'description' => __( 'Average review rating for this product.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -47,7 +47,7 @@ public static function register_connections() { 'rating' => [ 'type' => 'Float', 'description' => __( 'Review rating', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $review = $source['node']; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $rating = get_comment_meta( $review->commentId, 'rating', true ); @@ -55,7 +55,7 @@ public static function register_connections() { }, ], ], - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post_type', 'product' ); @@ -78,14 +78,14 @@ public static function register_connections() { 'isCustomerNote' => [ 'type' => 'Boolean', 'description' => __( 'Is this a customer note?', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $note = $source['node']; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return get_comment_meta( $note->commentId, 'is_customer_note', true ); }, ], ], - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post_id', $source->ID ); diff --git a/includes/connection/class-coupons.php b/includes/connection/class-coupons.php index 4f2fe2467..6e9d6f36c 100644 --- a/includes/connection/class-coupons.php +++ b/includes/connection/class-coupons.php @@ -43,7 +43,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'Coupon', 'fromFieldName' => 'coupons', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function ( $source, $args, $context, $info ) { + 'resolve' => static function ( $source, $args, $context, $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'shop_coupon' ); if ( ! self::should_execute() ) { diff --git a/includes/connection/class-customers.php b/includes/connection/class-customers.php index c924517be..24d1cc85a 100644 --- a/includes/connection/class-customers.php +++ b/includes/connection/class-customers.php @@ -32,7 +32,7 @@ public static function register_connections() { 'toType' => 'Customer', 'fromFieldName' => 'customers', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new UserConnectionResolver( $source, $args, $context, $info ); if ( ! self::should_execute() ) { @@ -55,7 +55,7 @@ public static function register_connections() { 'toType' => 'Customer', 'fromFieldName' => 'usedBy', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new UserConnectionResolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'include', $source->used_by_ids ); diff --git a/includes/connection/class-orders.php b/includes/connection/class-orders.php index af589a974..55dc9840d 100644 --- a/includes/connection/class-orders.php +++ b/includes/connection/class-orders.php @@ -37,7 +37,7 @@ public static function register_connections() { [ 'fromType' => 'Customer', 'fromFieldName' => 'orders', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info ); return self::get_customer_order_connection( $resolver, $source ); @@ -65,7 +65,7 @@ public static function register_connections() { 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' ); $resolver->set_should_execute( true ); @@ -85,7 +85,7 @@ public static function register_connections() { 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' ); return self::get_customer_refund_connection( $resolver, $source ); @@ -215,7 +215,7 @@ public static function get_connection_config( $args = [], $post_type = 'shop_ord 'toType' => 'Order', 'fromFieldName' => 'orders', 'connectionArgs' => self::get_connection_args( 'private' ), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) { // Check if user shop manager. $not_manager = ! current_user_can( $post_object->cap->edit_posts ); diff --git a/includes/connection/class-payment-gateways.php b/includes/connection/class-payment-gateways.php index cb6ddd1d5..6118f74a7 100644 --- a/includes/connection/class-payment-gateways.php +++ b/includes/connection/class-payment-gateways.php @@ -41,7 +41,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'PaymentGateway', 'fromFieldName' => 'paymentGateways', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Payment_Gateway_Connection_Resolver(); return $resolver->resolve( $source, $args, $context, $info ); diff --git a/includes/connection/class-posts.php b/includes/connection/class-posts.php index 4d2eaf604..e9456f5f7 100644 --- a/includes/connection/class-posts.php +++ b/includes/connection/class-posts.php @@ -30,7 +30,7 @@ public static function register_connections() { 'fromType' => 'Product', 'toType' => 'MediaItem', 'fromFieldName' => 'galleryImages', - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'attachment' ); $resolver->set_query_arg( 'post_type', 'attachment' ); $resolver->set_query_arg( 'post__in', $source->gallery_image_ids ); diff --git a/includes/connection/class-product-attributes.php b/includes/connection/class-product-attributes.php index 601446c7a..96846962f 100644 --- a/includes/connection/class-product-attributes.php +++ b/includes/connection/class-product-attributes.php @@ -67,7 +67,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'ProductAttribute', 'fromFieldName' => 'attributes', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Product_Attribute_Connection_Resolver(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase switch ( $info->fieldName ) { diff --git a/includes/connection/class-products.php b/includes/connection/class-products.php index c87152ec1..3b23ed85c 100644 --- a/includes/connection/class-products.php +++ b/includes/connection/class-products.php @@ -33,7 +33,7 @@ public static function register_connections() { self::get_connection_config( [ 'fromType' => 'Coupon', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -55,7 +55,7 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProducts', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -88,7 +88,7 @@ public static function register_connections() { ], ] ), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -97,7 +97,7 @@ public static function register_connections() { if ( empty( $args['where']['shuffle'] ) ) { add_filter( 'woocommerce_product_related_posts_shuffle', - function() { + static function() { return false; } ); @@ -121,7 +121,7 @@ function() { [ 'fromType' => 'Product', 'fromFieldName' => 'upsell', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -144,7 +144,7 @@ function() { self::get_connection_config( [ 'fromType' => 'GroupProduct', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -165,7 +165,7 @@ function() { // Product cross-sell connections. $cross_sell_config = [ 'fromFieldName' => 'crossSell', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -198,7 +198,7 @@ function() { 'fromType' => 'VariableProduct', 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -228,7 +228,7 @@ function() { 'description' => __( 'The parent of the node. The parent object can be of various types', 'wp-graphql-woocommerce' ), 'oneToOne' => true, 'queryClass' => '\WC_Product_Query', - 'resolve' => function( $source, $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, $args, AppContext $context, ResolveInfo $info ) { if ( empty( $source->parent_id ) ) { return null; } @@ -255,7 +255,7 @@ function() { 'fromType' => ucfirst( graphql_format_field_name( $attribute ) ), 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { global $wpdb; add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); @@ -325,7 +325,7 @@ public static function set_connection_config( $config ) { $taxonomies = self::get_product_connected_taxonomies(); if ( 'Product' === $to_type && in_array( $from_type, $taxonomies, true ) ) { - $config['resolve'] = function( $source, array $args, AppContext $context, ResolveInfo $info ) { + $config['resolve'] = static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); @@ -362,7 +362,7 @@ public static function get_connection_config( $args = [] ): array { 'fromFieldName' => 'products', 'queryClass' => '\WC_Product_Query', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); diff --git a/includes/connection/class-shipping-methods.php b/includes/connection/class-shipping-methods.php index e3c44f1aa..edd36b594 100644 --- a/includes/connection/class-shipping-methods.php +++ b/includes/connection/class-shipping-methods.php @@ -43,7 +43,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'ShippingMethod', 'fromFieldName' => 'shippingMethods', 'connectionArgs' => [], - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); diff --git a/includes/connection/class-tax-rates.php b/includes/connection/class-tax-rates.php index e1e86c981..64b1633b4 100644 --- a/includes/connection/class-tax-rates.php +++ b/includes/connection/class-tax-rates.php @@ -43,7 +43,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'TaxRate', 'fromFieldName' => 'taxRates', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Tax_Rate_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); diff --git a/includes/connection/class-variation-attributes.php b/includes/connection/class-variation-attributes.php index 8707385e9..54bdcf6cb 100644 --- a/includes/connection/class-variation-attributes.php +++ b/includes/connection/class-variation-attributes.php @@ -57,7 +57,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'VariationAttribute', 'fromFieldName' => 'attributes', 'connectionArgs' => [], - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Variation_Attribute_Connection_Resolver(); return $resolver->resolve( $source, $args, $context, $info ); diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index 834940343..1f7af8184 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -61,7 +61,7 @@ public static function register_connections() { 'fromType' => $post_type_object->graphql_single_name, 'toType' => $tax_object->graphql_single_name, 'fromFieldName' => $tax_object->graphql_plural_name, - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $term_ids = \wc_get_object_terms( $source->ID, $tax_object->name, 'term_id' ); @@ -89,7 +89,7 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'productCategories', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $resolver->set_query_arg( 'term_taxonomy_id', $source->product_category_ids ); @@ -104,7 +104,7 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProductCategories', - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $resolver->set_query_arg( 'term_taxonomy_id', $source->excluded_product_category_ids ); @@ -121,7 +121,7 @@ public static function register_connections() { 'queryClass' => 'WP_Term_Query', 'fromFieldName' => 'terms', 'connectionArgs' => self::get_connection_args(), - 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { if ( ! $source->is_taxonomy() ) { throw new UserError( __( 'Invalid product attribute', 'wp-graphql-woocommerce' ) ); } diff --git a/includes/data/connection/class-cart-item-connection-resolver.php b/includes/data/connection/class-cart-item-connection-resolver.php index dbf2104db..12d8d5210 100644 --- a/includes/data/connection/class-cart-item-connection-resolver.php +++ b/includes/data/connection/class-cart-item-connection-resolver.php @@ -56,7 +56,7 @@ public function get_query_args() { $where_args = $this->args['where']; if ( isset( $where_args['needsShipping'] ) ) { $needs_shipping = $where_args['needsShipping']; - $query_args['filters'][] = function( $cart_item ) use ( $needs_shipping ) { + $query_args['filters'][] = static function( $cart_item ) use ( $needs_shipping ) { $product = \WC()->product_factory->get_product( $cart_item['product_id'] ); if ( ! is_object( $product ) ) { diff --git a/includes/data/connection/class-downloadable-item-connection-resolver.php b/includes/data/connection/class-downloadable-item-connection-resolver.php index 5d62afbf9..8465cd173 100644 --- a/includes/data/connection/class-downloadable-item-connection-resolver.php +++ b/includes/data/connection/class-downloadable-item-connection-resolver.php @@ -58,7 +58,7 @@ public function get_query_args() { if ( isset( $where_args['active'] ) ) { $active = $where_args['active']; - $query_args['filters'][] = function( $downloadable_item ) use ( $active ) { + $query_args['filters'][] = static function( $downloadable_item ) use ( $active ) { $is_expired = isset( $downloadable_item['access_expires'] ) ? time() > $downloadable_item['access_expires']->getTimestamp() : false; @@ -73,7 +73,7 @@ public function get_query_args() { if ( isset( $where_args['expired'] ) ) { $expired = $where_args['expired']; - $query_args['filters'][] = function( $downloadable_item ) use ( $expired ) { + $query_args['filters'][] = static function( $downloadable_item ) use ( $expired ) { $is_expired = isset( $downloadable_item['access_expires'] ) ? time() < $downloadable_item['access_expires']->getTimestamp() : false; @@ -85,7 +85,7 @@ public function get_query_args() { if ( isset( $where_args['hasDownloadsRemaining'] ) ) { $has_downloads_remaining = $where_args['hasDownloadsRemaining']; - $query_args['filters'][] = function( $downloadable_item ) use ( $has_downloads_remaining ) { + $query_args['filters'][] = static function( $downloadable_item ) use ( $has_downloads_remaining ) { $downloads_remaining = ( 'integer' === gettype( $downloadable_item['downloads_remaining'] ) ) ? 0 < $downloadable_item['downloads_remaining'] : true; diff --git a/includes/data/connection/class-order-item-connection-resolver.php b/includes/data/connection/class-order-item-connection-resolver.php index 073a519dc..9e4683067 100644 --- a/includes/data/connection/class-order-item-connection-resolver.php +++ b/includes/data/connection/class-order-item-connection-resolver.php @@ -128,7 +128,7 @@ public function get_query() { $items = array_reverse( $items ); } - $get_item_id = function( $item ) { + $get_item_id = static function( $item ) { return $item->get_id(); }; diff --git a/includes/data/connection/class-product-attribute-connection-resolver.php b/includes/data/connection/class-product-attribute-connection-resolver.php index 41c84f23e..d9842b164 100644 --- a/includes/data/connection/class-product-attribute-connection-resolver.php +++ b/includes/data/connection/class-product-attribute-connection-resolver.php @@ -56,7 +56,7 @@ private function get_items( $attributes, $source, $args, $context, $info, $type case 'local': $items = array_filter( $items, - function( $item ) { + static function( $item ) { return ! $item->is_taxonomy(); } ); @@ -64,7 +64,7 @@ function( $item ) { case 'global': $items = array_filter( $items, - function( $item ) { + static function( $item ) { return $item->is_taxonomy(); } ); diff --git a/includes/data/connection/class-shipping-method-connection-resolver.php b/includes/data/connection/class-shipping-method-connection-resolver.php index 35ef6259e..df9a7a80e 100644 --- a/includes/data/connection/class-shipping-method-connection-resolver.php +++ b/includes/data/connection/class-shipping-method-connection-resolver.php @@ -60,7 +60,7 @@ public function get_query() { // Get shipping method IDs. $methods = array_map( - function( $item ) { + static function( $item ) { return $item->id; }, array_values( $methods ) diff --git a/includes/data/connection/class-tax-rate-connection-resolver.php b/includes/data/connection/class-tax-rate-connection-resolver.php index 533b6ad5e..69bf30b8c 100644 --- a/includes/data/connection/class-tax-rate-connection-resolver.php +++ b/includes/data/connection/class-tax-rate-connection-resolver.php @@ -141,7 +141,7 @@ public function get_query() { }//end if $results = array_map( - function( $rate ) { + static function( $rate ) { return $rate->tax_rate_id; }, (array) $results diff --git a/includes/data/loader/class-wc-cpt-loader.php b/includes/data/loader/class-wc-cpt-loader.php index f1c9c4f6d..b6095e6eb 100644 --- a/includes/data/loader/class-wc-cpt-loader.php +++ b/includes/data/loader/class-wc-cpt-loader.php @@ -111,7 +111,7 @@ public function loadKeys( array $keys ) { */ add_filter( 'split_the_query', - function ( $split, \WP_Query $query ) { + static function ( $split, \WP_Query $query ) { if ( false === $query->get( 'split_the_query' ) ) { return false; } @@ -202,7 +202,7 @@ function() use ( $key, $post_type, $customer_id, $parent_id, $context ) { * Once dependencies are loaded, return the Post Object */ $loaded_posts[ $key ] = $load_dependencies->then( - function() use ( $post_type, $key ) { + static function() use ( $post_type, $key ) { return self::resolve_model( $post_type, $key ); } ); diff --git a/includes/data/mutation/class-cart-mutation.php b/includes/data/mutation/class-cart-mutation.php index 21d3364aa..991b15dc9 100644 --- a/includes/data/mutation/class-cart-mutation.php +++ b/includes/data/mutation/class-cart-mutation.php @@ -26,7 +26,7 @@ class Cart_Mutation { public static function get_cart_field( $fallback = false ) { return [ 'type' => 'Cart', - 'resolve' => function ( $payload ) use ( $fallback ) { + 'resolve' => static function ( $payload ) use ( $fallback ) { $cart = ! empty( $payload['cart'] ) ? $payload['cart'] : null; if ( is_null( $cart ) && $fallback ) { diff --git a/includes/functions.php b/includes/functions.php index a427b27eb..97b7fbee7 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -37,7 +37,7 @@ function woographql_swp_result_possible_types( array $type_names ) { $type_names = array_merge( array_filter( $type_names, - function( $type_name ) { + static function( $type_name ) { return 'Product' !== $type_name; } ), diff --git a/includes/mutation/class-cart-add-fee.php b/includes/mutation/class-cart-add-fee.php index 7d721cc63..6432f2ed6 100644 --- a/includes/mutation/class-cart-add-fee.php +++ b/includes/mutation/class-cart-add-fee.php @@ -73,7 +73,7 @@ public static function get_output_fields() { return [ 'cartFee' => [ 'type' => 'CartFee', - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $fees = \WC()->cart->get_fees(); return $fees[ $payload['id'] ]; }, @@ -88,7 +88,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( ! current_user_can( 'edit_shop_orders' ) ) { diff --git a/includes/mutation/class-cart-add-item.php b/includes/mutation/class-cart-add-item.php index 8044368ac..7e2542bd5 100644 --- a/includes/mutation/class-cart-add-item.php +++ b/includes/mutation/class-cart-add-item.php @@ -75,7 +75,7 @@ public static function get_output_fields() { return [ 'cartItem' => [ 'type' => 'CartItem', - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $item = \WC()->cart->get_cart_item( $payload['key'] ); return $item; @@ -91,7 +91,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Prepare args for "add_to_cart" from input data. diff --git a/includes/mutation/class-cart-add-items.php b/includes/mutation/class-cart-add-items.php index 7069c6e7e..fbce0d47f 100644 --- a/includes/mutation/class-cart-add-items.php +++ b/includes/mutation/class-cart-add-items.php @@ -58,7 +58,7 @@ public static function get_output_fields() { return [ 'added' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $items = []; foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); @@ -69,7 +69,7 @@ public static function get_output_fields() { ], 'cartErrors' => [ 'type' => [ 'list_of' => 'CartItemError' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $errors = []; foreach ( $payload['failure'] as $error_data ) { $cart_error = $error_data['cart_item_data']; @@ -97,7 +97,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Throw error, if no cart item data provided. diff --git a/includes/mutation/class-cart-apply-coupon.php b/includes/mutation/class-cart-apply-coupon.php index 8ab4d206e..d6a06c377 100644 --- a/includes/mutation/class-cart-apply-coupon.php +++ b/includes/mutation/class-cart-apply-coupon.php @@ -58,7 +58,7 @@ public static function get_output_fields() { return [ 'applied' => [ 'type' => 'AppliedCoupon', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['code']; }, ], @@ -72,7 +72,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input ) { + return static function( $input ) { Cart_Mutation::check_session_token(); $reason = ''; diff --git a/includes/mutation/class-cart-empty.php b/includes/mutation/class-cart-empty.php index a8b5dabe7..97ddd0756 100644 --- a/includes/mutation/class-cart-empty.php +++ b/includes/mutation/class-cart-empty.php @@ -48,7 +48,7 @@ public static function get_output_fields() { 'deletedCart' => Cart_Mutation::get_cart_field(), 'cart' => [ 'type' => 'Cart', - 'resolve' => function () { + 'resolve' => static function () { return \WC()->cart; }, ], @@ -61,7 +61,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Get/Clone WC_Cart instance. diff --git a/includes/mutation/class-cart-fill.php b/includes/mutation/class-cart-fill.php index dbdccb036..56283ee33 100644 --- a/includes/mutation/class-cart-fill.php +++ b/includes/mutation/class-cart-fill.php @@ -67,7 +67,7 @@ public static function get_output_fields() { return [ 'added' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $items = []; foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); @@ -78,21 +78,21 @@ public static function get_output_fields() { ], 'applied' => [ 'type' => [ 'list_of' => 'AppliedCoupon' ], - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $codes = $payload['applied']; return ! empty( $codes ) ? $codes : null; }, ], 'chosenShippingMethods' => [ 'type' => [ 'list_of' => 'String' ], - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $methods = $payload['chosen_shipping_methods']; return ! empty( $methods ) ? $methods : null; }, ], 'cartErrors' => [ 'type' => [ 'list_of' => 'CartError' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $errors = []; $all_error_data = array_merge( $payload['invalid_cart_items'], @@ -150,7 +150,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Throw error, if no cart item data provided. diff --git a/includes/mutation/class-cart-remove-coupons.php b/includes/mutation/class-cart-remove-coupons.php index 342a17d6e..aeaa67344 100644 --- a/includes/mutation/class-cart-remove-coupons.php +++ b/includes/mutation/class-cart-remove-coupons.php @@ -65,7 +65,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input ) { + return static function( $input ) { Cart_Mutation::check_session_token(); // Retrieve product database ID if relay ID provided. diff --git a/includes/mutation/class-cart-remove-items.php b/includes/mutation/class-cart-remove-items.php index d4c7e6479..796f1bd91 100644 --- a/includes/mutation/class-cart-remove-items.php +++ b/includes/mutation/class-cart-remove-items.php @@ -63,7 +63,7 @@ public static function get_output_fields() { return [ 'cartItems' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['items']; }, ], @@ -77,7 +77,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( \WC()->cart->is_empty() ) { diff --git a/includes/mutation/class-cart-restore-items.php b/includes/mutation/class-cart-restore-items.php index 9be834c4e..11aaaa6d9 100644 --- a/includes/mutation/class-cart-restore-items.php +++ b/includes/mutation/class-cart-restore-items.php @@ -65,7 +65,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( empty( $input['keys'] ) ) { diff --git a/includes/mutation/class-cart-update-item-quantities.php b/includes/mutation/class-cart-update-item-quantities.php index 365195c7f..6fffe3bda 100644 --- a/includes/mutation/class-cart-update-item-quantities.php +++ b/includes/mutation/class-cart-update-item-quantities.php @@ -60,7 +60,7 @@ public static function get_output_fields() { return [ 'updated' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $items = []; foreach ( $payload['updated'] as $key ) { $items[] = WC()->cart->get_cart_item( $key ); @@ -71,13 +71,13 @@ public static function get_output_fields() { ], 'removed' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['removed']; }, ], 'items' => [ 'type' => [ 'list_of' => 'CartItem' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $updated = []; foreach ( $payload['updated'] as $key ) { $updated[] = \WC()->cart->get_cart_item( $key ); @@ -96,7 +96,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Confirm "items" exists. @@ -138,7 +138,7 @@ public static function mutate_and_get_payload() { $errors = array_keys( array_filter( array_merge( $removed, $updated ), - function( $value ) { + static function( $value ) { return ! $value; } ) diff --git a/includes/mutation/class-cart-update-shipping-method.php b/includes/mutation/class-cart-update-shipping-method.php index 6fad1d58f..500bcc65c 100644 --- a/includes/mutation/class-cart-update-shipping-method.php +++ b/includes/mutation/class-cart-update-shipping-method.php @@ -64,7 +64,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input ) { + return static function( $input ) { Cart_Mutation::check_session_token(); if ( empty( $input['shippingMethods'] ) ) { diff --git a/includes/mutation/class-checkout.php b/includes/mutation/class-checkout.php index 308f8930b..39f3b3b32 100644 --- a/includes/mutation/class-checkout.php +++ b/includes/mutation/class-checkout.php @@ -99,25 +99,25 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return new Order( $payload['id'] ); }, ], 'customer' => [ 'type' => 'Customer', - 'resolve' => function() { + 'resolve' => static function() { return is_user_logged_in() ? new Customer( get_current_user_id() ) : new Customer(); }, ], 'result' => [ 'type' => 'String', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['result']; }, ], 'redirect' => [ 'type' => 'String', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['redirect']; }, ], @@ -130,7 +130,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Create order. $order = null; try { diff --git a/includes/mutation/class-coupon-create.php b/includes/mutation/class-coupon-create.php index 4d19e4277..53eb9a0f2 100644 --- a/includes/mutation/class-coupon-create.php +++ b/includes/mutation/class-coupon-create.php @@ -137,13 +137,13 @@ public static function get_output_fields() { return [ 'coupon' => [ 'type' => 'Coupon', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return new Coupon( $payload['id'] ); }, ], 'code' => [ 'type' => 'String', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['code']; }, ], diff --git a/includes/mutation/class-coupon-delete.php b/includes/mutation/class-coupon-delete.php index 4501c3e1f..2b437acd1 100644 --- a/includes/mutation/class-coupon-delete.php +++ b/includes/mutation/class-coupon-delete.php @@ -66,7 +66,7 @@ public static function get_output_fields() { [ 'coupon' => [ 'type' => 'Coupon', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return ! empty( $payload['coupon'] ) ? $payload['coupon'] : null; }, ], diff --git a/includes/mutation/class-customer-register.php b/includes/mutation/class-customer-register.php index 798bf0676..86a4877ae 100644 --- a/includes/mutation/class-customer-register.php +++ b/includes/mutation/class-customer-register.php @@ -82,13 +82,13 @@ public static function get_output_fields() { return [ 'customer' => [ 'type' => 'Customer', - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return new Customer( $payload['id'] ); }, ], 'viewer' => [ 'type' => 'User', - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); return false !== $user ? new User( $user ) : null; }, @@ -102,7 +102,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Validate input. if ( empty( $input['email'] ) ) { throw new UserError( __( 'Please provide a valid email address.', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-customer-update.php b/includes/mutation/class-customer-update.php index 99cf05256..372cb177d 100644 --- a/includes/mutation/class-customer-update.php +++ b/includes/mutation/class-customer-update.php @@ -80,7 +80,7 @@ public static function get_output_fields() { return [ 'customer' => [ 'type' => 'Customer', - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return new Customer( $payload['id'] ); }, ], @@ -93,7 +93,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { $session_only = empty( $input['id'] ); $payload = null; diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index c72aa7919..04a4d54af 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -124,13 +124,13 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return new Order( $payload['id'] ); }, ], 'orderId' => [ 'type' => 'Int', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['id']; }, ], @@ -143,7 +143,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Check if authorized to create this order. if ( ! Order_Mutation::authorized( $input, $context, $info, 'create', null ) ) { throw new UserError( __( 'User does not have the capabilities necessary to create an order.', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-order-delete-items.php b/includes/mutation/class-order-delete-items.php index 9b90ea59f..5beab86d0 100644 --- a/includes/mutation/class-order-delete-items.php +++ b/includes/mutation/class-order-delete-items.php @@ -71,7 +71,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['order']; }, ], @@ -84,7 +84,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-order-delete.php b/includes/mutation/class-order-delete.php index 0877b10db..3bfce6ed7 100644 --- a/includes/mutation/class-order-delete.php +++ b/includes/mutation/class-order-delete.php @@ -72,7 +72,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return $payload['order']; }, ], @@ -85,7 +85,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-order-update.php b/includes/mutation/class-order-update.php index c28f179d1..c16c94c1c 100644 --- a/includes/mutation/class-order-update.php +++ b/includes/mutation/class-order-update.php @@ -73,7 +73,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { return new Order( $payload['id'] ); }, ], @@ -86,7 +86,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-payment-method-delete.php b/includes/mutation/class-payment-method-delete.php index cd306faef..06e0f48fd 100644 --- a/includes/mutation/class-payment-method-delete.php +++ b/includes/mutation/class-payment-method-delete.php @@ -65,7 +65,7 @@ public static function get_output_fields() { 'status' => [ 'type' => 'String', 'description' => __( 'Status of the request', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return ! empty( $payload['status'] ) ? $payload['status'] : 'FAILED'; }, ], @@ -78,7 +78,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { global $wp; if ( ! is_user_logged_in() ) { throw new UserError( __( 'Must be authenticated to set a default payment method', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-payment-method-set-default.php b/includes/mutation/class-payment-method-set-default.php index b42844ca1..61ee6a163 100644 --- a/includes/mutation/class-payment-method-set-default.php +++ b/includes/mutation/class-payment-method-set-default.php @@ -64,14 +64,14 @@ public static function get_output_fields() { 'status' => [ 'type' => 'String', 'description' => __( 'Status of the request', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return ! empty( $payload['status'] ) ? $payload['status'] : 'FAILED'; }, ], 'token' => [ 'type' => 'PaymentToken', 'description' => __( 'Preferred payment method token', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { return ! empty( $payload['token'] ) ? $payload['token'] : null; }, ], @@ -84,7 +84,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { global $wp; if ( ! is_user_logged_in() ) { throw new UserError( __( 'Must be authenticated to set a default payment method', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-review-delete-restore.php b/includes/mutation/class-review-delete-restore.php index 3a471f542..b86837cfe 100644 --- a/includes/mutation/class-review-delete-restore.php +++ b/includes/mutation/class-review-delete-restore.php @@ -87,7 +87,7 @@ public static function get_output_fields( $restore = false ) { 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the affected product review', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { if ( ! isset( $payload['rating'] ) ) { return null; } @@ -98,7 +98,7 @@ public static function get_output_fields( $restore = false ) { 'affectedId' => [ 'type' => 'Id', 'description' => __( 'The affected product review ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { $deleted = (object) $payload['commentObject']; return ! empty( $deleted->comment_ID ) ? Relay::toGlobalId( 'comment', (string) $deleted->comment_ID ) : null; @@ -107,7 +107,7 @@ public static function get_output_fields( $restore = false ) { 'review' => [ 'type' => 'Comment', 'description' => __( 'The affected product review', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload, $args, AppContext $context, ResolveInfo $info ) use ( $restore ) { + 'resolve' => static function( $payload, $args, AppContext $context, ResolveInfo $info ) use ( $restore ) { if ( empty( $payload['commentObject'] ) ) { return null; } @@ -130,7 +130,7 @@ public static function get_output_fields( $restore = false ) { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Retrieve the product review rating for the payload. $id_parts = Relay::fromGlobalId( $input['id'] ); if ( empty( $id_parts['id'] ) ) { diff --git a/includes/mutation/class-review-update.php b/includes/mutation/class-review-update.php index 14ccec76a..b75c8dcb0 100644 --- a/includes/mutation/class-review-update.php +++ b/includes/mutation/class-review-update.php @@ -70,7 +70,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Set comment type to "review". $input['type'] = 'review'; diff --git a/includes/mutation/class-review-write.php b/includes/mutation/class-review-write.php index f781e09be..6b612030a 100644 --- a/includes/mutation/class-review-write.php +++ b/includes/mutation/class-review-write.php @@ -69,7 +69,7 @@ public static function get_output_fields() { 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the review that was created', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload ) { + 'resolve' => static function( $payload ) { if ( ! isset( $payload['id'] ) || ! absint( $payload['id'] ) ) { return null; } @@ -79,7 +79,7 @@ public static function get_output_fields() { 'review' => [ 'type' => 'Comment', 'description' => __( 'The product review that was created', 'wp-graphql-woocommerce' ), - 'resolve' => function( $payload, $args, AppContext $context ) { + 'resolve' => static function( $payload, $args, AppContext $context ) { if ( ! isset( $payload['id'] ) || ! absint( $payload['id'] ) ) { return null; } @@ -101,7 +101,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { // Set comment type to "review". $input['type'] = 'review'; diff --git a/includes/mutation/class-update-session.php b/includes/mutation/class-update-session.php index 829d09875..9f087332d 100644 --- a/includes/mutation/class-update-session.php +++ b/includes/mutation/class-update-session.php @@ -61,7 +61,7 @@ public static function get_output_fields() { return [ 'session' => [ 'type' => [ 'list_of' => 'MetaData' ], - 'resolve' => function ( $payload ) { + 'resolve' => static function ( $payload ) { /** * Session handler. * @@ -83,7 +83,7 @@ public static function get_output_fields() { ], 'customer' => [ 'type' => 'Customer', - 'resolve' => function () { + 'resolve' => static function () { return new Customer( 'session' ); }, ], @@ -96,7 +96,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return function( $input, AppContext $context, ResolveInfo $info ) { + return static function( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Guard against missing input. diff --git a/includes/type/enum/class-countries.php b/includes/type/enum/class-countries.php index 827d4f1b8..b9332a6f5 100644 --- a/includes/type/enum/class-countries.php +++ b/includes/type/enum/class-countries.php @@ -22,7 +22,7 @@ public static function register() { $countries = $wc_countries->get_countries(); array_walk( $countries, - function( &$value, $code ) { + static function( &$value, $code ) { $value = [ 'value' => $code ]; } ); diff --git a/includes/type/interface/class-attribute.php b/includes/type/interface/class-attribute.php index c8975ad4a..1db26a122 100644 --- a/includes/type/interface/class-attribute.php +++ b/includes/type/interface/class-attribute.php @@ -28,19 +28,19 @@ public static function register_interface() { 'name' => [ 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, ], 'value' => [ 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['value'] ) ? $source['value'] : null; }, ], ], - 'resolveType' => function( $value ) { + 'resolveType' => static function( $value ) { $type_registry = \WPGraphQL::get_type_registry(); if ( $value->is_taxonomy() ) { return $type_registry->get_type( 'SimpleAttribute' ); diff --git a/includes/type/interface/class-cart-error.php b/includes/type/interface/class-cart-error.php index d2499c54c..75121c947 100644 --- a/includes/type/interface/class-cart-error.php +++ b/includes/type/interface/class-cart-error.php @@ -24,7 +24,7 @@ public static function register_interface() { [ 'description' => __( 'An error that occurred when updating the cart', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), - 'resolveType' => function( array $value ) { + 'resolveType' => static function( array $value ) { $type_registry = \WPGraphQL::get_type_registry(); switch ( $value['type'] ) { case 'INVALID_CART_ITEM': @@ -51,14 +51,14 @@ public static function get_fields() { 'type' => [ 'type' => [ 'non_null' => 'CartErrorType' ], 'description' => __( 'Type of error', 'wp-graphql-woocommerce' ), - 'resolve' => function ( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['type'] ) ? $error['type'] : null; }, ], 'reasons' => [ 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Reason for error', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $error ) { + 'resolve' => static function ( $error ) { return ! empty( $error['reasons'] ) ? $error['reasons'] : [ 'Reasons for error unknown, sorry.' ]; }, ], diff --git a/includes/type/interface/class-payment-token.php b/includes/type/interface/class-payment-token.php index e0e6bfbe8..1afc61233 100644 --- a/includes/type/interface/class-payment-token.php +++ b/includes/type/interface/class-payment-token.php @@ -28,7 +28,7 @@ public static function register_interface() { 'description' => __( 'Payment token object', 'wp-graphql-woocommerce' ), 'interfaces' => [ 'Node' ], 'fields' => self::get_fields(), - 'resolveType' => function( $value ) { + 'resolveType' => static function( $value ) { $type_registry = \WPGraphQL::get_type_registry(); $type = $value->get_type(); switch ( $type ) { @@ -62,28 +62,28 @@ public static function get_fields( $other_fields = [] ) { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Token ID unique identifier', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_id() ) ? Relay::toGlobalId( 'token', $source->get_id() ) : null; }, ], 'tokenId' => [ 'type' => [ 'non_null' => 'Integer' ], 'description' => __( 'Token database ID.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, ], 'type' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Token type', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_type() ) ? $source->get_type() : null; }, ], 'gateway' => [ 'type' => 'PaymentGateway', 'description' => __( 'Token payment gateway', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $gateway_id = $source->get_gateway_id(); return null; }, @@ -91,7 +91,7 @@ public static function get_fields( $other_fields = [] ) { 'isDefault' => [ 'type' => 'Boolean', 'description' => __( 'Is token connected to user\'s preferred payment method', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->is_default() ) ? $source->is_default() : false; }, ], diff --git a/includes/type/interface/class-product-attribute.php b/includes/type/interface/class-product-attribute.php index af19ea355..ecda051f3 100644 --- a/includes/type/interface/class-product-attribute.php +++ b/includes/type/interface/class-product-attribute.php @@ -25,7 +25,7 @@ public static function register_interface() { 'description' => __( 'Product attribute object', 'wp-graphql-woocommerce' ), 'interfaces' => [ 'Node' ], 'fields' => self::get_fields(), - 'resolveType' => function( $value ) { + 'resolveType' => static function( $value ) { $type_registry = \WPGraphQL::get_type_registry(); if ( $value->is_taxonomy() ) { return $type_registry->get_type( 'GlobalProductAttribute' ); @@ -51,28 +51,28 @@ public static function get_fields() { 'attributeId' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Attribute ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_id() ) ? $attribute->get_id() : null; }, ], 'name' => [ 'type' => 'String', 'description' => __( 'Attribute name', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, ], 'label' => [ 'type' => 'String', 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? ucwords( $attribute->get_name() ) : null; }, ], 'options' => [ 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Attribute options', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { $slugs = $attribute->get_slugs(); return ! empty( $slugs ) ? $slugs : null; }, @@ -80,28 +80,28 @@ public static function get_fields() { 'position' => [ 'type' => 'Int', 'description' => __( 'Attribute position', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_position() ) ? $attribute->get_position() : null; }, ], 'visible' => [ 'type' => 'Boolean', 'description' => __( 'Is attribute visible', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_visible() ) ? $attribute->get_visible() : null; }, ], 'variation' => [ 'type' => 'Boolean', 'description' => __( 'Is attribute on product variation', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! is_null( $attribute->get_variation() ) ? $attribute->get_variation() : null; }, ], 'scope' => [ 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return $attribute->is_taxonomy() ? 'global' : 'local'; }, ], diff --git a/includes/type/interface/class-product.php b/includes/type/interface/class-product.php index 4d0f0ab76..dc31f9ed0 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -48,7 +48,7 @@ public static function register_interface() { 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -122,7 +122,7 @@ public static function get_fields() { 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->descriptionRaw; @@ -139,7 +139,7 @@ public static function get_fields() { 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shortDescriptionRaw; @@ -187,7 +187,7 @@ public static function get_fields() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Main image', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { // @codingStandardsIgnoreLine. if ( empty( $source->image_id ) || ! absint( $source->image_id ) ) { return null; diff --git a/includes/type/object/class-cart-error-types.php b/includes/type/object/class-cart-error-types.php index de8d0a265..b12c9f275 100644 --- a/includes/type/object/class-cart-error-types.php +++ b/includes/type/object/class-cart-error-types.php @@ -28,35 +28,35 @@ public static function register() { 'productId' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['productId'] ) ? $error['productId'] : null; }, ], 'quantity' => [ 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['quantity'] ) ? $error['quantity'] : null; }, ], 'variationId' => [ 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['variationId'] ) ? $error['variationId'] : null; }, ], 'variation' => [ 'type' => [ 'list_of' => 'ProductAttributeOutput' ], 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['variation'] ) ? $error['variation'] : null; }, ], 'extraData' => [ 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['extraData'] ) ? $error['extraData'] : null; }, ], @@ -73,7 +73,7 @@ public static function register() { 'code' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code of the coupon the failed to be applied', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['code'] ) ? $error['code'] : null; }, ], @@ -90,14 +90,14 @@ public static function register() { 'package' => [ 'type' => [ 'non_null' => 'Integer' ], 'description' => __( 'Index of package for desired shipping method', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return isset( $error['package'] ) && is_int( $error['package'] ) ? $error['package'] : null; }, ], 'chosenMethod' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'ID of chosen shipping rate', 'wp-graphql-woocommerce' ), - 'resolve' => function( array $error ) { + 'resolve' => static function( array $error ) { return ! empty( $error['chosen_method'] ) ? $error['chosen_method'] : null; }, ], diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index 3bc9a702e..e8c188979 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -55,7 +55,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_subtotal() ) ? $source->get_subtotal() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -74,7 +74,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_subtotal_tax() ) ? $source->get_subtotal_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -93,7 +93,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_discount_total() ) ? $source->get_discount_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -112,7 +112,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_discount_tax() ) ? $source->get_discount_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -125,7 +125,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'availableShippingMethods' => [ 'type' => [ 'list_of' => 'ShippingPackage' ], 'description' => __( 'Available shipping methods for this order.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $packages = []; $available_packages = $source->needs_shipping() @@ -143,7 +143,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'chosenShippingMethods' => [ 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Shipping method chosen for this order.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $chosen_shipping_methods = []; $available_packages = $source->needs_shipping() @@ -168,7 +168,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_shipping_total() ) ? $source->get_shipping_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -187,7 +187,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_shipping_tax() ) ? $source->get_shipping_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -206,7 +206,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { if ( $source->display_prices_including_tax() ) { $cart_subtotal = $source->get_subtotal() + $source->get_subtotal_tax(); } else { @@ -233,7 +233,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_cart_contents_tax() ) ? $source->get_cart_contents_tax() : 0; @@ -254,7 +254,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_fee_total() ) ? $source->get_fee_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -273,7 +273,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_fee_tax() ) ? $source->get_fee_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -292,7 +292,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $source->calculate_totals(); $price = isset( $source->get_totals()['total'] ) ? apply_filters( 'graphql_woocommerce_cart_get_total', $source->get_totals()['total'] ) @@ -314,7 +314,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = ! is_null( $source->get_total_tax() ) ? $source->get_total_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -327,7 +327,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'totalTaxes' => [ 'type' => [ 'list_of' => 'CartTax' ], 'description' => __( 'Cart total taxes itemized', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $taxes = $source->get_tax_totals(); return ! empty( $taxes ) ? array_values( $taxes ) : null; }, @@ -335,14 +335,14 @@ public static function get_cart_fields( $other_fields = [] ) { 'isEmpty' => [ 'type' => 'Boolean', 'description' => __( 'Is cart empty', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->is_empty() ) ? $source->is_empty() : null; }, ], 'displayPricesIncludeTax' => [ 'type' => 'Boolean', 'description' => __( 'Do display prices include taxes', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->display_prices_including_tax() ) ? $source->display_prices_including_tax() : null; @@ -351,7 +351,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'needsShippingAddress' => [ 'type' => 'Boolean', 'description' => __( 'Is customer shipping address needed', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->needs_shipping_address() ) ? $source->needs_shipping_address() : null; @@ -360,7 +360,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'fees' => [ 'type' => [ 'list_of' => 'CartFee' ], 'description' => __( 'Additional fees on the cart.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $fees = $source->get_fees(); return ! empty( $fees ) ? array_values( $fees ) : null; }, @@ -368,7 +368,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'appliedCoupons' => [ 'type' => [ 'list_of' => 'AppliedCoupon' ], 'description' => __( 'Coupons applied to the cart', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $applied_coupons = $source->get_applied_coupons(); return ! empty( $applied_coupons ) ? $applied_coupons : null; @@ -400,7 +400,7 @@ public static function get_cart_connections( $other_connections = [] ) { 'itemCount' => [ 'type' => 'Int', 'description' => __( 'Total number of items in the cart.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -416,7 +416,7 @@ public static function get_cart_connections( $other_connections = [] ) { 'productCount' => [ 'type' => 'Int', 'description' => __( 'Total number of different products in the cart', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -425,7 +425,7 @@ public static function get_cart_connections( $other_connections = [] ) { }, ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Cart_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); @@ -481,14 +481,14 @@ public static function register_cart_item() { 'key' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'CartItem ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['key'] ) ? $source['key'] : null; }, ], 'quantity' => [ 'type' => 'Int', 'description' => __( 'Quantity of the product', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return isset( $source['quantity'] ) ? absint( $source['quantity'] ) : null; }, ], @@ -501,7 +501,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = isset( $source['line_subtotal'] ) ? floatval( $source['line_subtotal'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -520,7 +520,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = isset( $source['line_subtotal_tax'] ) ? floatval( $source['line_subtotal_tax'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -539,7 +539,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : 0; $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; $price = $price_without_tax + $tax; @@ -560,7 +560,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $price = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -583,7 +583,7 @@ public static function register_cart_item() { 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { // Check if "key" argument set and assigns to target "keys" array. if ( ! empty( $args['key'] ) && ! empty( $source[ $args['key'] ] ) ) { $keys = [ $args['key'] ]; @@ -640,7 +640,7 @@ public static function register_cart_item() { 'simpleVariations' => [ 'type' => [ 'list_of' => 'SimpleAttribute' ], 'description' => __( 'Simple variation attribute data', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $attributes = []; $variation = $source['node']; @@ -654,7 +654,7 @@ public static function register_cart_item() { }, ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = $source['product_id']; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -671,7 +671,7 @@ public static function register_cart_item() { 'attributes' => [ 'type' => [ 'list_of' => 'VariationAttribute' ], 'description' => __( 'Attributes of the variation.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $attributes = []; $variation = $source['node']; @@ -689,7 +689,7 @@ public static function register_cart_item() { }, ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = $source['variation_id']; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); @@ -722,42 +722,42 @@ public static function register_cart_fee() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Fee ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->id ) ? $source->id : null; }, ], 'name' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->name ) ? $source->name : null; }, ], 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Fee tax class', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->tax_class ) ? $source->tax_class : null; }, ], 'taxable' => [ 'type' => 'Boolean', 'description' => __( 'Is fee taxable?', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->taxable ) ? $source->taxable : null; }, ], 'amount' => [ 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->amount ) ? $source->amount : 0; }, ], 'total' => [ 'type' => 'Float', 'description' => __( 'Fee total', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! is_null( $source->total ) ? $source->total : 0; }, ], @@ -779,21 +779,21 @@ public static function register_cart_tax() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Tax Rate ID', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->tax_rate_id ) ? $source->tax_rate_id : null; }, ], 'label' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Tax label', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->label ) ? $source->label : null; }, ], 'isCompound' => [ 'type' => 'Boolean', 'description' => __( 'Is tax compound?', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->is_compound ) ? $source->is_compound : null; }, ], @@ -806,7 +806,7 @@ public static function register_cart_tax() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $amount = ! empty( $source->amount ) ? $source->amount : null; if ( ! $amount ) { @@ -839,7 +839,7 @@ public static function register_applied_coupon() { 'code' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return $source; }, ], @@ -856,7 +856,7 @@ public static function register_applied_coupon() { ], ], 'description' => __( 'Discount applied with this coupon', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $ex_tax = ! empty( $args['excludeTax'] ) ? $args['excludeTax'] : true; $amount = Factory::resolve_cart()->get_coupon_discount_amount( $source, $ex_tax ); @@ -876,7 +876,7 @@ public static function register_applied_coupon() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $tax = Factory::resolve_cart()->get_coupon_discount_tax_amount( $source ); if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -889,7 +889,7 @@ public static function register_applied_coupon() { 'description' => [ 'type' => 'String', 'description' => __( 'Description of applied coupon', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $coupon = new \WC_Coupon( $source ); return $coupon->get_description(); }, diff --git a/includes/type/object/class-country-state-type.php b/includes/type/object/class-country-state-type.php index 8d5d26549..f38fc3e9c 100644 --- a/includes/type/object/class-country-state-type.php +++ b/includes/type/object/class-country-state-type.php @@ -29,14 +29,14 @@ public static function register() { 'code' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Country state code', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['code'] ) ? $source['code'] : null; }, ], 'name' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Country state name', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['name'] ) ? $source['name'] : null; }, ], diff --git a/includes/type/object/class-customer-address-type.php b/includes/type/object/class-customer-address-type.php index ff6b99911..7314428e9 100644 --- a/includes/type/object/class-customer-address-type.php +++ b/includes/type/object/class-customer-address-type.php @@ -29,77 +29,77 @@ public static function register() { 'firstName' => [ 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['first_name'] ) ? $address['first_name'] : null; }, ], 'lastName' => [ 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['last_name'] ) ? $address['last_name'] : null; }, ], 'company' => [ 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['company'] ) ? $address['company'] : null; }, ], 'address1' => [ 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['address_1'] ) ? $address['address_1'] : null; }, ], 'address2' => [ 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['address_2'] ) ? $address['address_2'] : null; }, ], 'city' => [ 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['city'] ) ? $address['city'] : null; }, ], 'state' => [ 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['state'] ) ? $address['state'] : null; }, ], 'postcode' => [ 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['postcode'] ) ? $address['postcode'] : null; }, ], 'country' => [ 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['country'] ) ? $address['country'] : null; }, ], 'email' => [ 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['email'] ) ? $address['email'] : null; }, ], 'phone' => [ 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), - 'resolve' => function( $address ) { + 'resolve' => static function( $address ) { return ! empty( $address['phone'] ) ? $address['phone'] : null; }, ], diff --git a/includes/type/object/class-customer-type.php b/includes/type/object/class-customer-type.php index 36033354d..4330ba6f7 100644 --- a/includes/type/object/class-customer-type.php +++ b/includes/type/object/class-customer-type.php @@ -40,7 +40,7 @@ public static function get_fields( $other_fields = [] ) { 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $database_id = absint( $source->ID ); return ! empty( $database_id ) ? $database_id : null; }, @@ -60,7 +60,7 @@ public static function get_fields( $other_fields = [] ) { 'lastOrder' => [ 'type' => 'Order', 'description' => __( 'Gets the customers last order.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->last_order_id, $context ); }, ], @@ -120,7 +120,7 @@ public static function get_fields( $other_fields = [] ) { 'session' => [ 'type' => [ 'list_of' => 'MetaData' ], 'description' => __( 'Session data for the viewing customer', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { /** * Session Handler. * @@ -176,7 +176,7 @@ public static function get_connections( $other_connections = [] ) { 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Downloadable_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); @@ -226,7 +226,7 @@ public static function register() { 'availablePaymentMethods' => [ 'type' => [ 'list_of' => 'PaymentToken' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( get_current_user_id() === $source->ID ) { return array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ); } @@ -237,11 +237,11 @@ public static function register() { 'availablePaymentMethodsCC' => [ 'type' => [ 'list_of' => 'PaymentTokenCC' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( get_current_user_id() === $source->ID ) { $tokens = array_filter( array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ), - function ( $token ) { + static function ( $token ) { return 'CC' === $token->get_type(); } ); @@ -254,11 +254,11 @@ function ( $token ) { 'availablePaymentMethodsEC' => [ 'type' => [ 'list_of' => 'PaymentTokenECheck' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( get_current_user_id() === $source->ID ) { $tokens = array_filter( array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ), - function ( $token ) { + static function ( $token ) { return 'eCheck' === $token->get_type(); } ); @@ -287,7 +287,7 @@ public static function register_session_handler_fields() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( \get_current_user_id() === $source->ID || 'guest' === $source->id ) { /** * Session handler. @@ -312,7 +312,7 @@ public static function register_session_handler_fields() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( \get_current_user_id() === $source->userId ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase /** * Session handler @@ -345,7 +345,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'cartUrl' => [ 'type' => 'String', 'description' => __( 'A nonced link to the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -371,7 +371,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'cartNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -395,7 +395,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'checkoutUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the checkout page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -421,7 +421,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'checkoutNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the checkout page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -445,7 +445,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'accountUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the account page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -475,7 +475,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'accountNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the account page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -503,7 +503,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'addPaymentMethodUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the add payment method page for the authenticated user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -533,7 +533,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'addPaymentMethodNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the add payment method page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { if ( ! is_user_logged_in() ) { return null; } diff --git a/includes/type/object/class-downloadable-item-type.php b/includes/type/object/class-downloadable-item-type.php index d3829e84b..6a835ad0d 100644 --- a/includes/type/object/class-downloadable-item-type.php +++ b/includes/type/object/class-downloadable-item-type.php @@ -35,35 +35,35 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Downloadable item unique identifier', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['download_id'] ) ? Relay::toGlobalId( 'download', $source['download_id'] ) : null; }, ], 'downloadId' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Downloadable item ID.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['download_id'] ) ? $source['download_id'] : null; }, ], 'url' => [ 'type' => 'String', 'description' => __( 'Download URL of the downloadable item.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['download_url'] ) ? $source['download_url'] : null; }, ], 'name' => [ 'type' => 'String', 'description' => __( 'Name of the downloadable item.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['download_name'] ) ? $source['download_name'] : null; }, ], 'downloadsRemaining' => [ 'type' => 'Int', 'description' => __( 'Number of times the item can be downloaded.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['downloads_remaining'] ) && 'integer' === gettype( $source['downloads_remaining'] ) ? $source['downloads_remaining'] : null; @@ -72,21 +72,21 @@ public static function register() { 'accessExpires' => [ 'type' => 'String', 'description' => __( 'The date the downloadable item expires', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['access_expires'] ) ? $source['access_expires'] : null; }, ], 'product' => [ 'type' => 'Product', 'description' => __( 'Product of downloadable item.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source['product_id'], $context ); }, ], 'download' => [ 'type' => 'ProductDownload', 'description' => __( 'ProductDownload of the downloadable item', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { $download_id = $source['download_id']; $product_id = $source['product_id']; $files = array_filter( (array) get_post_meta( $product_id, '_downloadable_files', true ) ); diff --git a/includes/type/object/class-meta-data-type.php b/includes/type/object/class-meta-data-type.php index c0b1b126c..bba4e69ae 100644 --- a/includes/type/object/class-meta-data-type.php +++ b/includes/type/object/class-meta-data-type.php @@ -31,21 +31,21 @@ public static function register() { 'id' => [ 'type' => 'ID', 'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, ], 'key' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->key ) ? (string) $source->key : null; }, ], 'value' => [ 'type' => 'String', 'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { if ( empty( $source->value ) ) { return null; } @@ -85,7 +85,7 @@ public static function get_metadata_field_definition() { 'description' => __( 'Retrieve meta with matching keys', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { // Set unique flag. $single = ! empty( $args['multiple'] ) ? false : true; @@ -95,7 +95,7 @@ public static function get_metadata_field_definition() { if ( ! is_array( $data ) ) { $data = array_filter( $source->get_meta_data(), - function( $meta ) use ( $data ) { + static function( $meta ) use ( $data ) { return $meta->value === $data; } ); @@ -107,7 +107,7 @@ function( $meta ) use ( $data ) { $found = []; $data = array_filter( $source->get_meta_data(), - function( $meta ) use ( $keys, $single, &$found ) { + static function( $meta ) use ( $keys, $single, &$found ) { if ( in_array( $meta->key, $keys, true ) ) { if ( $single ) { if ( ! in_array( $meta->key, $found, true ) ) { @@ -125,7 +125,7 @@ function( $meta ) use ( $keys, $single, &$found ) { $found = []; $data = array_filter( $source->get_meta_data(), - function( $meta ) use ( $single, &$found ) { + static function( $meta ) use ( $single, &$found ) { if ( $single ) { if ( ! in_array( $meta->key, $found, true ) ) { $found[] = $meta->key; diff --git a/includes/type/object/class-order-item-type.php b/includes/type/object/class-order-item-type.php index 179427cf6..4772e7c91 100644 --- a/includes/type/object/class-order-item-type.php +++ b/includes/type/object/class-order-item-type.php @@ -46,7 +46,7 @@ public static function register() { 'coupon' => [ 'type' => 'Coupon', 'description' => __( 'Line\'s Coupon', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->coupon_id, $context ); }, ], @@ -115,7 +115,7 @@ public static function register() { 'shippingMethod' => [ 'type' => 'ShippingMethod', 'description' => __( 'Shipping Line\'s shipping method', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return Factory::resolve_shipping_method( $source->method_id ); }, ], @@ -149,7 +149,7 @@ public static function register() { 'taxRate' => [ 'type' => 'TaxRate', 'description' => __( 'Tax line\'s tax rate', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { return Factory::resolve_tax_rate( $source->rate_id, $context ); }, ], @@ -210,7 +210,7 @@ public static function register() { 'product' => [ 'toType' => 'Product', 'oneToOne' => true, - 'resolve' => function ( $source, array $args, AppContext $context, $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, $info ) { $id = $source->productId; // @phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -223,7 +223,7 @@ public static function register() { 'variation' => [ 'toType' => 'ProductVariation', 'oneToOne' => true, - 'resolve' => function ( $source, array $args, AppContext $context, $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, $info ) { $id = $source->variationId; // @phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); @@ -263,35 +263,35 @@ public static function register() { 'taxLineId' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Order item ID for tax line connected to this statement', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['ID'] ) ? $source['ID'] : null; }, ], 'subtotal' => [ 'type' => 'Float', 'description' => __( 'Subtotal', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['subtotal'] ) ? $source['subtotal'] : null; }, ], 'total' => [ 'type' => 'Float', 'description' => __( 'Total', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['total'] ) ? $source['total'] : null; }, ], 'amount' => [ 'type' => 'Float', 'description' => __( 'Amount taxed', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['amount'] ) ? $source['amount'] : null; }, ], 'taxLine' => [ 'type' => 'TaxLine', 'description' => __( 'Tax line connected to this statement', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $item = \WC_Order_Factory::get_order_item( $source['ID'] ); // Return early if the item is not found. if ( false === $item ) { diff --git a/includes/type/object/class-order-type.php b/includes/type/object/class-order-type.php index c53fb61e7..f520129e1 100644 --- a/includes/type/object/class-order-type.php +++ b/includes/type/object/class-order-type.php @@ -131,7 +131,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->discountTotalRaw; @@ -150,7 +150,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->discountTaxRaw; @@ -169,7 +169,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shippingTotalRaw; @@ -188,7 +188,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shippingTaxRaw; @@ -207,7 +207,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->cartTaxRaw; @@ -226,7 +226,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->totalRaw; @@ -244,7 +244,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->totalTaxRaw; @@ -263,7 +263,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->subtotalRaw; @@ -311,14 +311,14 @@ public static function get_fields( $other_fields = [] ) { 'parent' => [ 'type' => 'Order', 'description' => __( 'Parent order', 'wp-graphql-woocommerce' ), - 'resolve' => function( $order, array $args, AppContext $context ) { + 'resolve' => static function( $order, array $args, AppContext $context ) { return Factory::resolve_crud_object( $order->parent_id, $context ); }, ], 'customer' => [ 'type' => 'Customer', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), - 'resolve' => function( $order, array $args, AppContext $context ) { + 'resolve' => static function( $order, array $args, AppContext $context ) { if ( empty( $order->customer_id ) ) { // Guest orders don't have an attached customer. return null; @@ -411,7 +411,7 @@ public static function get_connections( $other_connections = [] ) { 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Downloadable_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); diff --git a/includes/type/object/class-payment-gateway-type.php b/includes/type/object/class-payment-gateway-type.php index bc24beb00..eddf6ff9e 100644 --- a/includes/type/object/class-payment-gateway-type.php +++ b/includes/type/object/class-payment-gateway-type.php @@ -30,28 +30,28 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->id ) ? $source->id : null; }, ], 'title' => [ 'type' => 'String', 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->title ) ? $source->title : null; }, ], 'description' => [ 'type' => 'String', 'description' => __( 'gateway\'s description', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->description ) ? $source->description : null; }, ], 'icon' => [ 'type' => 'String', 'description' => __( 'gateway\'s icon', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->icon ) ? $source->icon : null; }, ], diff --git a/includes/type/object/class-payment-token-types.php b/includes/type/object/class-payment-token-types.php index da64a5d6e..86f5e7682 100644 --- a/includes/type/object/class-payment-token-types.php +++ b/includes/type/object/class-payment-token-types.php @@ -52,7 +52,7 @@ public static function get_e_check_fields() { 'last4' => [ 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored account number', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, ], @@ -68,28 +68,28 @@ public static function get_credit_card_fields() { 'cardType' => [ 'type' => 'String', 'description' => __( 'Card type (visa, mastercard, etc)', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_card_type() ) ? $source->get_card_type() : null; }, ], 'expiryYear' => [ 'type' => 'String', 'description' => __( 'Card\'s expiration year.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_expiry_year() ) ? $source->get_expiry_year() : null; }, ], 'expiryMonth' => [ 'type' => 'String', 'description' => __( 'Card\'s expiration month', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_expiry_month() ) ? $source->get_expiry_month() : null; }, ], 'last4' => [ 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored credit card number', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, ], diff --git a/includes/type/object/class-product-attribute-types.php b/includes/type/object/class-product-attribute-types.php index 0a201ae1c..d14f65401 100644 --- a/includes/type/object/class-product-attribute-types.php +++ b/includes/type/object/class-product-attribute-types.php @@ -31,14 +31,14 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! empty( $attribute->_relay_id ) ? $attribute->_relay_id : Relay::toGlobalId( 'LocalProductAttribute', $attribute->get_id() ); }, ], 'scope' => [ 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), - 'resolve' => function () { + 'resolve' => static function () { return 'local'; }, ], @@ -56,21 +56,21 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! empty( $attribute->_relay_id ) ? $attribute->_relay_id : Relay::toGlobalId( 'GlobalProductAttribute', $attribute->get_id() ); }, ], 'scope' => [ 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), - 'resolve' => function () { + 'resolve' => static function () { return 'global'; }, ], 'label' => [ 'type' => 'String', 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { $taxonomy = get_taxonomy( $attribute->get_name() ); return $taxonomy ? ucwords( $taxonomy->labels->singular_name ) : null; }, @@ -78,7 +78,7 @@ public static function register() { 'name' => [ 'type' => 'String', 'description' => __( 'Product attribute name', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { $taxonomy = get_taxonomy( $attribute->get_name() ); return $taxonomy ? $taxonomy->labels->singular_name : null; @@ -87,7 +87,7 @@ public static function register() { 'slug' => [ 'type' => 'String', 'description' => __( 'Product attribute slug', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $attribute ) { + 'resolve' => static function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, ], @@ -104,14 +104,14 @@ public static function register() { 'attributeName' => [ 'type' => 'String', 'description' => __( 'Attribute name.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( array $attribute ) { + 'resolve' => static function ( array $attribute ) { return ! empty( $attribute['attributeName'] ) ? $attribute['attributeName'] : null; }, ], 'attributeValue' => [ 'type' => 'String', 'description' => __( 'Attribute value.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( array $attribute ) { + 'resolve' => static function ( array $attribute ) { return ! empty( $attribute['attributeValue'] ) ? $attribute['attributeValue'] : null; }, ], diff --git a/includes/type/object/class-product-category-type.php b/includes/type/object/class-product-category-type.php index 240f6b329..1e93584f7 100644 --- a/includes/type/object/class-product-category-type.php +++ b/includes/type/object/class-product-category-type.php @@ -29,7 +29,7 @@ public static function register_fields() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product category image', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { $thumbnail_id = get_term_meta( $source->term_id, 'thumbnail_id', true ); return ! empty( $thumbnail_id ) ? $context->get_loader( 'post' )->load_deferred( $thumbnail_id ) @@ -39,7 +39,7 @@ public static function register_fields() { 'display' => [ 'type' => 'ProductCategoryDisplay', 'description' => __( 'Product category display type', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { $display = get_term_meta( $source->term_id, 'display_type', true ); return ! empty( $display ) ? $display : 'default'; }, @@ -47,7 +47,7 @@ public static function register_fields() { 'menuOrder' => [ 'type' => 'Integer', 'description' => __( 'Product category menu order', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { $order = get_term_meta( $source->term_id, 'order', true ); return ! empty( $order ) ? $order : 0; }, diff --git a/includes/type/object/class-product-download-type.php b/includes/type/object/class-product-download-type.php index 109498b75..53f2e686c 100644 --- a/includes/type/object/class-product-download-type.php +++ b/includes/type/object/class-product-download-type.php @@ -29,56 +29,56 @@ public static function register() { 'downloadId' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Product download ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_id() : null; }, ], 'name' => [ 'type' => 'String', 'description' => __( 'Product download name', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_name() : null; }, ], 'filePathType' => [ 'type' => 'String', 'description' => __( 'Type of file path set', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_type_of_file_path() : null; }, ], 'fileType' => [ 'type' => 'String', 'description' => __( 'File type', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file_type() : null; }, ], 'fileExt' => [ 'type' => 'String', 'description' => __( 'File extension', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file_extension() : null; }, ], 'allowedFileType' => [ 'type' => 'Boolean', 'description' => __( 'Is file allowed', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->is_allowed_filetype() : null; }, ], 'fileExists' => [ 'type' => 'Boolean', 'description' => __( 'Validate file exists', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->file_exists() : null; }, ], 'file' => [ 'type' => 'String', 'description' => __( 'Download file', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $download ) { + 'resolve' => static function ( $download ) { return ! empty( $download ) ? $download->get_file() : null; }, ], diff --git a/includes/type/object/class-product-types.php b/includes/type/object/class-product-types.php index 8ef245e57..e1b4b3317 100644 --- a/includes/type/object/class-product-types.php +++ b/includes/type/object/class-product-types.php @@ -159,7 +159,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->priceRaw; @@ -177,7 +177,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->regularPriceRaw; @@ -196,7 +196,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->salePriceRaw; @@ -351,7 +351,7 @@ private static function register_group_product_type() { 'price' => [ 'type' => 'String', 'description' => __( 'Products\' price range', 'wp-graphql-woocommerce' ), - 'resolve' => function( Model $source ) { + 'resolve' => static function( Model $source ) { $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); $child_prices = []; $children = array_filter( array_map( 'wc_get_product', $source->grouped_ids ) ); @@ -409,7 +409,7 @@ private static function register_unsupported_product_type() { 'type' => [ 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - 'resolve' => function () { + 'resolve' => static function () { return 'unsupported'; }, ], diff --git a/includes/type/object/class-product-variation-type.php b/includes/type/object/class-product-variation-type.php index 3950bb27f..d8e16859c 100644 --- a/includes/type/object/class-product-variation-type.php +++ b/includes/type/object/class-product-variation-type.php @@ -74,7 +74,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->priceRaw; @@ -92,7 +92,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->regularPriceRaw; @@ -111,7 +111,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function( $source, $args ) { + 'resolve' => static function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->salePriceRaw; @@ -232,7 +232,7 @@ public static function register() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { return ! empty( $source->image_id ) ? $context->get_loader( 'post' )->load_deferred( $source->image_id ) : null; diff --git a/includes/type/object/class-refund-type.php b/includes/type/object/class-refund-type.php index e4c8cc538..bcc93e7c1 100644 --- a/includes/type/object/class-refund-type.php +++ b/includes/type/object/class-refund-type.php @@ -56,7 +56,7 @@ public static function register() { 'refundedBy' => [ 'type' => 'User', 'description' => __( 'User who completed the refund', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { $user_id = absint( $source->refunded_by_id ); if ( 0 !== $user_id ) { return $context->get_loader( 'user' )->load( $user_id ); diff --git a/includes/type/object/class-root-query.php b/includes/type/object/class-root-query.php index 08b0346f1..a65eed078 100644 --- a/includes/type/object/class-root-query.php +++ b/includes/type/object/class-root-query.php @@ -38,7 +38,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => function( $_, $args ) { + 'resolve' => static function( $_, $args ) { $token_invalid = apply_filters( 'graphql_woocommerce_session_token_errors', null ); if ( $token_invalid ) { throw new UserError( $token_invalid ); @@ -60,7 +60,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args, AppContext $context ) { + 'resolve' => static function( $source, array $args, AppContext $context ) { $item = Factory::resolve_cart()->get_cart_item( $args['key'] ); if ( empty( $item ) || empty( $item['key'] ) ) { throw new UserError( __( 'Failed to retrieve cart item.', 'wp-graphql-woocommerce' ) ); @@ -77,7 +77,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source, array $args ) { + 'resolve' => static function( $source, array $args ) { $fees = Factory::resolve_cart()->get_fees(); $fee_id = $args['id']; @@ -98,7 +98,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify coupon', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -159,7 +159,7 @@ public static function register_fields() { 'description' => __( 'Get the customer by their database ID', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $customer_id = 0; if ( ! empty( $args['id'] ) ) { $id_components = Relay::fromGlobalId( $args['id'] ); @@ -199,7 +199,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify order', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -277,7 +277,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -323,7 +323,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify refund', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -404,7 +404,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -439,7 +439,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify tax rate', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -464,7 +464,7 @@ public static function register_fields() { 'allowedCountries' => [ 'type' => [ 'list_of' => 'CountriesEnum' ], 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), - 'resolve' => function() { + 'resolve' => static function() { $wc_countries = new \WC_Countries(); $countries = $wc_countries->get_allowed_countries(); @@ -480,7 +480,7 @@ public static function register_fields() { ], ], 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), - 'resolve' => function( $_, $args ) { + 'resolve' => static function( $_, $args ) { $country = $args['country']; $wc_countries = new \WC_Countries(); $states = $wc_countries->get_shipping_country_states(); @@ -544,7 +544,7 @@ public static function register_fields() { 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $type_key, $unsupported_type_enabled ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $type_key, $unsupported_type_enabled ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; diff --git a/includes/type/object/class-shipping-package-type.php b/includes/type/object/class-shipping-package-type.php index 70760f095..09c91e57b 100644 --- a/includes/type/object/class-shipping-package-type.php +++ b/includes/type/object/class-shipping-package-type.php @@ -29,7 +29,7 @@ public static function register() { 'packageDetails' => [ 'type' => 'String', 'description' => __( 'Shipping package details', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { $product_names = []; foreach ( $source['contents'] as $item_id => $values ) { $product_names[ $item_id ] = html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); @@ -44,14 +44,14 @@ public static function register() { 'rates' => [ 'type' => [ 'list_of' => 'ShippingRate' ], 'description' => __( 'Shipping package rates', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { return ! empty( $source['rates'] ) ? $source['rates'] : null; }, ], 'supportsShippingCalculator' => [ 'type' => 'Boolean', 'description' => __( 'This shipping package supports the shipping calculator.', 'wp-graphql-woocommerce' ), - 'resolve' => function( $source ) { + 'resolve' => static function( $source ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound return apply_filters( 'woocommerce_shipping_show_shipping_calculator', true, $source['index'], $source ); }, diff --git a/includes/type/object/class-shipping-rate-type.php b/includes/type/object/class-shipping-rate-type.php index b77851774..f50c30c70 100644 --- a/includes/type/object/class-shipping-rate-type.php +++ b/includes/type/object/class-shipping-rate-type.php @@ -29,35 +29,35 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Shipping rate ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, ], 'methodId' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Shipping method ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_method_id() ) ? $source->get_method_id() : null; }, ], 'instanceId' => [ 'type' => 'Int', 'description' => __( 'Shipping instance ID', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_instance_id() ) ? $source->get_instance_id() : null; }, ], 'label' => [ 'type' => 'String', 'description' => __( 'Shipping rate label', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_label() ) ? $source->get_label() : null; }, ], 'cost' => [ 'type' => 'String', 'description' => __( 'Shipping rate cost', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_cost() ) ? $source->get_cost() : null; }, ], diff --git a/includes/type/object/class-variation-attribute-type.php b/includes/type/object/class-variation-attribute-type.php index 590df5ef1..3b8e0c974 100644 --- a/includes/type/object/class-variation-attribute-type.php +++ b/includes/type/object/class-variation-attribute-type.php @@ -30,21 +30,21 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The Global ID of the attribute.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['id'] ) ? $source['id'] : null; }, ], 'attributeId' => [ 'type' => 'Int', 'description' => __( 'The Database ID of the attribute.', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['attributeId'] ) ? $source['attributeId'] : null; }, ], 'label' => [ 'type' => 'String', 'description' => __( 'Label of attribute', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { if ( ! isset( $source['name'] ) ) { return null; } @@ -56,14 +56,14 @@ public static function register() { 'name' => [ 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, ], 'value' => [ 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), - 'resolve' => function ( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['value'] ) ? $source['value'] : null; }, ], diff --git a/includes/utils/class-ql-session-handler.php b/includes/utils/class-ql-session-handler.php index f1ed34927..af02f4bc5 100644 --- a/includes/utils/class-ql-session-handler.php +++ b/includes/utils/class-ql-session-handler.php @@ -164,7 +164,7 @@ public function init_session_token() { if ( is_wp_error( $token ) ) { add_filter( 'graphql_woocommerce_session_token_errors', - function( $errors ) use ( $token ) { + static function( $errors ) use ( $token ) { $errors = $token->get_error_message(); return $errors; } diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index 5953b2afb..4da0e431b 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -124,7 +124,7 @@ function init() { foreach ( $not_ready as $dep ) { add_action( 'admin_notices', - function() use ( $dep ) { + static function() use ( $dep ) { ?>