Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: use static closures when possible #764

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 19 additions & 19 deletions composer.lock

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

10 changes: 5 additions & 5 deletions includes/admin/class-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
),
Expand All @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions includes/class-jwt-auth-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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 );
},
Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wp-graphql-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions includes/connection/class-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -47,15 +47,15 @@ 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 );
return $rating ? $rating : 0;
},
],
],
'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' );
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-coupons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/connection/class-customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand All @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions includes/connection/class-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-payment-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-product-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Loading