Skip to content

Commit d4927b9

Browse files
authored
fix: use static closures when possible (#764)
* fix!: update deps to required versions * fix: use static closures when possible
1 parent fa8e300 commit d4927b9

File tree

80 files changed

+340
-340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+340
-340
lines changed

includes/admin/class-general.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function get_fields() {
102102
),
103103
'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ),
104104
'disabled' => $enable_auth_urls_hardcoded ? true : false,
105-
'sanitize_callback' => function( $value ) {
105+
'sanitize_callback' => static function( $value ) {
106106
if ( empty( $value ) ) {
107107
return [];
108108
}
@@ -131,7 +131,7 @@ public static function get_fields() {
131131
'type' => 'text',
132132
'value' => $cart_url_hardcoded ? CART_URL_NONCE_PARAM : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
133133
'disabled' => defined( 'CART_URL_NONCE_PARAM' ) || ! in_array( 'cart_url', $enabled_authorizing_url_fields, true ),
134-
'sanitize_callback' => function ( $value ) {
134+
'sanitize_callback' => static function ( $value ) {
135135
$other_nonces = self::get_other_nonce_values( 'cart_url' );
136136
if ( in_array( $value, $other_nonces, true ) ) {
137137
add_settings_error(
@@ -155,7 +155,7 @@ public static function get_fields() {
155155
'type' => 'text',
156156
'value' => $checkout_url_hardcoded ? CHECKOUT_URL_NONCE_PARAM : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
157157
'disabled' => defined( 'CHECKOUT_URL_NONCE_PARAM' ) || ! in_array( 'checkout_url', $enabled_authorizing_url_fields, true ),
158-
'sanitize_callback' => function ( $value ) {
158+
'sanitize_callback' => static function ( $value ) {
159159
$other_nonces = self::get_other_nonce_values( 'checkout_url' );
160160
if ( in_array( $value, $other_nonces, true ) ) {
161161
add_settings_error(
@@ -179,7 +179,7 @@ public static function get_fields() {
179179
'type' => 'text',
180180
'value' => $account_url_hardcoded ? ACCOUNT_URL_NONCE_PARAM : woographql_setting( 'account_url_nonce_param', '_wc_account' ),
181181
'disabled' => defined( 'ACCOUNT_URL_NONCE_PARAM' ) || ! in_array( 'account_url', $enabled_authorizing_url_fields, true ),
182-
'sanitize_callback' => function ( $value ) {
182+
'sanitize_callback' => static function ( $value ) {
183183
$other_nonces = self::get_other_nonce_values( 'account_url' );
184184
if ( in_array( $value, $other_nonces, true ) ) {
185185
add_settings_error(
@@ -203,7 +203,7 @@ public static function get_fields() {
203203
'type' => 'text',
204204
'value' => $add_payment_method_url_hardcoded ? ADD_PAYMENT_METHOD_URL_NONCE_PARAM : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
205205
'disabled' => defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) || ! in_array( 'add_payment_method_url', $enabled_authorizing_url_fields, true ),
206-
'sanitize_callback' => function ( $value ) {
206+
'sanitize_callback' => static function ( $value ) {
207207
$other_nonces = self::get_other_nonce_values( 'add_payment_method_url' );
208208
if ( in_array( $value, $other_nonces, true ) ) {
209209
add_settings_error(

includes/class-core-schema-filters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public static function inject_union_types( $config, $wp_union ) {
306306
$config['typeNames'] = array_merge(
307307
array_filter(
308308
$config['typeNames'],
309-
function( $type ) {
309+
static function( $type ) {
310310
return 'Product' !== $type;
311311
}
312312
),
@@ -318,7 +318,7 @@ function( $type ) {
318318

319319
// Update 'types' callback.
320320
if ( $refresh_callback ) {
321-
$config['types'] = function () use ( $config, $wp_union ) {
321+
$config['types'] = static function () use ( $config, $wp_union ) {
322322
$prepared_types = [];
323323
foreach ( $config['typeNames'] as $type_name ) {
324324
$prepared_types[] = $wp_union->type_registry->get_type( $type_name );

includes/class-jwt-auth-schema-filters.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry )
6161
'authToken' => [
6262
'type' => $type_registry->get_type( 'String' ),
6363
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ),
64-
'resolve' => function( $payload ) {
64+
'resolve' => static function( $payload ) {
6565
$user = get_user_by( 'ID', $payload['id'] );
6666

6767
if ( ! $user ) {
@@ -85,7 +85,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry )
8585
'refreshToken' => [
8686
'type' => $type_registry->get_type( 'String' ),
8787
'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' ),
88-
'resolve' => function( $payload ) {
88+
'resolve' => static function( $payload ) {
8989
$user = get_user_by( 'ID', $payload['id'] );
9090

9191
if ( ! $user ) {
@@ -124,7 +124,7 @@ public static function add_customer_to_login_payload() {
124124
[
125125
'type' => 'Customer',
126126
'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ),
127-
'resolve' => function( $payload ) {
127+
'resolve' => static function( $payload ) {
128128
$id = $payload['id'];
129129
return new Customer( $id );
130130
},
@@ -138,7 +138,7 @@ public static function add_customer_to_login_payload() {
138138
[
139139
'type' => 'String',
140140
'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ),
141-
'resolve' => function( $payload ) {
141+
'resolve' => static function( $payload ) {
142142
/**
143143
* Session Handler.
144144
*

includes/class-wp-graphql-woocommerce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private function includes() {
360360
if ( ! class_exists( 'Firebase\JWT\JWT' ) ) {
361361
add_action(
362362
'admin_notices',
363-
function () {
363+
static function () {
364364
if ( ! current_user_can( 'manage_options' ) ) {
365365
return;
366366
}

includes/connection/class-comments.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function register_connections() {
3434
'averageRating' => [
3535
'type' => 'Float',
3636
'description' => __( 'Average review rating for this product.', 'wp-graphql-woocommerce' ),
37-
'resolve' => function( $source ) {
37+
'resolve' => static function( $source ) {
3838
if ( empty( $source['edges'] ) ) {
3939
return 0;
4040
}
@@ -47,15 +47,15 @@ public static function register_connections() {
4747
'rating' => [
4848
'type' => 'Float',
4949
'description' => __( 'Review rating', 'wp-graphql-woocommerce' ),
50-
'resolve' => function( $source ) {
50+
'resolve' => static function( $source ) {
5151
$review = $source['node'];
5252
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
5353
$rating = get_comment_meta( $review->commentId, 'rating', true );
5454
return $rating ? $rating : 0;
5555
},
5656
],
5757
],
58-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
58+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) {
5959
$resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info );
6060

6161
$resolver->set_query_arg( 'post_type', 'product' );
@@ -78,14 +78,14 @@ public static function register_connections() {
7878
'isCustomerNote' => [
7979
'type' => 'Boolean',
8080
'description' => __( 'Is this a customer note?', 'wp-graphql-woocommerce' ),
81-
'resolve' => function( $source ) {
81+
'resolve' => static function( $source ) {
8282
$note = $source['node'];
8383
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
8484
return get_comment_meta( $note->commentId, 'is_customer_note', true );
8585
},
8686
],
8787
],
88-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
88+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) {
8989
$resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info );
9090

9191
$resolver->set_query_arg( 'post_id', $source->ID );

includes/connection/class-coupons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function get_connection_config( $args = [] ): array {
4343
'toType' => 'Coupon',
4444
'fromFieldName' => 'coupons',
4545
'connectionArgs' => self::get_connection_args(),
46-
'resolve' => function ( $source, $args, $context, $info ) {
46+
'resolve' => static function ( $source, $args, $context, $info ) {
4747
$resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'shop_coupon' );
4848

4949
if ( ! self::should_execute() ) {

includes/connection/class-customers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function register_connections() {
3232
'toType' => 'Customer',
3333
'fromFieldName' => 'customers',
3434
'connectionArgs' => self::get_connection_args(),
35-
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
35+
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
3636
$resolver = new UserConnectionResolver( $source, $args, $context, $info );
3737

3838
if ( ! self::should_execute() ) {
@@ -55,7 +55,7 @@ public static function register_connections() {
5555
'toType' => 'Customer',
5656
'fromFieldName' => 'usedBy',
5757
'connectionArgs' => self::get_connection_args(),
58-
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
58+
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
5959
$resolver = new UserConnectionResolver( $source, $args, $context, $info );
6060

6161
$resolver->set_query_arg( 'include', $source->used_by_ids );

includes/connection/class-orders.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function register_connections() {
3737
[
3838
'fromType' => 'Customer',
3939
'fromFieldName' => 'orders',
40-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
40+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) {
4141
$resolver = new Order_Connection_Resolver( $source, $args, $context, $info );
4242

4343
return self::get_customer_order_connection( $resolver, $source );
@@ -65,7 +65,7 @@ public static function register_connections() {
6565
'toType' => 'Refund',
6666
'fromFieldName' => 'refunds',
6767
'connectionArgs' => self::get_refund_connection_args(),
68-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
68+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) {
6969
$resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' );
7070

7171
$resolver->set_should_execute( true );
@@ -85,7 +85,7 @@ public static function register_connections() {
8585
'toType' => 'Refund',
8686
'fromFieldName' => 'refunds',
8787
'connectionArgs' => self::get_refund_connection_args(),
88-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) {
88+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) {
8989
$resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' );
9090

9191
return self::get_customer_refund_connection( $resolver, $source );
@@ -215,7 +215,7 @@ public static function get_connection_config( $args = [], $post_type = 'shop_ord
215215
'toType' => 'Order',
216216
'fromFieldName' => 'orders',
217217
'connectionArgs' => self::get_connection_args( 'private' ),
218-
'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) {
218+
'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) {
219219
// Check if user shop manager.
220220
$not_manager = ! current_user_can( $post_object->cap->edit_posts );
221221

includes/connection/class-payment-gateways.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function get_connection_config( $args = [] ): array {
4141
'toType' => 'PaymentGateway',
4242
'fromFieldName' => 'paymentGateways',
4343
'connectionArgs' => self::get_connection_args(),
44-
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
44+
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
4545
$resolver = new Payment_Gateway_Connection_Resolver();
4646

4747
return $resolver->resolve( $source, $args, $context, $info );

includes/connection/class-posts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function register_connections() {
3030
'fromType' => 'Product',
3131
'toType' => 'MediaItem',
3232
'fromFieldName' => 'galleryImages',
33-
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
33+
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
3434
$resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'attachment' );
3535
$resolver->set_query_arg( 'post_type', 'attachment' );
3636
$resolver->set_query_arg( 'post__in', $source->gallery_image_ids );

0 commit comments

Comments
 (0)