From 9773228617688f1f16bbcc3693c70bae1b1fe216 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 26 Aug 2022 14:20:48 -0400 Subject: [PATCH 1/3] chore: WPGraphQL v1.9x + WP Bedrock support added. --- access-functions.php | 351 +++++------ bin/_lib.sh | 7 +- composer.json | 13 - composer.lock | 2 +- includes/class-acf-schema-filters.php | 4 +- includes/class-core-schema-filters.php | 44 +- includes/class-jwt-auth-schema-filters.php | 36 +- includes/class-type-registry.php | 196 +++---- includes/class-woocommerce-filters.php | 12 +- includes/class-wp-graphql-woocommerce.php | 214 ++++++- includes/connection/class-comments.php | 36 +- includes/connection/class-coupons.php | 18 +- includes/connection/class-customers.php | 56 +- includes/connection/class-orders.php | 147 ++--- .../connection/class-payment-gateways.php | 14 +- includes/connection/class-posts.php | 4 +- .../connection/class-product-attributes.php | 22 +- includes/connection/class-products.php | 348 +++++------ .../connection/class-shipping-methods.php | 8 +- includes/connection/class-tax-rates.php | 30 +- .../connection/class-variation-attributes.php | 15 +- includes/connection/class-wc-terms.php | 22 +- .../connection/wc-cpt-connection-args.php | 60 +- includes/data/class-factory.php | 10 +- .../class-cart-item-connection-resolver.php | 64 +-- .../class-coupon-connection-resolver.php | 13 +- .../class-customer-connection-resolver.php | 28 +- ...-downloadable-item-connection-resolver.php | 63 +- .../class-order-connection-resolver.php | 19 +- .../class-order-item-connection-resolver.php | 8 +- ...ss-payment-gateway-connection-resolver.php | 2 +- ...-product-attribute-connection-resolver.php | 4 +- .../class-product-connection-resolver.php | 120 ++-- .../class-refund-connection-resolver.php | 18 +- ...ss-shipping-method-connection-resolver.php | 4 +- .../class-tax-rate-connection-resolver.php | 12 +- ...ariation-attribute-connection-resolver.php | 16 +- .../connection/trait-wc-cpt-loader-common.php | 13 +- includes/data/loader/class-wc-cpt-loader.php | 16 +- .../data/loader/class-wc-customer-loader.php | 8 +- includes/data/loader/class-wc-db-loader.php | 17 +- .../data/mutation/class-cart-mutation.php | 24 +- .../data/mutation/class-checkout-mutation.php | 64 +-- .../data/mutation/class-coupon-mutation.php | 6 +- .../data/mutation/class-customer-mutation.php | 26 +- .../data/mutation/class-order-mutation.php | 46 +- includes/functions.php | 4 +- includes/model/class-coupon.php | 14 +- includes/model/class-customer.php | 8 +- includes/model/class-order-item.php | 32 +- includes/model/class-order.php | 72 +-- includes/model/class-product-variation.php | 16 +- includes/model/class-product.php | 58 +- includes/model/class-refund.php | 8 +- includes/model/class-shipping-method.php | 8 +- includes/model/class-tax-rate.php | 12 +- includes/model/class-wc-post.php | 12 +- includes/mutation/class-cart-add-fee.php | 36 +- includes/mutation/class-cart-add-item.php | 42 +- includes/mutation/class-cart-add-items.php | 42 +- includes/mutation/class-cart-apply-coupon.php | 24 +- includes/mutation/class-cart-empty.php | 20 +- includes/mutation/class-cart-fill.php | 84 +-- .../mutation/class-cart-remove-coupons.php | 20 +- includes/mutation/class-cart-remove-items.php | 30 +- .../mutation/class-cart-restore-items.php | 16 +- .../class-cart-update-item-quantities.php | 50 +- .../class-cart-update-shipping-method.php | 20 +- includes/mutation/class-checkout.php | 74 +-- includes/mutation/class-coupon-create.php | 120 ++-- includes/mutation/class-coupon-delete.php | 28 +- includes/mutation/class-coupon-update.php | 20 +- includes/mutation/class-customer-register.php | 40 +- includes/mutation/class-customer-update.php | 44 +- includes/mutation/class-order-create.php | 98 ++-- .../mutation/class-order-delete-items.php | 34 +- includes/mutation/class-order-delete.php | 32 +- includes/mutation/class-order-update.php | 32 +- .../mutation/class-review-delete-restore.php | 40 +- includes/mutation/class-review-update.php | 20 +- includes/mutation/class-review-write.php | 26 +- includes/type/enum/class-backorders.php | 14 +- includes/type/enum/class-cart-error-type.php | 14 +- .../type/enum/class-catalog-visibility.php | 16 +- includes/type/enum/class-countries.php | 6 +- ...class-customer-connection-orderby-enum.php | 32 +- includes/type/enum/class-discount-type.php | 6 +- includes/type/enum/class-id-type-enums.php | 84 +-- includes/type/enum/class-manage-stock.php | 14 +- includes/type/enum/class-order-status.php | 6 +- .../type/enum/class-orders-orderby-enum.php | 28 +- .../enum/class-post-type-orderby-enum.php | 36 +- .../type/enum/class-pricing-field-format.php | 12 +- .../enum/class-product-attribute-types.php | 16 +- .../enum/class-product-category-display.php | 24 +- includes/type/enum/class-product-taxonomy.php | 8 +- includes/type/enum/class-product-types.php | 28 +- .../type/enum/class-products-orderby-enum.php | 36 +- includes/type/enum/class-stock-status.php | 14 +- includes/type/enum/class-tax-class.php | 18 +- ...class-tax-rate-connection-orderby-enum.php | 12 +- includes/type/enum/class-tax-status.php | 14 +- .../type/enum/class-taxonomy-operator.php | 18 +- includes/type/input/class-cart-item-input.php | 32 +- .../input/class-cart-item-quantity-input.php | 20 +- .../type/input/class-create-account-input.php | 20 +- .../input/class-customer-address-input.php | 56 +- includes/type/input/class-fee-line-input.php | 32 +- includes/type/input/class-line-item-input.php | 50 +- includes/type/input/class-meta-data-input.php | 24 +- includes/type/input/class-orderby-inputs.php | 22 +- .../input/class-product-attribute-input.php | 18 +- .../class-product-taxonomy-filter-input.php | 30 +- .../input/class-product-taxonomy-input.php | 18 +- .../type/input/class-shipping-line-input.php | 40 +- ...lass-tax-rate-connection-orderby-input.php | 18 +- includes/type/interface/class-attribute.php | 16 +- includes/type/interface/class-cart-error.php | 22 +- .../interface/class-product-attribute.php | 62 +- includes/type/interface/class-product.php | 154 ++--- .../type/object/class-cart-error-types.php | 72 +-- includes/type/object/class-cart-type.php | 346 +++++------ includes/type/object/class-coupon-type.php | 90 +-- .../object/class-customer-address-type.php | 52 +- includes/type/object/class-customer-type.php | 120 ++-- .../object/class-downloadable-item-type.php | 40 +- includes/type/object/class-meta-data-type.php | 56 +- .../type/object/class-order-item-type.php | 248 ++++---- includes/type/object/class-order-type.php | 302 +++++----- .../object/class-payment-gateway-type.php | 26 +- .../object/class-product-attribute-types.php | 66 +-- .../object/class-product-category-type.php | 16 +- .../object/class-product-download-type.php | 42 +- includes/type/object/class-product-types.php | 192 +++---- .../object/class-product-variation-type.php | 194 +++---- includes/type/object/class-refund-type.php | 40 +- includes/type/object/class-root-query.php | 197 +++---- .../object/class-shipping-method-type.php | 30 +- .../object/class-shipping-package-type.php | 24 +- .../type/object/class-shipping-rate-type.php | 32 +- .../object/class-simple-attribute-type.php | 8 +- includes/type/object/class-tax-rate-type.php | 68 +-- .../object/class-variation-attribute-type.php | 32 +- includes/utils/class-ql-session-handler.php | 20 +- .../class-session-transaction-manager.php | 12 +- phpcs.xml.dist | 6 + tests/_support/Factory/CartFactory.php | 6 +- tests/_support/Factory/CouponFactory.php | 10 +- tests/_support/Factory/CustomerFactory.php | 16 +- tests/_support/Factory/OrderFactory.php | 54 +- tests/_support/Factory/ProductFactory.php | 112 ++-- .../Factory/ProductVariationFactory.php | 46 +- tests/_support/Factory/RefundFactory.php | 12 +- .../_support/Factory/ShippingZoneFactory.php | 22 +- tests/_support/Factory/TaxRateFactory.php | 17 +- tests/_support/Helper/GraphQLE2E.php | 112 ++-- tests/_support/Helper/Wpunit.php | 12 +- .../_support/TestCase/WooGraphQLTestCase.php | 6 +- tests/_support/Utils/Dummy.php | 20 +- .../acceptance/NewCustomerCheckingOutCept.php | 54 +- .../ReturningCustomerSessionCept.php | 182 +++--- tests/functional/CartTransactionQueueCest.php | 192 +++---- tests/functional/QLSessionHandlerCest.php | 250 ++++---- tests/wpunit/CartMutationsTest.php | 538 ++++++++--------- tests/wpunit/CartQueriesTest.php | 150 ++--- tests/wpunit/CheckoutMutationTest.php | 544 +++++++++--------- tests/wpunit/ConnectionPaginationTest.php | 226 ++++---- tests/wpunit/CoreInterfaceQueriesTest.php | 126 ++-- tests/wpunit/CouponMutationsTest.php | 60 +- tests/wpunit/CouponQueriesTest.php | 100 ++-- tests/wpunit/CustomerMutationsTest.php | 328 +++++------ tests/wpunit/CustomerQueriesTest.php | 94 +-- tests/wpunit/DownloadableItemQueriesTest.php | 162 +++--- tests/wpunit/IntrospectionQueryTest.php | 4 +- tests/wpunit/MetaDataQueriesTest.php | 514 ++++++++--------- tests/wpunit/OrderItemQueriesTest.php | 30 +- tests/wpunit/OrderMutationsTest.php | 514 ++++++++--------- tests/wpunit/OrderQueriesTest.php | 116 ++-- tests/wpunit/PaymentGatewayQueriesTest.php | 48 +- tests/wpunit/ProductAttributeQueriesTest.php | 96 ++-- tests/wpunit/ProductQueriesTest.php | 406 ++++++------- tests/wpunit/ProductReviewMutationsTest.php | 102 ++-- tests/wpunit/ProductVariationQueriesTest.php | 84 +-- tests/wpunit/QLSessionHandlerTest.php | 4 +- tests/wpunit/RefundQueriesTest.php | 110 ++-- tests/wpunit/ShippingMethodQueriesTest.php | 28 +- tests/wpunit/TaxRateQueriesTest.php | 106 ++-- .../wpunit/VariationAttributeQueriesTest.php | 40 +- wp-graphql-woocommerce.php | 68 ++- 189 files changed, 6390 insertions(+), 6248 deletions(-) diff --git a/access-functions.php b/access-functions.php index 982d80fad..e858ce28e 100644 --- a/access-functions.php +++ b/access-functions.php @@ -4,177 +4,187 @@ * * @package WPGraphQL\WooCommerce * @since 0.0.1 - * @deprecated v0.10.2 - * - * Will be removed in v0.11.0. Some functions will be relocated. */ -/** - * Checks if source string starts with the target string - * - * @param string $haystack - Source string. - * @param string $needle - Target string. - * - * @return bool - */ -function wc_graphql_starts_with( $haystack, $needle ) { - $length = strlen( $needle ); - return ( substr( $haystack, 0, $length ) === $needle ); +if ( ! function_exists( 'wc_graphql_starts_with' ) ) { + /** + * Checks if source string starts with the target string + * + * @param string $haystack - Source string. + * @param string $needle - Target string. + * + * @return bool + */ + function wc_graphql_starts_with( $haystack, $needle ) { + $length = strlen( $needle ); + return ( substr( $haystack, 0, $length ) === $needle ); + } } -/** - * Checks if source string ends with the target string - * - * @param string $haystack - Source string. - * @param string $needle - Target string. - * - * @return bool - */ -function wc_graphql_ends_with( $haystack, $needle ) { - $length = strlen( $needle ); - if ( 0 === $length ) { - return true; - } +if ( ! function_exists( 'wc_graphql_ends_with' ) ) { + /** + * Checks if source string ends with the target string + * + * @param string $haystack - Source string. + * @param string $needle - Target string. + * + * @return bool + */ + function wc_graphql_ends_with( $haystack, $needle ) { + $length = strlen( $needle ); + if ( 0 === $length ) { + return true; + } - return ( substr( $haystack, -$length ) === $needle ); + return ( substr( $haystack, -$length ) === $needle ); + } } -/** - * Returns formatted array of tax statement objects. - * - * @param array $raw_taxes - array of raw taxes object from WC_Order_Item crud objects. - * - * @return array - */ -function wc_graphql_map_tax_statements( $raw_taxes ) { - $taxes = array(); - foreach ( $raw_taxes as $field => $values ) { - foreach ( $values as $id => $amount ) { - if ( empty( $taxes[ $id ] ) ) { - $taxes[ $id ] = array(); +if ( ! function_exists( 'wc_graphql_map_tax_statements' ) ) { + /** + * Returns formatted array of tax statement objects. + * + * @param array $raw_taxes - array of raw taxes object from WC_Order_Item crud objects. + * + * @return array + */ + function wc_graphql_map_tax_statements( $raw_taxes ) { + $taxes = []; + foreach ( $raw_taxes as $field => $values ) { + foreach ( $values as $id => $amount ) { + if ( empty( $taxes[ $id ] ) ) { + $taxes[ $id ] = []; + } + $taxes[ $id ]['ID'] = $id; + $taxes[ $id ][ $field ] = $amount; } - $taxes[ $id ]['ID'] = $id; - $taxes[ $id ][ $field ] = $amount; } - } - return array_values( $taxes ); + return array_values( $taxes ); + } } -/** - * Get order statuses without prefixes. - * - * @return array - */ -function wc_graphql_get_order_statuses() { - $order_statuses = array(); - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { - $order_statuses[] = str_replace( 'wc-', '', $status ); +if ( ! function_exists( 'wc_graphql_get_order_statuses' ) ) { + /** + * Get order statuses without prefixes. + * + * @return array + */ + function wc_graphql_get_order_statuses() { + $order_statuses = []; + foreach ( array_keys( wc_get_order_statuses() ) as $status ) { + $order_statuses[] = str_replace( 'wc-', '', $status ); + } + return $order_statuses; } - return $order_statuses; } -/** - * Format the price with a currency symbol. - * - * @param float $price Raw price. - * @param array $args Arguments to format a price { - * Array of arguments. - * Defaults to empty array. - * - * @type string $currency Currency code. - * Defaults to empty string (Use the result from get_woocommerce_currency()). - * @type string $decimal_separator Decimal separator. - * Defaults the result of wc_get_price_decimal_separator(). - * @type string $thousand_separator Thousand separator. - * Defaults the result of wc_get_price_thousand_separator(). - * @type string $decimals Number of decimals. - * Defaults the result of wc_get_price_decimals(). - * @type string $price_format Price format depending on the currency position. - * Defaults the result of get_woocommerce_price_format(). - * } - * @return string - */ -function wc_graphql_price( $price, $args = array() ) { - $price = floatval( $price ); - $args = apply_filters( - 'wc_price_args', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound - wp_parse_args( - $args, - array( - 'currency' => '', - 'decimal_separator' => wc_get_price_decimal_separator(), - 'thousand_separator' => wc_get_price_thousand_separator(), - 'decimals' => wc_get_price_decimals(), - 'price_format' => get_woocommerce_price_format(), +if ( ! function_exists( 'wc_graphql_price' ) ) { + /** + * Format the price with a currency symbol. + * + * @param float $price Raw price. + * @param array $args Arguments to format a price { + * Array of arguments. + * Defaults to empty array. + * + * @type string $currency Currency code. + * Defaults to empty string (Use the result from get_woocommerce_currency()). + * @type string $decimal_separator Decimal separator. + * Defaults the result of wc_get_price_decimal_separator(). + * @type string $thousand_separator Thousand separator. + * Defaults the result of wc_get_price_thousand_separator(). + * @type string $decimals Number of decimals. + * Defaults the result of wc_get_price_decimals(). + * @type string $price_format Price format depending on the currency position. + * Defaults the result of get_woocommerce_price_format(). + * } + * @return string + */ + function wc_graphql_price( $price, $args = [] ) { + $price = floatval( $price ); + $args = apply_filters( + 'wc_price_args', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + wp_parse_args( + $args, + [ + 'currency' => '', + 'decimal_separator' => wc_get_price_decimal_separator(), + 'thousand_separator' => wc_get_price_thousand_separator(), + 'decimals' => wc_get_price_decimals(), + 'price_format' => get_woocommerce_price_format(), + ] ) - ) - ); + ); - $unformatted_price = $price; - $negative = $price < 0; + $unformatted_price = $price; + $negative = $price < 0; - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound - $price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) ); - - $price = apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound - 'formatted_woocommerce_price', - number_format( + $price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) ); + + $price = apply_filters( + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + 'formatted_woocommerce_price', + number_format( + $price, + $args['decimals'], + $args['decimal_separator'], + $args['thousand_separator'] + ), $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'] - ), - $price, - $args['decimals'], - $args['decimal_separator'], - $args['thousand_separator'] - ); - - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound - if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $args['decimals'] > 0 ) { - $price = wc_trim_zeros( $price ); - } + ); + + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $args['decimals'] > 0 ) { + $price = wc_trim_zeros( $price ); + } + + // phpcs:ignore PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet + $symbol = html_entity_decode( get_woocommerce_currency_symbol( $args['currency'] ) ); + $return = ( $negative ? '-' : '' ) . sprintf( $args['price_format'], $symbol, $price ); - // phpcs:ignore PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet - $symbol = html_entity_decode( get_woocommerce_currency_symbol( $args['currency'] ) ); - $return = ( $negative ? '-' : '' ) . sprintf( $args['price_format'], $symbol, $price ); + /** + * Filters the string of price markup. + * + * @param string $return Price HTML markup. + * @param string $price Formatted price. + * @param array $args Pass on the args. + * @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0. + */ + return apply_filters( 'graphql_woocommerce_price', $return, $price, $args, $unformatted_price, $symbol ); + } +} +if ( ! function_exists( 'wc_graphql_price_range' ) ) { /** - * Filters the string of price markup. + * Format a price range for display. * - * @param string $return Price HTML markup. - * @param string $price Formatted price. - * @param array $args Pass on the args. - * @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0. + * @param string $from Price from. + * @param string $to Price to. + * @return string */ - return apply_filters( 'graphql_woocommerce_price', $return, $price, $args, $unformatted_price, $symbol ); -} - -/** - * Format a price range for display. - * - * @param string $from Price from. - * @param string $to Price to. - * @return string - */ -function wc_graphql_price_range( $from, $to ) { - if ( $from === $to ) { - return wc_graphql_price( $from ); - } + function wc_graphql_price_range( $from, $to ) { + if ( $from === $to ) { + return wc_graphql_price( $from ); + } - $price = sprintf( - /* translators: 1: price from 2: price to */ - _x( '%1$s %2$s %3$s', 'Price range: from-to', 'wp-graphql-woocommerce' ), - is_numeric( $from ) ? wc_graphql_price( $from ) : $from, - apply_filters( 'graphql_woocommerce_format_price_range_separator', '-', $from, $to ), - is_numeric( $to ) ? wc_graphql_price( $to ) : $to - ); + $price = sprintf( + /* translators: 1: price from 2: price to */ + _x( '%1$s %2$s %3$s', 'Price range: from-to', 'wp-graphql-woocommerce' ), + is_numeric( $from ) ? wc_graphql_price( $from ) : $from, + apply_filters( 'graphql_woocommerce_format_price_range_separator', '-', $from, $to ), + is_numeric( $to ) ? wc_graphql_price( $to ) : $to + ); - return apply_filters( 'graphql_woocommerce_format_price_range', $price, $from, $to ); + return apply_filters( 'graphql_woocommerce_format_price_range', $price, $from, $to ); + } } +if ( ! function_exists( 'wc_graphql_underscore_to_camel_case' ) ) { /** * Converts a camel case formatted string to a underscore formatted string. * @@ -183,35 +193,50 @@ function wc_graphql_price_range( $from, $to ) { * * @return string */ -function wc_graphql_underscore_to_camel_case( $string, $capitalize = false ) { - $str = str_replace( ' ', '', ucwords( str_replace( '-', ' ', $string ) ) ); + function wc_graphql_underscore_to_camel_case( $string, $capitalize = false ) { + $str = str_replace( ' ', '', ucwords( str_replace( '-', ' ', $string ) ) ); - if ( ! $capitalize ) { - $str[0] = strtolower( $str[0] ); - } + if ( ! $capitalize ) { + $str[0] = strtolower( $str[0] ); + } - return $str; + return $str; + } } - /** - * Converts a camel case formatted string to a underscore formatted string. - * - * @param string $string String to be formatted. - * - * @return string - */ -function wc_graphql_camel_case_to_underscore( $string ) { - preg_match_all( - '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', - $string, - $matches - ); +if ( ! function_exists( 'wc_graphql_camel_case_to_underscore' ) ) { + /** + * Converts a camel case formatted string to a underscore formatted string. + * + * @param string $string String to be formatted. + * + * @return string + */ + function wc_graphql_camel_case_to_underscore( $string ) { + preg_match_all( + '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', + $string, + $matches + ); - $ret = $matches[0]; + $ret = $matches[0]; - foreach ( $ret as &$match ) { - $match = strtoupper( $match ) === $match ? strtolower( $match ) : lcfirst( $match ); - } + foreach ( $ret as &$match ) { + $match = strtoupper( $match ) === $match ? strtolower( $match ) : lcfirst( $match ); + } - return implode( '_', $ret ); + return implode( '_', $ret ); + } } + + + + + + + + + + + + diff --git a/bin/_lib.sh b/bin/_lib.sh index abb7570ac..17c7e242d 100644 --- a/bin/_lib.sh +++ b/bin/_lib.sh @@ -52,13 +52,14 @@ remove_wordpress() { install_local_test_library() { # Install testing library dependencies. composer install - composer require --dev \ + composer require --dev --with-all-dependencies \ lucatume/wp-browser \ codeception/module-asserts:^1.0 \ - codeception/module-rest:^1.0 \ + codeception/module-rest:^2.0 \ codeception/util-universalframework:^1.0 \ - wp-graphql/wp-graphql-testcase \ + wp-graphql/wp-graphql-testcase:^2.3 \ stripe/stripe-php + } remove_local_test_library() { diff --git a/composer.json b/composer.json index 37aa03d42..0e1a09c92 100644 --- a/composer.json +++ b/composer.json @@ -39,22 +39,9 @@ "process-timeout": 0, "sort-packages": true, "allow-plugins": { - "composer/installers": true, "johnpbloch/wordpress-core-installer": true } }, - "autoload": { - "files": [ - "includes/connection/wc-cpt-connection-args.php", - "includes/functions.php" - ], - "psr-4": { - "WPGraphQL\\WooCommerce\\": "includes/" - }, - "classmap": [ - "includes/" - ] - }, "autoload-dev": { "files": [ "tests/_data/config.php" diff --git a/composer.lock b/composer.lock index 4f4902bc2..c7ce5ae7b 100644 --- a/composer.lock +++ b/composer.lock @@ -182,5 +182,5 @@ "php": ">=7.1.0" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/includes/class-acf-schema-filters.php b/includes/class-acf-schema-filters.php index f85df6026..41fa62d7d 100644 --- a/includes/class-acf-schema-filters.php +++ b/includes/class-acf-schema-filters.php @@ -22,8 +22,8 @@ class ACF_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs && taxonomies. - add_filter( 'graphql_acf_get_root_id', array( __CLASS__, 'resolve_crud_root_id' ), 10, 2 ); - add_filter( 'graphql_acf_post_object_source', array( __CLASS__, 'resolve_post_object_source' ), 10, 2 ); + add_filter( 'graphql_acf_get_root_id', [ __CLASS__, 'resolve_crud_root_id' ], 10, 2 ); + add_filter( 'graphql_acf_post_object_source', [ __CLASS__, 'resolve_post_object_source' ], 10, 2 ); } /** diff --git a/includes/class-core-schema-filters.php b/includes/class-core-schema-filters.php index 806da6f33..52724b0eb 100644 --- a/includes/class-core-schema-filters.php +++ b/includes/class-core-schema-filters.php @@ -22,25 +22,25 @@ class Core_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs. - add_filter( 'register_post_type_args', array( __CLASS__, 'register_post_types' ), 10, 2 ); - add_filter( 'graphql_post_entities_allowed_post_types', array( __CLASS__, 'skip_type_registry' ), 10 ); + add_filter( 'register_post_type_args', [ __CLASS__, 'register_post_types' ], 10, 2 ); + add_filter( 'graphql_post_entities_allowed_post_types', [ __CLASS__, 'skip_type_registry' ], 10 ); // Registers WooCommerce taxonomies. - add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 ); + add_filter( 'register_taxonomy_args', [ __CLASS__, 'register_taxonomy_args' ], 10, 2 ); // Add data-loaders to AppContext. - add_filter( 'graphql_data_loaders', array( __CLASS__, 'graphql_data_loaders' ), 10, 2 ); + add_filter( 'graphql_data_loaders', [ __CLASS__, 'graphql_data_loaders' ], 10, 2 ); // Add node resolvers. add_filter( 'graphql_resolve_node', - array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ), + [ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node' ], 10, 4 ); add_filter( 'graphql_resolve_node_type', - array( '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ), + [ '\WPGraphQL\WooCommerce\Data\Factory', 'resolve_node_type' ], 10, 2 ); @@ -48,70 +48,70 @@ public static function add_filters() { // Filter Unions. add_filter( 'graphql_wp_union_type_config', - array( __CLASS__, 'inject_union_types' ), + [ __CLASS__, 'inject_union_types' ], 10, 2 ); add_filter( 'graphql_union_resolve_type', - array( __CLASS__, 'inject_type_resolver' ), + [ __CLASS__, 'inject_type_resolver' ], 10, 3 ); add_filter( 'graphql_interface_resolve_type', - array( __CLASS__, 'inject_type_resolver' ), + [ __CLASS__, 'inject_type_resolver' ], 10, 3 ); add_filter( 'graphql_dataloader_pre_get_model', - array( '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ), + [ '\WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader', 'inject_post_loader_models' ], 10, 3 ); add_filter( 'graphql_dataloader_get_model', - array( '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ), + [ '\WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader', 'inject_user_loader_models' ], 10, 3 ); add_filter( 'graphql_post_object_connection_query_args', - array( '\WPGraphQL\WooCommerce\Connection\Orders', 'post_object_connection_query_args' ), + [ '\WPGraphQL\WooCommerce\Connection\Orders', 'post_object_connection_query_args' ], 10, 5 ); add_filter( 'graphql_map_input_fields_to_wp_query', - array( '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ), + [ '\WPGraphQL\WooCommerce\Connection\Coupons', 'map_input_fields_to_wp_query' ], 10, 7 ); add_filter( 'graphql_map_input_fields_to_wp_query', - array( '\WPGraphQL\WooCommerce\Connection\Products', 'map_input_fields_to_wp_query' ), + [ '\WPGraphQL\WooCommerce\Connection\Products', 'map_input_fields_to_wp_query' ], 10, 7 ); add_filter( 'graphql_map_input_fields_to_wp_query', - array( '\WPGraphQL\WooCommerce\Connection\Orders', 'map_input_fields_to_wp_query' ), + [ '\WPGraphQL\WooCommerce\Connection\Orders', 'map_input_fields_to_wp_query' ], 10, 7 ); add_filter( 'graphql_map_input_fields_to_wp_user_query', - array( '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ), + [ '\WPGraphQL\WooCommerce\Connection\Customers', 'map_input_fields_to_wp_query' ], 10, 6 ); @@ -173,10 +173,10 @@ public static function skip_type_registry( $post_types ) { return array_diff( $post_types, get_post_types( - array( + [ 'show_in_graphql' => true, 'skip_graphql_type_registry' => true, - ) + ] ) ); } @@ -221,7 +221,7 @@ public static function register_taxonomy_args( $args, $taxonomy ) { } // Filter product attributes taxonomies. - $attributes = \WP_GraphQL_WooCommerce::get_product_attribute_taxonomies(); + $attributes = WP_GraphQL_WooCommerce::get_product_attribute_taxonomies(); if ( in_array( $taxonomy, $attributes, true ) ) { $singular_name = graphql_format_field_name( $taxonomy ); $args['show_in_graphql'] = true; @@ -280,7 +280,7 @@ function( $type ) { return 'Product' !== $type; } ), - array_values( \WP_GraphQL_WooCommerce::get_enabled_product_types() ) + array_values( WP_GraphQL_WooCommerce::get_enabled_product_types() ) ); $refresh_callback = true; } @@ -288,9 +288,9 @@ function( $type ) { // Update 'types' callback. if ( $refresh_callback ) { $config['types'] = function () use ( $config, $wp_union ) { - $prepared_types = array(); + $prepared_types = []; if ( ! empty( $config['typeNames'] ) && is_array( $config['typeNames'] ) ) { - $prepared_types = array(); + $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 454bcca22..08518d1ec 100644 --- a/includes/class-jwt-auth-schema-filters.php +++ b/includes/class-jwt-auth-schema-filters.php @@ -21,10 +21,10 @@ class JWT_Auth_Schema_Filters { public static function add_filters() { // Confirm WPGraphQL JWT Authentication is installed. if ( \class_exists( '\WPGraphQL\JWT_Authentication\Auth' ) ) { - add_filter( 'graphql_jwt_user_types', array( __CLASS__, 'add_customer_to_jwt_user_types' ), 10 ); - add_filter( 'graphql_registerCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 ); - add_filter( 'graphql_updateCustomerPayload_fields', array( __CLASS__, 'add_jwt_output_fields' ), 10, 3 ); - add_action( 'graphql_register_types', array( __CLASS__, 'add_customer_to_login_payload' ), 10 ); + add_filter( 'graphql_jwt_user_types', [ __CLASS__, 'add_customer_to_jwt_user_types' ], 10 ); + add_filter( 'graphql_registerCustomerPayload_fields', [ __CLASS__, 'add_jwt_output_fields' ], 10, 3 ); + add_filter( 'graphql_updateCustomerPayload_fields', [ __CLASS__, 'add_jwt_output_fields' ], 10, 3 ); + add_action( 'graphql_register_types', [ __CLASS__, 'add_customer_to_login_payload' ], 10 ); } } @@ -51,12 +51,12 @@ public static function add_customer_to_jwt_user_types( array $types ) { public static function add_jwt_output_fields( $fields, $object, $type_registry ): array { $fields = array_merge( $fields, - array( - 'authToken' => array( + [ + '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 ) { - $user = get_user_by( 'ID', $payload['id'] ); + $user = get_user_by( 'ID', $payload['id'] ); $token = \WPGraphQL\JWT_Authentication\Auth::get_token( $user ); if ( is_wp_error( $token ) ) { @@ -65,12 +65,12 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) return $token; }, - ), - 'refreshToken' => array( + ], + '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 ) { - $user = get_user_by( 'ID', $payload['id'] ); + $user = get_user_by( 'ID', $payload['id'] ); $refresh_token = \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ); if ( is_wp_error( $refresh_token ) ) { @@ -79,8 +79,8 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) return $refresh_token; }, - ), - ) + ], + ] ); return $fields; @@ -92,23 +92,23 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) public static function add_customer_to_login_payload() { register_graphql_fields( 'LoginPayload', - array( - 'customer' => array( + [ + 'customer' => [ 'type' => 'Customer', 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload ) { $id = $payload['id']; return new Customer( $id ); }, - ), - 'sessionToken' => array( + ], + 'sessionToken' => [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload ) { return apply_filters( 'graphql_customer_session_token', \WC()->session->build_token() ); }, - ), - ) + ], + ] ); } } diff --git a/includes/class-type-registry.php b/includes/class-type-registry.php index c7457b06b..e24497be4 100644 --- a/includes/class-type-registry.php +++ b/includes/class-type-registry.php @@ -20,115 +20,115 @@ class Type_Registry { */ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) { // Enumerations. - \WPGraphQL\WooCommerce\Type\WPEnum\Backorders::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Catalog_Visibility::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Countries::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Customer_Connection_Orderby_Enum::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Discount_Type::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Manage_Stock::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Order_Status::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Product_Types::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Product_Attribute_Types::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Product_Category_Display::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Stock_Status::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Tax_Class::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Tax_Status::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Tax_Rate_Connection_Orderby_Enum::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Pricing_Field_Format::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Product_Taxonomy::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Taxonomy_Operator::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Post_Type_Orderby_Enum::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Products_Orderby_Enum::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Orders_Orderby_Enum::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Id_Type_Enums::register(); - \WPGraphQL\WooCommerce\Type\WPEnum\Cart_Error_Type::register(); + Type\WPEnum\Backorders::register(); + Type\WPEnum\Catalog_Visibility::register(); + Type\WPEnum\Countries::register(); + Type\WPEnum\Customer_Connection_Orderby_Enum::register(); + Type\WPEnum\Discount_Type::register(); + Type\WPEnum\Manage_Stock::register(); + Type\WPEnum\Order_Status::register(); + Type\WPEnum\Product_Types::register(); + Type\WPEnum\Product_Attribute_Types::register(); + Type\WPEnum\Product_Category_Display::register(); + Type\WPEnum\Stock_Status::register(); + Type\WPEnum\Tax_Class::register(); + Type\WPEnum\Tax_Status::register(); + Type\WPEnum\Tax_Rate_Connection_Orderby_Enum::register(); + Type\WPEnum\Pricing_Field_Format::register(); + Type\WPEnum\Product_Taxonomy::register(); + Type\WPEnum\Taxonomy_Operator::register(); + Type\WPEnum\Post_Type_Orderby_Enum::register(); + Type\WPEnum\Products_Orderby_Enum::register(); + Type\WPEnum\Orders_Orderby_Enum::register(); + Type\WPEnum\Id_Type_Enums::register(); + Type\WPEnum\Cart_Error_Type::register(); // InputObjects. - \WPGraphQL\WooCommerce\Type\WPInputObject\Cart_Item_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Customer_Address_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Product_Attribute_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Tax_Rate_Connection_Orderby_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Fee_Line_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Line_Item_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Meta_Data_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Shipping_Line_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Create_Account_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Cart_Item_Quantity_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Product_Taxonomy_Filter_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Product_Taxonomy_Input::register(); - \WPGraphQL\WooCommerce\Type\WPInputObject\Orderby_Inputs::register(); + Type\WPInputObject\Cart_Item_Input::register(); + Type\WPInputObject\Customer_Address_Input::register(); + Type\WPInputObject\Product_Attribute_Input::register(); + Type\WPInputObject\Tax_Rate_Connection_Orderby_Input::register(); + Type\WPInputObject\Fee_Line_Input::register(); + Type\WPInputObject\Line_Item_Input::register(); + Type\WPInputObject\Meta_Data_Input::register(); + Type\WPInputObject\Shipping_Line_Input::register(); + Type\WPInputObject\Create_Account_Input::register(); + Type\WPInputObject\Cart_Item_Quantity_Input::register(); + Type\WPInputObject\Product_Taxonomy_Filter_Input::register(); + Type\WPInputObject\Product_Taxonomy_Input::register(); + Type\WPInputObject\Orderby_Inputs::register(); // Interfaces. - \WPGraphQL\WooCommerce\Type\WPInterface\Product::register_interface( $type_registry ); - \WPGraphQL\WooCommerce\Type\WPInterface\Attribute::register_interface( $type_registry ); - \WPGraphQL\WooCommerce\Type\WPInterface\Product_Attribute::register_interface( $type_registry ); - \WPGraphQL\WooCommerce\Type\WPInterface\Cart_Error::register_interface( $type_registry ); + Type\WPInterface\Product::register_interface( $type_registry ); + Type\WPInterface\Attribute::register_interface( $type_registry ); + Type\WPInterface\Product_Attribute::register_interface( $type_registry ); + Type\WPInterface\Cart_Error::register_interface( $type_registry ); // Objects. - \WPGraphQL\WooCommerce\Type\WPObject\Meta_Data_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Downloadable_Item_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Coupon_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Product_Types::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Product_Attribute_Types::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Product_Variation_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Order_Item_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Order_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Refund_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Product_Download_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Customer_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Customer_Address_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Tax_Rate_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Shipping_Method_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Cart_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Simple_Attribute_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Variation_Attribute_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Payment_Gateway_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Shipping_Package_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Shipping_Rate_Type::register(); - \WPGraphQL\WooCommerce\Type\WPObject\Cart_Error_Types::register(); + Type\WPObject\Meta_Data_Type::register(); + Type\WPObject\Downloadable_Item_Type::register(); + Type\WPObject\Coupon_Type::register(); + Type\WPObject\Product_Types::register(); + Type\WPObject\Product_Attribute_Types::register(); + Type\WPObject\Product_Variation_Type::register(); + Type\WPObject\Order_Item_Type::register(); + Type\WPObject\Order_Type::register(); + Type\WPObject\Refund_Type::register(); + Type\WPObject\Product_Download_Type::register(); + Type\WPObject\Customer_Type::register(); + Type\WPObject\Customer_Address_Type::register(); + Type\WPObject\Tax_Rate_Type::register(); + Type\WPObject\Shipping_Method_Type::register(); + Type\WPObject\Cart_Type::register(); + Type\WPObject\Simple_Attribute_Type::register(); + Type\WPObject\Variation_Attribute_Type::register(); + Type\WPObject\Payment_Gateway_Type::register(); + Type\WPObject\Shipping_Package_Type::register(); + Type\WPObject\Shipping_Rate_Type::register(); + Type\WPObject\Cart_Error_Types::register(); // Object fields. - \WPGraphQL\WooCommerce\Type\WPObject\Product_Category_Type::register_fields(); - \WPGraphQL\WooCommerce\Type\WPObject\Root_Query::register_fields(); + Type\WPObject\Product_Category_Type::register_fields(); + Type\WPObject\Root_Query::register_fields(); // Connections. - \WPGraphQL\WooCommerce\Connection\Posts::register_connections(); - \WPGraphQL\WooCommerce\Connection\WC_Terms::register_connections(); - \WPGraphQL\WooCommerce\Connection\Comments::register_connections(); - \WPGraphQL\WooCommerce\Connection\Coupons::register_connections(); - \WPGraphQL\WooCommerce\Connection\Products::register_connections(); - \WPGraphQL\WooCommerce\Connection\Orders::register_connections(); - \WPGraphQL\WooCommerce\Connection\Product_Attributes::register_connections(); - \WPGraphQL\WooCommerce\Connection\Variation_Attributes::register_connections(); - \WPGraphQL\WooCommerce\Connection\Customers::register_connections(); - \WPGraphQL\WooCommerce\Connection\Tax_Rates::register_connections(); - \WPGraphQL\WooCommerce\Connection\Shipping_Methods::register_connections(); - \WPGraphQL\WooCommerce\Connection\Payment_Gateways::register_connections(); + Connection\Posts::register_connections(); + Connection\WC_Terms::register_connections(); + Connection\Comments::register_connections(); + Connection\Coupons::register_connections(); + Connection\Products::register_connections(); + Connection\Orders::register_connections(); + Connection\Product_Attributes::register_connections(); + Connection\Variation_Attributes::register_connections(); + Connection\Customers::register_connections(); + Connection\Tax_Rates::register_connections(); + Connection\Shipping_Methods::register_connections(); + Connection\Payment_Gateways::register_connections(); // Mutations. - \WPGraphQL\WooCommerce\Mutation\Customer_Register::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Customer_Update::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Add_Item::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Add_Items::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Update_Item_Quantities::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Remove_Items::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Restore_Items::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Empty::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Apply_Coupon::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Remove_Coupons::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Add_Fee::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Update_Shipping_Method::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Cart_Fill::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Order_Create::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Order_Update::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Order_Delete::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Order_Delete_Items::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Checkout::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Review_Write::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Review_Update::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Review_Delete_Restore::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Coupon_Create::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Coupon_Update::register_mutation(); - \WPGraphQL\WooCommerce\Mutation\Coupon_Delete::register_mutation(); + Mutation\Customer_Register::register_mutation(); + Mutation\Customer_Update::register_mutation(); + Mutation\Cart_Add_Item::register_mutation(); + Mutation\Cart_Add_Items::register_mutation(); + Mutation\Cart_Update_Item_Quantities::register_mutation(); + Mutation\Cart_Remove_Items::register_mutation(); + Mutation\Cart_Restore_Items::register_mutation(); + Mutation\Cart_Empty::register_mutation(); + Mutation\Cart_Apply_Coupon::register_mutation(); + Mutation\Cart_Remove_Coupons::register_mutation(); + Mutation\Cart_Add_Fee::register_mutation(); + Mutation\Cart_Update_Shipping_Method::register_mutation(); + Mutation\Cart_Fill::register_mutation(); + Mutation\Order_Create::register_mutation(); + Mutation\Order_Update::register_mutation(); + Mutation\Order_Delete::register_mutation(); + Mutation\Order_Delete_Items::register_mutation(); + Mutation\Checkout::register_mutation(); + Mutation\Review_Write::register_mutation(); + Mutation\Review_Update::register_mutation(); + Mutation\Review_Delete_Restore::register_mutation(); + Mutation\Coupon_Create::register_mutation(); + Mutation\Coupon_Update::register_mutation(); + Mutation\Coupon_Delete::register_mutation(); } } diff --git a/includes/class-woocommerce-filters.php b/includes/class-woocommerce-filters.php index d5f0fee39..7da5dab95 100644 --- a/includes/class-woocommerce-filters.php +++ b/includes/class-woocommerce-filters.php @@ -28,13 +28,13 @@ public static function setup() { // Check if request is a GraphQL POST request. if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) { - add_filter( 'woocommerce_session_handler', array( __CLASS__, 'woocommerce_session_handler' ) ); - add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) ); - add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) ); + add_filter( 'woocommerce_session_handler', [ __CLASS__, 'woocommerce_session_handler' ] ); + add_filter( 'graphql_response_headers_to_send', [ __CLASS__, 'add_session_header_to_expose_headers' ] ); + add_filter( 'graphql_access_control_allow_headers', [ __CLASS__, 'add_session_header_to_allow_headers' ] ); } // Add better support for Stripe payment gateway. - add_filter( 'graphql_stripe_process_payment_args', array( __CLASS__, 'woographql_stripe_gateway_args' ), 10, 2 ); + add_filter( 'graphql_stripe_process_payment_args', [ __CLASS__, 'woographql_stripe_gateway_args' ], 10, 2 ); } /** @@ -86,13 +86,13 @@ public static function add_session_header_to_allow_headers( array $allowed_heade */ public static function woographql_stripe_gateway_args( $gateway_args, $payment_method ) { if ( 'stripe' === $payment_method ) { - $gateway_args = array( + $gateway_args = [ $gateway_args[0], true, false, false, true, - ); + ]; } return $gateway_args; diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index dfa73d751..c04163364 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -6,10 +6,12 @@ * @since 0.0.1 */ +namespace WPGraphQL\WooCommerce; + // Exit if accessed directly. defined( 'ABSPATH' ) || exit; -if ( ! class_exists( 'WP_GraphQL_WooCommerce' ) ) : +if ( ! class_exists( '\WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce' ) ) : /** * Class WP_GraphQL_WooCommerce @@ -54,13 +56,13 @@ public static function instance() { public static function get_post_types() { return apply_filters( 'graphql_woocommerce_post_types', - array( + [ 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund', - ) + ] ); } @@ -72,12 +74,12 @@ public static function get_post_types() { public static function get_enabled_product_types() { return apply_filters( 'graphql_woocommerce_product_types', - array( + [ 'simple' => 'SimpleProduct', 'variable' => 'VariableProduct', 'external' => 'ExternalProduct', 'grouped' => 'GroupProduct', - ) + ] ); } @@ -91,7 +93,7 @@ public static function get_product_attribute_taxonomies() { $attribute_taxonomies = \wc_get_attribute_taxonomies(); // Get taxonomy names. - $attributes = array(); + $attributes = []; foreach ( $attribute_taxonomies as $tax ) { $attributes[] = 'pa_' . $tax->attribute_name; } @@ -136,6 +138,178 @@ public function __wakeup() { * @since 0.0.1 */ private function includes() { + $include_directory_path = get_includes_directory(); + + // Include util class files. + require $include_directory_path . 'utils/class-ql-session-handler.php'; + require $include_directory_path . 'utils/class-session-transaction-manager.php'; + + // Include models class files. + require $include_directory_path . 'model/class-customer.php'; + require $include_directory_path . 'model/class-wc-post.php'; + require $include_directory_path . 'model/class-coupon.php'; + require $include_directory_path . 'model/class-product.php'; + require $include_directory_path . 'model/class-product-variation.php'; + require $include_directory_path . 'model/class-order.php'; + require $include_directory_path . 'model/class-refund.php'; + require $include_directory_path . 'model/class-order-item.php'; + require $include_directory_path . 'model/class-shipping-method.php'; + require $include_directory_path . 'model/class-tax-rate.php'; + + // Include data loaders class files. + require $include_directory_path . 'data/loader/class-wc-cpt-loader.php'; + require $include_directory_path . 'data/loader/class-wc-customer-loader.php'; + require $include_directory_path . 'data/loader/class-wc-db-loader.php'; + + // Include connection resolver trait/class files. + require $include_directory_path . 'data/connection/trait-wc-db-loader-common.php'; + require $include_directory_path . 'data/connection/class-cart-item-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-downloadable-item-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-order-item-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-payment-gateway-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-product-attribute-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-shipping-method-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-tax-rate-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-variation-attribute-connection-resolver.php'; + + // Include deprecated resolver trait/class files. + require $include_directory_path . 'data/connection/trait-wc-cpt-loader-common.php'; + require $include_directory_path . 'data/connection/class-coupon-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-product-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-refund-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-order-connection-resolver.php'; + require $include_directory_path . 'data/connection/class-customer-connection-resolver.php'; + + // Include mutation processor class files. + require $include_directory_path . 'data/mutation/class-cart-mutation.php'; + require $include_directory_path . 'data/mutation/class-checkout-mutation.php'; + require $include_directory_path . 'data/mutation/class-coupon-mutation.php'; + require $include_directory_path . 'data/mutation/class-customer-mutation.php'; + require $include_directory_path . 'data/mutation/class-order-mutation.php'; + + // Include factory class file. + require $include_directory_path . 'data/class-factory.php'; + + // Include enum type class files. + require $include_directory_path . 'type/enum/class-backorders.php'; + require $include_directory_path . 'type/enum/class-cart-error-type.php'; + require $include_directory_path . 'type/enum/class-catalog-visibility.php'; + require $include_directory_path . 'type/enum/class-countries.php'; + require $include_directory_path . 'type/enum/class-customer-connection-orderby-enum.php'; + require $include_directory_path . 'type/enum/class-discount-type.php'; + require $include_directory_path . 'type/enum/class-id-type-enums.php'; + require $include_directory_path . 'type/enum/class-manage-stock.php'; + require $include_directory_path . 'type/enum/class-order-status.php'; + require $include_directory_path . 'type/enum/class-post-type-orderby-enum.php'; + require $include_directory_path . 'type/enum/class-orders-orderby-enum.php'; + require $include_directory_path . 'type/enum/class-products-orderby-enum.php'; + require $include_directory_path . 'type/enum/class-pricing-field-format.php'; + require $include_directory_path . 'type/enum/class-product-attribute-types.php'; + require $include_directory_path . 'type/enum/class-product-category-display.php'; + require $include_directory_path . 'type/enum/class-product-taxonomy.php'; + require $include_directory_path . 'type/enum/class-product-types.php'; + require $include_directory_path . 'type/enum/class-stock-status.php'; + require $include_directory_path . 'type/enum/class-tax-class.php'; + require $include_directory_path . 'type/enum/class-tax-rate-connection-orderby-enum.php'; + require $include_directory_path . 'type/enum/class-tax-status.php'; + require $include_directory_path . 'type/enum/class-taxonomy-operator.php'; + + // Include interface type class files. + require $include_directory_path . 'type/interface/class-attribute.php'; + require $include_directory_path . 'type/interface/class-cart-error.php'; + require $include_directory_path . 'type/interface/class-product-attribute.php'; + require $include_directory_path . 'type/interface/class-product.php'; + + // Include object type class files. + require $include_directory_path . 'type/object/class-cart-error-types.php'; + require $include_directory_path . 'type/object/class-cart-type.php'; + require $include_directory_path . 'type/object/class-coupon-type.php'; + require $include_directory_path . 'type/object/class-customer-address-type.php'; + require $include_directory_path . 'type/object/class-customer-type.php'; + require $include_directory_path . 'type/object/class-downloadable-item-type.php'; + require $include_directory_path . 'type/object/class-meta-data-type.php'; + require $include_directory_path . 'type/object/class-order-item-type.php'; + require $include_directory_path . 'type/object/class-order-type.php'; + require $include_directory_path . 'type/object/class-payment-gateway-type.php'; + require $include_directory_path . 'type/object/class-product-attribute-types.php'; + require $include_directory_path . 'type/object/class-product-category-type.php'; + require $include_directory_path . 'type/object/class-product-download-type.php'; + require $include_directory_path . 'type/object/class-product-types.php'; + require $include_directory_path . 'type/object/class-product-variation-type.php'; + require $include_directory_path . 'type/object/class-refund-type.php'; + require $include_directory_path . 'type/object/class-root-query.php'; + require $include_directory_path . 'type/object/class-shipping-method-type.php'; + require $include_directory_path . 'type/object/class-shipping-package-type.php'; + require $include_directory_path . 'type/object/class-shipping-rate-type.php'; + require $include_directory_path . 'type/object/class-simple-attribute-type.php'; + require $include_directory_path . 'type/object/class-tax-rate-type.php'; + require $include_directory_path . 'type/object/class-variation-attribute-type.php'; + + // Include input type class files. + require $include_directory_path . 'type/input/class-cart-item-input.php'; + require $include_directory_path . 'type/input/class-cart-item-quantity-input.php'; + require $include_directory_path . 'type/input/class-create-account-input.php'; + require $include_directory_path . 'type/input/class-customer-address-input.php'; + require $include_directory_path . 'type/input/class-fee-line-input.php'; + require $include_directory_path . 'type/input/class-line-item-input.php'; + require $include_directory_path . 'type/input/class-meta-data-input.php'; + require $include_directory_path . 'type/input/class-orderby-inputs.php'; + require $include_directory_path . 'type/input/class-product-attribute-input.php'; + require $include_directory_path . 'type/input/class-product-taxonomy-filter-input.php'; + require $include_directory_path . 'type/input/class-product-taxonomy-input.php'; + require $include_directory_path . 'type/input/class-shipping-line-input.php'; + require $include_directory_path . 'type/input/class-tax-rate-connection-orderby-input.php'; + + // Include mutation type class files. + require $include_directory_path . 'mutation/class-cart-add-fee.php'; + require $include_directory_path . 'mutation/class-cart-add-item.php'; + require $include_directory_path . 'mutation/class-cart-add-items.php'; + require $include_directory_path . 'mutation/class-cart-apply-coupon.php'; + require $include_directory_path . 'mutation/class-cart-empty.php'; + require $include_directory_path . 'mutation/class-cart-fill.php'; + require $include_directory_path . 'mutation/class-cart-remove-coupons.php'; + require $include_directory_path . 'mutation/class-cart-remove-items.php'; + require $include_directory_path . 'mutation/class-cart-restore-items.php'; + require $include_directory_path . 'mutation/class-cart-update-item-quantities.php'; + require $include_directory_path . 'mutation/class-cart-update-shipping-method.php'; + require $include_directory_path . 'mutation/class-checkout.php'; + require $include_directory_path . 'mutation/class-coupon-create.php'; + require $include_directory_path . 'mutation/class-coupon-delete.php'; + require $include_directory_path . 'mutation/class-coupon-update.php'; + require $include_directory_path . 'mutation/class-customer-register.php'; + require $include_directory_path . 'mutation/class-customer-update.php'; + require $include_directory_path . 'mutation/class-order-create.php'; + require $include_directory_path . 'mutation/class-order-delete-items.php'; + require $include_directory_path . 'mutation/class-order-delete.php'; + require $include_directory_path . 'mutation/class-order-update.php'; + require $include_directory_path . 'mutation/class-review-write.php'; + require $include_directory_path . 'mutation/class-review-delete-restore.php'; + require $include_directory_path . 'mutation/class-review-update.php'; + + // Include connection class/function files. + require $include_directory_path . 'connection/wc-cpt-connection-args.php'; + require $include_directory_path . 'connection/class-comments.php'; + require $include_directory_path . 'connection/class-coupons.php'; + require $include_directory_path . 'connection/class-customers.php'; + require $include_directory_path . 'connection/class-orders.php'; + require $include_directory_path . 'connection/class-payment-gateways.php'; + require $include_directory_path . 'connection/class-posts.php'; + require $include_directory_path . 'connection/class-product-attributes.php'; + require $include_directory_path . 'connection/class-products.php'; + require $include_directory_path . 'connection/class-shipping-methods.php'; + require $include_directory_path . 'connection/class-tax-rates.php'; + require $include_directory_path . 'connection/class-variation-attributes.php'; + require $include_directory_path . 'connection/class-wc-terms.php'; + + // Include main plugin class files. + require $include_directory_path . 'class-core-schema-filters.php'; + require $include_directory_path . 'class-jwt-auth-schema-filters.php'; + require $include_directory_path . 'class-woocommerce-filters.php'; + require $include_directory_path . 'class-acf-schema-filters.php'; + require $include_directory_path . 'class-type-registry.php'; + + // Required extra plugin function file. + require $include_directory_path . 'functions.php'; /** * WPGRAPHQL_AUTOLOAD can be set to "false" to prevent the autoloader from running. @@ -147,9 +321,9 @@ private function includes() { * so this is set to false for tests. */ if ( defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && true === WPGRAPHQL_WOOCOMMERCE_AUTOLOAD ) { - if ( file_exists( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php' ) ) { + if ( file_exists( get_vendor_directory() . 'autoload.php' ) ) { // Autoload Required Classes. - require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php'; + require_once get_vendor_directory() . 'autoload.php'; } /** @@ -176,16 +350,8 @@ function () { ); } ); - - return false; - }//end if + } }//end if - - // Required non-autoloaded classes. - require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'access-functions.php'; - require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'includes/functions.php'; - - return true; } /** @@ -193,23 +359,23 @@ function () { */ private function setup() { // Setup minor integrations. - \WPGraphQL\WooCommerce\Functions\setup_minor_integrations(); + Functions\setup_minor_integrations(); // Register WooCommerce filters. - \WPGraphQL\WooCommerce\WooCommerce_Filters::setup(); + WooCommerce_Filters::setup(); // Register WPGraphQL core filters. - \WPGraphQL\WooCommerce\Core_Schema_Filters::add_filters(); + Core_Schema_Filters::add_filters(); // Register WPGraphQL ACF filters. - \WPGraphQL\WooCommerce\ACF_Schema_Filters::add_filters(); + ACF_Schema_Filters::add_filters(); // Register WPGraphQL JWT Authentication filters. - \WPGraphQL\WooCommerce\JWT_Auth_Schema_Filters::add_filters(); + JWT_Auth_Schema_Filters::add_filters(); // Initialize WooGraphQL TypeRegistry. - $registry = new \WPGraphQL\WooCommerce\Type_Registry(); - add_action( 'graphql_register_types', array( $registry, 'init' ), 10, 1 ); + $registry = new Type_Registry(); + add_action( 'graphql_register_types', [ $registry, 'init' ], 10, 1 ); } } diff --git a/includes/connection/class-comments.php b/includes/connection/class-comments.php index 9421dece4..e7c8ec442 100644 --- a/includes/connection/class-comments.php +++ b/includes/connection/class-comments.php @@ -25,12 +25,12 @@ public static function register_connections() { // From Products. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Product', 'toType' => 'Comment', 'fromFieldName' => 'reviews', - 'connectionFields' => array( - 'averageRating' => array( + 'connectionFields' => [ + 'averageRating' => [ 'type' => 'Float', 'description' => __( 'Average review rating for this product.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -40,10 +40,10 @@ public static function register_connections() { $product = $source['edges'][0]['source']; return $product->averageRating; // @codingStandardsIgnoreLine }, - ), - ), - 'edgeFields' => array( - 'rating' => array( + ], + ], + 'edgeFields' => [ + 'rating' => [ 'type' => 'Float', 'description' => __( 'Review rating', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -52,8 +52,8 @@ public static function register_connections() { $rating = get_comment_meta( $review->commentId, 'rating', true ); return $rating ? $rating : 0; }, - ), - ), + ], + ], 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); @@ -62,19 +62,19 @@ public static function register_connections() { return $resolver->get_connection(); }, - ) + ] ) ); // From Orders. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Order', 'toType' => 'Comment', 'fromFieldName' => 'orderNotes', - 'edgeFields' => array( - 'isCustomerNote' => array( + 'edgeFields' => [ + 'isCustomerNote' => [ 'type' => 'Boolean', 'description' => __( 'Is this a customer note?', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -82,8 +82,8 @@ public static function register_connections() { // 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 ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); @@ -96,15 +96,15 @@ public static function register_connections() { $resolver->set_query_arg( 'meta_value', true ); } - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); + remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); $connection = $resolver->get_connection(); - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); + add_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); return $connection; }, - ) + ] ) ); } diff --git a/includes/connection/class-coupons.php b/includes/connection/class-coupons.php index d8d48825d..7f32606d9 100644 --- a/includes/connection/class-coupons.php +++ b/includes/connection/class-coupons.php @@ -34,9 +34,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'Coupon', 'fromFieldName' => 'coupons', @@ -45,12 +45,12 @@ public static function get_connection_config( $args = array() ): array { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'shop_coupon' ); if ( ! self::should_execute() ) { - return array(); + return []; } return $resolver->get_connection(); }, - ), + ], $args ); } @@ -78,12 +78,12 @@ public static function should_execute() { public static function get_connection_args(): array { return array_merge( get_wc_cpt_connection_args(), - array( - 'code' => array( + [ + 'code' => [ 'type' => 'String', 'description' => __( 'Limit result set to resources with a specific code.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -116,7 +116,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ if ( ! empty( $where_args['code'] ) ) { $id = \wc_get_coupon_id_by_code( $where_args['code'] ); - $ids = $id ? array( $id ) : array( '0' ); + $ids = $id ? [ $id ] : [ '0' ]; $query_args['post__in'] = ! empty( $query_args['post__in'] ) ? array_intersect( $ids, $query_args['post__in'] ) : $ids; diff --git a/includes/connection/class-customers.php b/includes/connection/class-customers.php index 67daf480d..e4ef7a95e 100644 --- a/includes/connection/class-customers.php +++ b/includes/connection/class-customers.php @@ -23,7 +23,7 @@ class Customers { */ public static function register_connections() { register_graphql_connection( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'Customer', 'fromFieldName' => 'customers', @@ -32,21 +32,21 @@ public static function register_connections() { $resolver = new UserConnectionResolver( $source, $args, $context, $info ); if ( ! self::should_execute() ) { - return array( - 'nodes' => array(), - 'edges' => array(), - ); + return [ + 'nodes' => [], + 'edges' => [], + ]; } $resolver->set_query_arg( 'role', 'customer' ); return $resolver->get_connection(); }, - ) + ] ); register_graphql_connection( - array( + [ 'fromType' => 'Coupon', 'toType' => 'Customer', 'fromFieldName' => 'usedBy', @@ -58,12 +58,12 @@ public static function register_connections() { $resolver->set_query_arg( 'role', 'customer' ); if ( ! self::should_execute() ) { - return array(); + return []; } return $resolver->get_connection(); }, - ) + ] ); } @@ -87,32 +87,32 @@ public static function should_execute() { * @return array */ public static function get_connection_args(): array { - return array( - 'search' => array( + return [ + 'search' => [ 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ), - 'exclude' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'exclude' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), - ), - 'include' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'include' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), - ), - 'email' => array( + ], + 'email' => [ 'type' => 'String', 'description' => __( 'Limit result set to resources with a specific email.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( + ], + 'orderby' => [ 'type' => 'CustomerConnectionOrderbyEnum', 'description' => __( 'Order results by a specific field.', 'wp-graphql-woocommerce' ), - ), - 'order' => array( + ], + 'order' => [ 'type' => 'OrderEnum', 'description' => __( 'Order of results.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -129,11 +129,11 @@ public static function get_connection_args(): array { * @return array Query arguments. */ public static function map_input_fields_to_wp_query( $query_args, $where_args, $source, $args, $context, $info ) { - $key_mapping = array( + $key_mapping = [ 'search' => 'search', 'exclude' => 'exclude', 'include' => 'include', - ); + ]; foreach ( $key_mapping as $key => $field ) { if ( ! empty( $where_args[ $key ] ) ) { @@ -144,7 +144,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ // Filter by email. if ( ! empty( $where_args['email'] ) ) { $query_args['search'] = $where_args['email']; - $query_args['search_columns'] = array( 'user_email' ); + $query_args['search_columns'] = [ 'user_email' ]; } /** diff --git a/includes/connection/class-orders.php b/includes/connection/class-orders.php index 32fe234ee..d2a0d194d 100644 --- a/includes/connection/class-orders.php +++ b/includes/connection/class-orders.php @@ -28,7 +28,7 @@ public static function register_connections() { // From Customer To Orders. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Customer', 'fromFieldName' => 'orders', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -36,25 +36,25 @@ public static function register_connections() { return self::get_customer_order_connection( $resolver, $source ); }, - ) + ] ) ); // From RootQuery To Refunds. register_graphql_connection( self::get_connection_config( - array( + [ 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - ), + ], 'shop_order_refund' ) ); // From Order To Refunds. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Order', 'toType' => 'Refund', 'fromFieldName' => 'refunds', @@ -66,14 +66,14 @@ public static function register_connections() { return $resolver->get_connection(); }, - ), + ], 'shop_order_refund' ) ); // From Customer To Refunds. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Customer', 'toType' => 'Refund', 'fromFieldName' => 'refunds', @@ -82,18 +82,18 @@ public static function register_connections() { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'shop_order_refund' ); $customer_orders = \wc_get_orders( - array( + [ 'customer_id' => $source->ID, 'no_rows_found' => true, 'return' => 'ids', - ) + ] ); $resolver->set_query_arg( 'post_parent__in', array_map( 'absint', $customer_orders ) ); return $resolver->get_connection(); }, - ), + ], 'shop_order_refund' ) ); @@ -110,7 +110,7 @@ public static function register_connections() { private static function get_customer_order_connection( $resolver, $customer ) { // If not "billing email" or "ID" set bail early by returning an empty connection. if ( empty( $customer->get_billing_email() ) && empty( $customer->get_id() ) ) { - return array(); + return []; } // If the querying user has a "billing email" set filter orders by user's billing email, otherwise filter by user's ID. @@ -135,11 +135,11 @@ private static function get_customer_order_connection( $resolver, $customer ) { private static function get_customer_refund_connection( $resolver, $customer ) { // If not "billing email" or "ID" set bail early by returning an empty connection. if ( empty( $customer->get_billing_email() ) && empty( $customer->get_id() ) ) { - return array( + return [ 'pageInfo' => null, - 'nodes' => array(), - 'edges' => array(), - ); + 'nodes' => [], + 'edges' => [], + ]; } } @@ -152,12 +152,12 @@ private static function get_customer_refund_connection( $resolver, $customer ) { * * @return array */ - public static function get_connection_config( $args = array(), $post_type = 'shop_order' ): array { + public static function get_connection_config( $args = [], $post_type = 'shop_order' ): array { // Get Post type object for use in connection resolve function. $post_object = get_post_type_object( $post_type ); return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'Order', 'fromFieldName' => 'orders', @@ -180,11 +180,11 @@ public static function get_connection_config( $args = array(), $post_type = 'sho * and return the connection. */ if ( 'shop_order_refund' === $post_object->name ) { - $empty_results = array( + $empty_results = [ 'pageInfo' => null, - 'nodes' => array(), - 'edges' => array(), - ); + 'nodes' => [], + 'edges' => [], + ]; return $not_manager ? $empty_results @@ -195,7 +195,7 @@ public static function get_connection_config( $args = array(), $post_type = 'sho ? self::get_customer_order_connection( $resolver, \WC()->customer ) : $resolver->get_connection(); }, - ), + ], $args ); } @@ -211,54 +211,54 @@ public static function get_connection_args( $access = 'public' ): array { case 'private': return array_merge( get_wc_cpt_connection_args(), - array( - 'statuses' => array( - 'type' => array( 'list_of' => 'OrderStatusEnum' ), + [ + 'statuses' => [ + 'type' => [ 'list_of' => 'OrderStatusEnum' ], 'description' => __( 'Limit result set to orders assigned a specific status.', 'wp-graphql-woocommerce' ), - ), - 'customerId' => array( + ], + 'customerId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific customer.', 'wp-graphql-woocommerce' ), - ), - 'customersIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'customersIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to orders assigned a specific group of customers.', 'wp-graphql-woocommerce' ), - ), - 'productId' => array( + ], + 'productId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific product.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( - 'type' => array( 'list_of' => 'OrdersOrderbyInput' ), + ], + 'orderby' => [ + 'type' => [ 'list_of' => 'OrdersOrderbyInput' ], 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); case 'public': default: - return array( - 'statuses' => array( - 'type' => array( 'list_of' => 'OrderStatusEnum' ), + return [ + 'statuses' => [ + 'type' => [ 'list_of' => 'OrderStatusEnum' ], 'description' => __( 'Limit result set to orders assigned a specific status.', 'wp-graphql-woocommerce' ), - ), - 'productId' => array( + ], + 'productId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to orders assigned a specific product.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( - 'type' => array( 'list_of' => 'OrdersOrderbyInput' ), + ], + 'orderby' => [ + 'type' => [ 'list_of' => 'OrdersOrderbyInput' ], 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ), - 'search' => array( + ], + 'search' => [ 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ), - 'dateQuery' => array( + ], + 'dateQuery' => [ 'type' => 'DateQueryInput', 'description' => __( 'Filter the connection based on dates.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; }//end switch } @@ -270,16 +270,16 @@ public static function get_connection_args( $access = 'public' ): array { public static function get_refund_connection_args(): array { return array_merge( get_wc_cpt_connection_args(), - array( - 'statuses' => array( - 'type' => array( 'list_of' => 'String' ), + [ + 'statuses' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to refunds assigned a specific status.', 'wp-graphql-woocommerce' ), - ), - 'orderIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'orderIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to refunds from a specific group of order IDs.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -295,9 +295,9 @@ public static function get_refund_connection_args(): array { * @return array */ public static function post_object_connection_query_args( $query_args, $source, $args, $context, $info ) { - $post_types = array( 'shop_order', 'shop_order_refund' ); + $post_types = [ 'shop_order', 'shop_order_refund' ]; $not_order_query = is_string( $query_args['post_type'] ) - ? empty( array_intersect( $post_types, array( $query_args['post_type'] ) ) ) + ? empty( array_intersect( $post_types, [ $query_args['post_type'] ] ) ) : empty( array_intersect( $post_types, $query_args['post_type'] ) ); if ( $not_order_query ) { @@ -328,8 +328,8 @@ public static function post_object_connection_query_args( $query_args, $source, * @return array Query arguments. */ public static function map_input_fields_to_wp_query( $query_args, $where_args, $source, $args, $context, $info, $post_type ) { - $post_types = array( 'shop_order', 'shop_order_refund' ); - if ( empty( array_intersect( $post_types, is_string( $post_type ) ? array( $post_type ) : $post_type ) ) ) { + $post_types = [ 'shop_order', 'shop_order_refund' ]; + if ( empty( array_intersect( $post_types, is_string( $post_type ) ? [ $post_type ] : $post_type ) ) ) { return $query_args; } @@ -341,8 +341,8 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ ); // Process order meta inputs. - $metas = array( 'customerId', 'customersIn' ); - $meta_query = array(); + $metas = [ 'customerId', 'customersIn' ]; + $meta_query = []; foreach ( $metas as $field ) { if ( isset( $query_args[ $field ] ) ) { $value = $query_args[ $field ]; @@ -350,31 +350,31 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ case 'customerId': case 'customersIn': if ( is_null( $value ) ) { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_customer_user', 'value' => 0, 'compare' => '=', - ); + ]; } else { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_customer_user', 'value' => $value, 'compare' => is_array( $value ) ? 'IN' : '=', - ); + ]; } } } }//end foreach if ( ! empty( $meta_query ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query $query_args['meta_query'] = $meta_query; - // WPCS: slow query ok. } - $key_mapping = array( + $key_mapping = [ 'statuses' => 'post_status', 'orderIn' => 'post_parent__in', - ); + ]; $prefixer = function( $status ) { $statuses = array_keys( \wc_get_order_statuses() ); @@ -407,6 +407,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ // Search by product. if ( ! empty( $where_args['productId'] ) ) { + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT order_id @@ -418,7 +419,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ ); // Force WP_Query return empty if don't found any order. - $query_args['post__in'] = ! empty( $order_ids ) ? $order_ids : array( 0 ); + $query_args['post__in'] = ! empty( $order_ids ) ? $order_ids : [ 0 ]; } // Search. diff --git a/includes/connection/class-payment-gateways.php b/includes/connection/class-payment-gateways.php index 8b3ad1b9f..4230abdc4 100644 --- a/includes/connection/class-payment-gateways.php +++ b/includes/connection/class-payment-gateways.php @@ -32,9 +32,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'PaymentGateway', 'fromFieldName' => 'paymentGateways', @@ -44,7 +44,7 @@ public static function get_connection_config( $args = array() ): array { return $resolver->resolve( $source, $args, $context, $info ); }, - ), + ], $args ); } @@ -55,11 +55,11 @@ public static function get_connection_config( $args = array() ): array { * @return array */ public static function get_connection_args(): array { - return array( - 'all' => array( + return [ + 'all' => [ 'type' => 'Boolean', 'description' => __( 'Include disabled payment gateways?', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } } diff --git a/includes/connection/class-posts.php b/includes/connection/class-posts.php index 64d5f016e..edb0c1ff5 100644 --- a/includes/connection/class-posts.php +++ b/includes/connection/class-posts.php @@ -26,7 +26,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( get_post_type_object( 'attachment' ), - array( + [ 'fromType' => 'Product', 'toType' => 'MediaItem', 'fromFieldName' => 'galleryImages', @@ -42,7 +42,7 @@ public static function register_connections() { return $resolver->get_connection(); }, - ) + ] ) ); } diff --git a/includes/connection/class-product-attributes.php b/includes/connection/class-product-attributes.php index 8bb6da586..732dce2c6 100644 --- a/includes/connection/class-product-attributes.php +++ b/includes/connection/class-product-attributes.php @@ -29,20 +29,20 @@ public static function register_connections() { // From Product to LocalProductAttribute. register_graphql_connection( self::get_connection_config( - array( + [ 'toType' => 'LocalProductAttribute', 'fromFieldName' => 'localAttributes', - ) + ] ) ); // From Product to GlobalProductAttribute. register_graphql_connection( self::get_connection_config( - array( + [ 'toType' => 'GlobalProductAttribute', 'fromFieldName' => 'globalAttributes', - ) + ] ) ); } @@ -54,9 +54,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'Product', 'toType' => 'ProductAttribute', 'fromFieldName' => 'attributes', @@ -66,7 +66,7 @@ public static function get_connection_config( $args = array() ): array { return $resolver->resolve( $source, $args, $context, $info ); }, - ), + ], $args ); } @@ -77,11 +77,11 @@ public static function get_connection_config( $args = array() ): array { * @return array */ public static function get_connection_args(): array { - return array( - 'type' => array( + return [ + 'type' => [ 'type' => 'ProductAttributeTypesEnum', 'description' => __( 'Filter results by attribute scope.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } } diff --git a/includes/connection/class-products.php b/includes/connection/class-products.php index 6d79280a5..e36ba5c14 100644 --- a/includes/connection/class-products.php +++ b/includes/connection/class-products.php @@ -11,6 +11,7 @@ use GraphQL\Type\Definition\ResolveInfo; use WPGraphQL\AppContext; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; use WPGraphQL\Data\Connection\PostObjectConnectionResolver; /** @@ -28,7 +29,7 @@ public static function register_connections() { // From Coupon. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Coupon', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -42,12 +43,12 @@ public static function register_connections() { return $resolver->get_connection(); }, - ) + ] ) ); register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProducts', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -62,24 +63,24 @@ public static function register_connections() { return $resolver->get_connection(); }, - ) + ] ) ); // Connections from all product types to related and upsell. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Product', 'fromFieldName' => 'related', 'connectionArgs' => array_merge( self::get_connection_args(), - array( - 'shuffle' => array( + [ + 'shuffle' => [ 'type' => 'Boolean', 'description' => __( 'Shuffle results? (Pagination currently not support by this argument)', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ), 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -104,12 +105,12 @@ function() { return $resolver->get_connection(); }, - ) + ] ) ); register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'Product', 'fromFieldName' => 'upsell', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { @@ -124,14 +125,14 @@ function() { return $resolver->get_connection(); }, - ) + ] ) ); // Group product children connection. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'GroupProduct', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -145,12 +146,12 @@ function() { return $resolver->get_connection(); }, - ) + ] ) ); // Product cross-sell connections. - $cross_sell_config = array( + $cross_sell_config = [ 'fromFieldName' => 'crossSell', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -164,22 +165,22 @@ function() { return $resolver->get_connection(); }, - ); + ]; register_graphql_connection( self::get_connection_config( - array_merge( array( 'fromType' => 'SimpleProduct' ), $cross_sell_config ) + array_merge( [ 'fromType' => 'SimpleProduct' ], $cross_sell_config ) ) ); register_graphql_connection( self::get_connection_config( - array_merge( array( 'fromType' => 'VariableProduct' ), $cross_sell_config ) + array_merge( [ 'fromType' => 'VariableProduct' ], $cross_sell_config ) ) ); // From VariableProduct to ProductVariation. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'VariableProduct', 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', @@ -199,12 +200,12 @@ function() { return $resolver->get_connection(); }, - ) + ] ) ); register_graphql_connection( - array( + [ 'fromType' => 'ProductVariation', 'toType' => 'VariableProduct', 'fromFieldName' => 'parent', @@ -222,21 +223,21 @@ function() { return $resolver->one_to_one()->get_connection(); }, - ) + ] ); // Taxonomy To Product resolver. $resolve_product_from_taxonomy = function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - $tax_query = array( - array( + $tax_query = [ + [ // WPCS: slow query ok. 'taxonomy' => $source->taxonomyName, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 'field' => 'term_id', 'terms' => $source->term_id, - ), - ); + ], + ]; $resolver->set_query_arg( 'tax_query', $tax_query ); $resolver = self::set_ordering_query_args( $resolver, $args ); @@ -247,37 +248,37 @@ function() { // From ProductCategory. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'ProductCategory', 'resolve' => $resolve_product_from_taxonomy, - ) + ] ) ); // From ProductTag. register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => 'ProductTag', 'resolve' => $resolve_product_from_taxonomy, - ) + ] ) ); // From WooCommerce product attributes. - $attributes = \WP_GraphQL_WooCommerce::get_product_attribute_taxonomies(); + $attributes = WP_GraphQL_WooCommerce::get_product_attribute_taxonomies(); foreach ( $attributes as $attribute ) { register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => ucfirst( graphql_format_field_name( $attribute ) ), 'resolve' => $resolve_product_from_taxonomy, - ) + ] ) ); register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => ucfirst( graphql_format_field_name( $attribute ) ), 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', @@ -287,6 +288,7 @@ function() { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $attribute_meta_key = 'attribute_' . strtolower( preg_replace( '/([A-Z])/', '_$1', $source->taxonomyName ) ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $variation_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID @@ -305,7 +307,7 @@ function() { return $resolver->get_connection(); }, - ) + ] ) ); }//end foreach @@ -318,9 +320,9 @@ function() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'Product', 'fromFieldName' => 'products', @@ -333,7 +335,7 @@ public static function get_connection_config( $args = array() ): array { return $resolver->get_connection(); }, - ), + ], $args ); } @@ -366,7 +368,7 @@ public static function set_ordering_query_args( $resolver, $args ) { $order = 'ASC' === $order ? 'DESC' : 'ASC'; } - $resolver->set_query_arg( 'orderby', array( 'meta_value_num' => $order ) ); + $resolver->set_query_arg( 'orderby', [ 'meta_value_num' => $order ] ); $resolver->set_query_arg( 'meta_key', esc_sql( $orderby_input['field'] ) ); $resolver->set_query_arg( 'meta_type', 'NUMERIC' ); break 2; @@ -383,138 +385,138 @@ public static function set_ordering_query_args( $resolver, $args ) { * @return array */ public static function get_connection_args(): array { - $args = array( - 'slugIn' => array( - 'type' => array( 'list_of' => 'String' ), + $args = [ + 'slugIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to products with specific slugs.', 'wp-graphql-woocommerce' ), - ), - 'status' => array( + ], + 'status' => [ 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific status.', 'wp-graphql-woocommerce' ), - ), - 'type' => array( + ], + 'type' => [ 'type' => 'ProductTypesEnum', 'description' => __( 'Limit result set to products assigned a specific type.', 'wp-graphql-woocommerce' ), - ), - 'typeIn' => array( - 'type' => array( 'list_of' => 'ProductTypesEnum' ), + ], + 'typeIn' => [ + 'type' => [ 'list_of' => 'ProductTypesEnum' ], 'description' => __( 'Limit result set to products assigned to a group of specific types.', 'wp-graphql-woocommerce' ), - ), - 'typeNotIn' => array( - 'type' => array( 'list_of' => 'ProductTypesEnum' ), + ], + 'typeNotIn' => [ + 'type' => [ 'list_of' => 'ProductTypesEnum' ], 'description' => __( 'Limit result set to products not assigned to a group of specific types.', 'wp-graphql-woocommerce' ), - ), - 'sku' => array( + ], + 'sku' => [ 'type' => 'String', 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'wp-graphql-woocommerce' ), - ), - 'featured' => array( + ], + 'featured' => [ 'type' => 'Boolean', 'description' => __( 'Limit result set to featured products.', 'wp-graphql-woocommerce' ), - ), - 'category' => array( + ], + 'category' => [ 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific category name.', 'wp-graphql-woocommerce' ), - ), - 'categoryIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'categoryIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to products assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), - ), - 'categoryNotIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'categoryNotIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to products not assigned to a group of specific categories by name.', 'wp-graphql-woocommerce' ), - ), - 'categoryId' => array( + ], + 'categoryId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific category name.', 'wp-graphql-woocommerce' ), - ), - 'categoryIdIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'categoryIdIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to products assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), - ), - 'categoryIdNotIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'categoryIdNotIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to products not assigned to a specific group of category IDs.', 'wp-graphql-woocommerce' ), - ), - 'tag' => array( + ], + 'tag' => [ 'type' => 'String', 'description' => __( 'Limit result set to products assigned a specific tag name.', 'wp-graphql-woocommerce' ), - ), - 'tagIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'tagIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to products assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), - ), - 'tagNotIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'tagNotIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Limit result set to products not assigned to a specific group of tags by name.', 'wp-graphql-woocommerce' ), - ), - 'tagId' => array( + ], + 'tagId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'wp-graphql-woocommerce' ), - ), - 'tagIdIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'tagIdIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to products assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), - ), - 'tagIdNotIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'tagIdNotIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to products not assigned to a specific group of tag IDs.', 'wp-graphql-woocommerce' ), - ), - 'shippingClassId' => array( + ], + 'shippingClassId' => [ 'type' => 'Int', 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'wp-graphql-woocommerce' ), - ), - 'attribute' => array( + ], + 'attribute' => [ 'type' => 'String', 'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'wp-graphql-woocommerce' ), - ), - 'attributeTerm' => array( + ], + 'attributeTerm' => [ 'type' => 'String', 'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'wp-graphql-woocommerce' ), - ), - 'stockStatus' => array( - 'type' => array( 'list_of' => 'StockStatusEnum' ), + ], + 'stockStatus' => [ + 'type' => [ 'list_of' => 'StockStatusEnum' ], 'description' => __( 'Limit result set to products in stock or out of stock.', 'wp-graphql-woocommerce' ), - ), - 'onSale' => array( + ], + 'onSale' => [ 'type' => 'Boolean', 'description' => __( 'Limit result set to products on sale.', 'wp-graphql-woocommerce' ), - ), - 'minPrice' => array( + ], + 'minPrice' => [ 'type' => 'Float', 'description' => __( 'Limit result set to products based on a minimum price.', 'wp-graphql-woocommerce' ), - ), - 'maxPrice' => array( + ], + 'maxPrice' => [ 'type' => 'Float', 'description' => __( 'Limit result set to products based on a maximum price.', 'wp-graphql-woocommerce' ), - ), - 'search' => array( + ], + 'search' => [ 'type' => 'String', 'description' => __( 'Limit result set to products based on a keyword search.', 'wp-graphql-woocommerce' ), - ), - 'visibility' => array( + ], + 'visibility' => [ 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Limit result set to products with a specific visibility level.', 'wp-graphql-woocommerce' ), - ), - 'taxonomyFilter' => array( + ], + 'taxonomyFilter' => [ 'type' => 'ProductTaxonomyInput', 'description' => __( 'Limit result set with complex set of taxonomy filters.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( - 'type' => array( 'list_of' => 'ProductsOrderbyInput' ), + ], + 'orderby' => [ + 'type' => [ 'list_of' => 'ProductsOrderbyInput' ], 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ), - 'supportedTypesOnly' => array( + ], + 'supportedTypesOnly' => [ 'type' => 'Boolean', 'description' => __( 'Limit result types to types supported by WooGraphQL.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; if ( wc_tax_enabled() ) { - $args['taxClass'] = array( + $args['taxClass'] = [ 'type' => 'TaxClassEnum', 'description' => __( 'Limit result set to products with a specific tax class.', 'wp-graphql-woocommerce' ), - ); + ]; } return array_merge( get_wc_cpt_connection_args(), $args ); @@ -544,7 +546,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ map_shared_input_fields_to_wp_query( $where_args ) ); - $remove = array( + $remove = [ 'cat', 'category_name', 'category__in', @@ -553,7 +555,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ 'tag__and', 'tag__in', 'tag__not_in', - ); + ]; $query_args = array_diff_key( $query_args, array_flip( $remove ) ); @@ -561,8 +563,8 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ $query_args['post_name__in'] = $where_args['slugIn']; } - $tax_query = array(); - $taxonomy_args = array( + $tax_query = []; + $taxonomy_args = [ 'type' => 'product_type', 'typeIn' => 'product_type', 'typeNotIn' => 'product_type', @@ -578,7 +580,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ 'tagId' => 'product_tag', 'tagIdIn' => 'product_tag', 'tagIdNotIn' => 'product_tag', - ); + ]; foreach ( $taxonomy_args as $field => $taxonomy ) { if ( ! empty( $where_args[ $field ] ) ) { @@ -603,12 +605,12 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ case 'tag': case 'tagIn': case 'tagNotIn': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $where_args[ $field ], 'operator' => $operator, - ); + ]; break; case 'categoryId': case 'categoryIdIn': @@ -616,12 +618,12 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ case 'tagId': case 'tagIdIn': case 'tagIdNotIn': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $where_args[ $field ], 'operator' => $operator, - ); + ]; break; }//end switch }//end if @@ -634,48 +636,48 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ // Filter by attribute and term. if ( ! empty( $where_args['attribute'] ) && ! empty( $where_args['attributeTerm'] ) ) { if ( in_array( $where_args['attribute'], \wc_get_attribute_taxonomy_names(), true ) ) { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $where_args['attribute'], 'field' => 'slug', 'terms' => $where_args['attributeTerm'], - ); + ]; } } if ( empty( $where_args['type'] ) && empty( $where_args['typeIn'] ) && ! empty( $where_args['supportedTypesOnly'] ) && true === $where_args['supportedTypesOnly'] ) { - $supported_types = array_keys( \WP_GraphQL_WooCommerce::get_enabled_product_types() ); + $supported_types = array_keys( WP_GraphQL_WooCommerce::get_enabled_product_types() ); $terms = ! empty( $where_args['typeNotIn'] ) ? array_diff( $supported_types, $where_args['typeNotIn'] ) : $supported_types; - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $terms, - ); + ]; } if ( isset( $where_args['featured'] ) ) { $product_visibility_term_ids = wc_get_product_visibility_term_ids(); if ( $where_args['featured'] ) { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['featured'] ), - ); - $tax_query[] = array( + 'terms' => [ $product_visibility_term_ids['featured'] ], + ]; + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['exclude-from-catalog'] ), + 'terms' => [ $product_visibility_term_ids['exclude-from-catalog'] ], 'operator' => 'NOT IN', - ); + ]; } else { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['featured'] ), + 'terms' => [ $product_visibility_term_ids['featured'] ], 'operator' => 'NOT IN', - ); + ]; } }//end if @@ -684,36 +686,36 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ if ( ! empty( $where_args['visibility'] ) ) { switch ( $where_args['visibility'] ) { case 'search': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-search' ), + 'terms' => [ 'exclude-from-search' ], 'operator' => 'NOT IN', - ); + ]; break; case 'catalog': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog' ), + 'terms' => [ 'exclude-from-catalog' ], 'operator' => 'NOT IN', - ); + ]; break; case 'visible': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], 'operator' => 'NOT IN', - ); + ]; break; case 'hidden': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], 'operator' => 'AND', - ); + ]; break; }//end switch }//end if @@ -724,30 +726,30 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ $relation = ! empty( $taxonomy_query['relation'] ) ? $taxonomy_query['relation'] : 'AND'; if ( ! empty( $taxonomy_query['filters'] ) ) { - $tax_groups = array(); + $tax_groups = []; foreach ( $taxonomy_query['filters'] as $filter ) { - $common = array( + $common = [ 'taxonomy' => $filter['taxonomy'], 'operator' => ! empty( $filter['operator'] ) ? $filter['operator'] : 'IN', - ); + ]; if ( ! empty( $filter['ids'] ) ) { $tax_groups[] = array_merge( $common, - array( + [ 'field' => 'ID', 'terms' => $filter['ids'], - ) + ] ); } if ( ! empty( $filter['terms'] ) ) { $tax_groups[] = array_merge( $common, - array( + [ 'field' => 'slug', 'terms' => $filter['terms'], - ) + ] ); } }//end foreach @@ -763,17 +765,17 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ }//end if if ( ! empty( $tax_query ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query $query_args['tax_query'] = $tax_query; - // WPCS: slow query ok. } - $meta_query = array(); + $meta_query = []; if ( ! empty( $where_args['sku'] ) ) { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_sku', 'value' => $where_args['sku'], 'compare' => 'LIKE', - ); + ]; } if ( ! empty( $where_args['minPrice'] ) || ! empty( $where_args['maxPrice'] ) ) { @@ -787,34 +789,34 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ $meta_query[] = apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'woocommerce_get_min_max_price_meta_query', - array( + [ 'key' => '_price', - 'value' => array( $current_min_price, $current_max_price ), + 'value' => [ $current_min_price, $current_max_price ], 'compare' => 'BETWEEN', 'type' => 'DECIMAL(10,' . wc_get_price_decimals() . ')', - ), + ], $query_args ); } if ( isset( $where_args['stockStatus'] ) ) { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_stock_status', 'value' => $where_args['stockStatus'], 'compare' => is_array( $where_args['stockStatus'] ) ? 'IN' : '=', - ); + ]; } if ( ! empty( $meta_query ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query $query_args['meta_query'] = $meta_query; - // WPCS: slow query ok. } if ( ! empty( $where_args['onSale'] ) && is_bool( $where_args['onSale'] ) ) { $on_sale_key = $where_args['onSale'] ? 'post__in' : 'post__not_in'; $on_sale_ids = \wc_get_product_ids_on_sale(); - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; + $on_sale_ids = empty( $on_sale_ids ) ? [ 0 ] : $on_sale_ids; $query_args[ $on_sale_key ] = $on_sale_ids; } @@ -833,7 +835,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ */ $query_args = apply_filters_deprecated( 'graphql_map_input_fields_to_product_query', - array( + [ $query_args, $where_args, $source, @@ -841,7 +843,7 @@ public static function map_input_fields_to_wp_query( $query_args, $where_args, $ $context, $info, $post_type, - ), + ], '0.9.0', 'graphql_map_input_fields_to_wp_query' ); diff --git a/includes/connection/class-shipping-methods.php b/includes/connection/class-shipping-methods.php index c03f860ed..4dbd141d3 100644 --- a/includes/connection/class-shipping-methods.php +++ b/includes/connection/class-shipping-methods.php @@ -34,19 +34,19 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'ShippingMethod', 'fromFieldName' => 'shippingMethods', - 'connectionArgs' => array(), + 'connectionArgs' => [], 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ), + ], $args ); } diff --git a/includes/connection/class-tax-rates.php b/includes/connection/class-tax-rates.php index e50a33ca9..7ce4cffc3 100644 --- a/includes/connection/class-tax-rates.php +++ b/includes/connection/class-tax-rates.php @@ -34,9 +34,9 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'RootQuery', 'toType' => 'TaxRate', 'fromFieldName' => 'taxRates', @@ -46,7 +46,7 @@ public static function get_connection_config( $args = array() ): array { return $resolver->get_connection(); }, - ), + ], $args ); } @@ -57,23 +57,23 @@ public static function get_connection_config( $args = array() ): array { * @return array */ public static function get_connection_args(): array { - return array( - 'class' => array( + return [ + 'class' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Sort by tax class.', 'wp-graphql-woocommerce' ), - ), - 'postCode' => array( + ], + 'postCode' => [ 'type' => 'String', 'description' => __( 'Filter results by a post code.', 'wp-graphql-woocommerce' ), - ), - 'postCodeIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'postCodeIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Filter results by a group of post codes.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( - 'type' => array( 'list_of' => 'TaxRateConnectionOrderbyInput' ), + ], + 'orderby' => [ + 'type' => [ 'list_of' => 'TaxRateConnectionOrderbyInput' ], 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } } diff --git a/includes/connection/class-variation-attributes.php b/includes/connection/class-variation-attributes.php index ba0978e28..ccd04721c 100644 --- a/includes/connection/class-variation-attributes.php +++ b/includes/connection/class-variation-attributes.php @@ -12,6 +12,7 @@ use GraphQL\Type\Definition\ResolveInfo; use WPGraphQL\AppContext; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; use WPGraphQL\WooCommerce\Data\Connection\Variation_Attribute_Connection_Resolver; /** @@ -27,14 +28,14 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config() ); // From product types. - $product_types = array_values( \WP_GraphQL_WooCommerce::get_enabled_product_types() ); + $product_types = array_values( WP_GraphQL_WooCommerce::get_enabled_product_types() ); foreach ( $product_types as $product_type ) { register_graphql_connection( self::get_connection_config( - array( + [ 'fromType' => $product_type, 'fromFieldName' => 'defaultAttributes', - ) + ] ) ); } @@ -47,19 +48,19 @@ public static function register_connections() { * @param array $args - Connection configuration. * @return array */ - public static function get_connection_config( $args = array() ): array { + public static function get_connection_config( $args = [] ): array { return array_merge( - array( + [ 'fromType' => 'ProductVariation', 'toType' => 'VariationAttribute', 'fromFieldName' => 'attributes', - 'connectionArgs' => array(), + 'connectionArgs' => [], 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Variation_Attribute_Connection_Resolver(); return $resolver->resolve( $source, $args, $context, $info ); }, - ), + ], $args ); } diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index 94595a9fc..7bd0230b4 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -17,7 +17,7 @@ use WPGraphQL\Data\DataSource; use WPGraphQL\Data\Connection\TermObjectConnectionResolver; use WPGraphQL; -use WP_GraphQL_WooCommerce; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; /** * Class - WC_Terms @@ -44,7 +44,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( $tax_object, - array( + [ 'fromType' => $post_type_object->graphql_single_name, 'toType' => $tax_object->graphql_single_name, 'fromFieldName' => $tax_object->graphql_plural_name, @@ -53,11 +53,11 @@ public static function register_connections() { $term_ids = \wc_get_object_terms( $source->ID, $tax_object->name, 'term_id' ); - $resolver->set_query_arg( 'term_taxonomy_id', ! empty( $term_ids ) ? $term_ids : array( '0' ) ); + $resolver->set_query_arg( 'term_taxonomy_id', ! empty( $term_ids ) ? $term_ids : [ '0' ] ); return $resolver->get_connection(); }, - ) + ] ) ); }//end if @@ -71,7 +71,7 @@ public static function register_connections() { register_graphql_connection( self::get_connection_config( $tax_object, - array( + [ 'fromType' => 'Coupon', 'fromFieldName' => 'productCategories', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { @@ -80,27 +80,27 @@ public static function register_connections() { return $resolver->get_connection(); }, - ) + ] ) ); register_graphql_connection( self::get_connection_config( $tax_object, - array( + [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProductCategories', 'resolve' => function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { - $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); + $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $resolver->set_query_arg( 'term_taxonomy_id', $source->excluded_product_category_ids ); return $resolver->get_connection(); }, - ) + ] ) ); register_graphql_connection( - array( + [ 'fromType' => 'GlobalProductAttribute', 'toType' => 'TermNode', 'queryClass' => 'WP_Term_Query', @@ -115,7 +115,7 @@ public static function register_connections() { $resolver->set_query_arg( 'slug', $source->get_slugs() ); return $resolver->get_connection(); }, - ) + ] ); } } diff --git a/includes/connection/wc-cpt-connection-args.php b/includes/connection/wc-cpt-connection-args.php index da200466c..b54125cb1 100644 --- a/includes/connection/wc-cpt-connection-args.php +++ b/includes/connection/wc-cpt-connection-args.php @@ -14,40 +14,40 @@ * @return array */ function get_wc_cpt_connection_args(): array { - return array( - 'search' => array( + return [ + 'search' => [ 'type' => 'String', 'description' => __( 'Limit results to those matching a string.', 'wp-graphql-woocommerce' ), - ), - 'exclude' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'exclude' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Ensure result set excludes specific IDs.', 'wp-graphql-woocommerce' ), - ), - 'include' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'include' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Limit result set to specific ids.', 'wp-graphql-woocommerce' ), - ), - 'orderby' => array( - 'type' => array( 'list_of' => 'PostTypeOrderbyInput' ), + ], + 'orderby' => [ + 'type' => [ 'list_of' => 'PostTypeOrderbyInput' ], 'description' => __( 'What paramater to use to order the objects by.', 'wp-graphql-woocommerce' ), - ), - 'dateQuery' => array( + ], + 'dateQuery' => [ 'type' => 'DateQueryInput', 'description' => __( 'Filter the connection based on dates.', 'wp-graphql-woocommerce' ), - ), - 'parent' => array( + ], + 'parent' => [ 'type' => 'Int', 'description' => __( 'Use ID to return only children. Use 0 to return only top-level items.', 'wp-graphql-woocommerce' ), - ), - 'parentIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'parentIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Specify objects whose parent is in an array.', 'wp-graphql-woocommerce' ), - ), - 'parentNotIn' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'parentNotIn' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'Specify objects whose parent is not in an array.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -58,8 +58,8 @@ function get_wc_cpt_connection_args(): array { * * @return array */ -function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = array() ) { - $args = array(); +function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = [] ) { + $args = []; if ( ! empty( $input['include'] ) ) { $args['post__in'] = $input['include']; } @@ -74,7 +74,7 @@ function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = arr if ( ! empty( $input['parentIn'] ) ) { if ( ! isset( $args['post_parent__in'] ) ) { - $args['post_parent__in'] = array(); + $args['post_parent__in'] = []; } $args['post_parent__in'] = array_merge( $args['post_parent__in'], $input['parentIn'] ); } @@ -91,14 +91,14 @@ function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = arr * Map the orderby inputArgs to the WP_Query */ if ( ! empty( $input['orderby'] ) && is_array( $input['orderby'] ) ) { - $args['orderby'] = array(); + $args['orderby'] = []; foreach ( $input['orderby'] as $orderby_input ) { /** * These orderby options should not include the order parameter. */ if ( in_array( $orderby_input['field'], - array( 'post__in', 'post_name__in', 'post_parent__in' ), + [ 'post__in', 'post_name__in', 'post_parent__in' ], true ) ) { $args['orderby'] = esc_sql( $orderby_input['field'] ); @@ -106,8 +106,8 @@ function map_shared_input_fields_to_wp_query( array $input, $ordering_meta = arr // Handle meta fields. } elseif ( in_array( $orderby_input['field'], $ordering_meta, true ) ) { $args['orderby']['meta_value_num'] = $orderby_input['order']; - $args['meta_key'] = esc_sql( $orderby_input['field'] ); - // WPCS: slow query ok. + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + $args['meta_key'] = esc_sql( $orderby_input['field'] ); // Handle post object fields. } elseif ( ! empty( $orderby_input['field'] ) ) { diff --git a/includes/data/class-factory.php b/includes/data/class-factory.php index ce30e9d7c..1044b9ef5 100644 --- a/includes/data/class-factory.php +++ b/includes/data/class-factory.php @@ -50,7 +50,7 @@ public static function resolve_customer( $id, AppContext $context ) { } $customer_id = absint( $id ); $loader = $context->getLoader( 'wc_customer' ); - $loader->buffer( array( $customer_id ) ); + $loader->buffer( [ $customer_id ] ); return new Deferred( function () use ( $loader, $customer_id ) { return $loader->load( $customer_id ); @@ -72,7 +72,7 @@ public static function resolve_crud_object( $id, AppContext $context ) { return null; } - $context->getLoader( 'wc_post' )->buffer( array( $id ) ); + $context->getLoader( 'wc_post' )->buffer( [ $id ] ); return new Deferred( function () use ( $id, $context ) { return $context->getLoader( 'wc_post' )->load( $id ); @@ -115,7 +115,7 @@ public static function resolve_tax_rate( $id, AppContext $context ) { $id = absint( $id ); $loader = $context->getLoader( 'tax_rate' ); - $loader->buffer( array( $id ) ); + $loader->buffer( [ $id ] ); return new Deferred( function () use ( $loader, $id ) { return $loader->load( $id ); @@ -169,7 +169,7 @@ public static function resolve_cart_item( $key, AppContext $context ) { return null; } - $context->getLoader( 'cart_item' )->buffer( array( $key ) ); + $context->getLoader( 'cart_item' )->buffer( [ $key ] ); return new Deferred( function () use ( $key, $context ) { return $context->getLoader( 'cart_item' )->load( $key ); @@ -206,7 +206,7 @@ public static function resolve_downloadable_item( $id, AppContext $context ) { } $object_id = absint( $id ); $loader = $context->getLoader( 'downloadable_item' ); - $loader->buffer( array( $object_id ) ); + $loader->buffer( [ $object_id ] ); return new Deferred( function () use ( $loader, $object_id ) { return $loader->load( $object_id ); diff --git a/includes/data/connection/class-cart-item-connection-resolver.php b/includes/data/connection/class-cart-item-connection-resolver.php index 69053e3b9..83125bc73 100644 --- a/includes/data/connection/class-cart-item-connection-resolver.php +++ b/includes/data/connection/class-cart-item-connection-resolver.php @@ -46,7 +46,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = array( 'filters' => array() ); + $query_args = [ 'filters' => [] ]; if ( ! empty( $this->args['where'] ) ) { $where_args = $this->args['where']; if ( isset( $where_args['needsShipping'] ) ) { @@ -86,27 +86,6 @@ public function get_query() { } } - $cursor = $this->get_offset(); - $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; - $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; - - // MUST DO FOR SANITY ~ If last, reverse list for correct slicing. - if ( $last ) { - $cart_items = array_reverse( $cart_items ); - } - - // Set offset. - $offset = $cursor - ? array_search( $cursor, array_column( $cart_items, 'key' ), true ) - : 0; - - // If cursor set, move index up one to ensure cursor not included in keys. - if ( $cursor ) { - $offset++; - } - - $cart_items = array_slice( $cart_items, $offset, $this->query_amount + 1 ); - // Cache cart items for later. foreach ( $cart_items as $item ) { $this->loader->prime( $item['key'], $item ); @@ -117,12 +96,12 @@ public function get_query() { } /** - * Return an array of items from the query - * - * @return array + * {@inheritDoc} */ - public function get_ids() { - return ! empty( $this->query ) ? $this->query : array(); + public function get_ids_from_query() { + $ids = ! empty( $this->query ) ? $this->query : []; + + return $ids; } /** @@ -147,35 +126,4 @@ public function is_valid_offset( $offset ) { protected function is_valid_model( $model ) { return ! empty( $model ) && ! empty( $model['key'] ) && ! empty( $model['product_id'] ); } - - /** - * Get_offset - * - * This returns the offset to be used in the $query_args based on the $args passed to the - * GraphQL query. - * - * @return int|mixed - */ - public function get_offset() { - /** - * Defaults - */ - $offset = 0; - - /** - * Get the $after offset - */ - if ( ! empty( $this->args['after'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) ); - } elseif ( ! empty( $this->args['before'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) ); - } - - /** - * Return the higher of the two values - */ - return $offset; - } } diff --git a/includes/data/connection/class-coupon-connection-resolver.php b/includes/data/connection/class-coupon-connection-resolver.php index 1e9b84474..22e7d98f7 100644 --- a/includes/data/connection/class-coupon-connection-resolver.php +++ b/includes/data/connection/class-coupon-connection-resolver.php @@ -98,15 +98,16 @@ public function get_query_args() { $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; // Set the $query_args based on various defaults and primary input $args. - $query_args = array( + $query_args = [ 'post_type' => 'shop_coupon', 'post_status' => 'any', 'perm' => 'readable', 'no_rows_found' => true, 'fields' => 'ids', + // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'posts_per_page' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, 'post_parent' => 0, - ); + ]; /** * Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support @@ -131,7 +132,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -184,7 +185,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query->posts ) ? $this->query->posts : array(); + return ! empty( $this->query->posts ) ? $this->query->posts : []; } /** @@ -193,7 +194,7 @@ public function get_ids() { * @return array */ public function ordering_meta() { - return array(); + return []; } /** @@ -211,7 +212,7 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['code'] ) ) { $id = \wc_get_coupon_id_by_code( $where_args['code'] ); - $ids = $id ? array( $id ) : array( '0' ); + $ids = $id ? [ $id ] : [ '0' ]; $args['post__in'] = isset( $args['post__in'] ) ? array_intersect( $ids, $args['post__in'] ) : $ids; diff --git a/includes/data/connection/class-customer-connection-resolver.php b/includes/data/connection/class-customer-connection-resolver.php index d9314b22c..dc653c1da 100644 --- a/includes/data/connection/class-customer-connection-resolver.php +++ b/includes/data/connection/class-customer-connection-resolver.php @@ -68,7 +68,7 @@ public function get_query_args() { $query_args['graphql_cursor_offset'] = $cursor_offset; $query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<'; - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -96,17 +96,17 @@ public function get_query_args() { * Map the orderby inputArgs to the WP_User_Query */ if ( ! empty( $this->args['where']['orderby'] ) && is_array( $this->args['where']['orderby'] ) ) { - $query_args['orderby'] = array(); + $query_args['orderby'] = []; foreach ( $this->args['where']['orderby'] as $orderby_input ) { /** * These orderby options should not include the order parameter. */ - if ( in_array( $orderby_input['field'], array( 'login__in', 'nicename__in' ), true ) ) { + if ( in_array( $orderby_input['field'], [ 'login__in', 'nicename__in' ], true ) ) { $query_args['orderby'] = esc_sql( $orderby_input['field'] ); } elseif ( ! empty( $orderby_input['field'] ) ) { - $query_args['orderby'] = array( + $query_args['orderby'] = [ esc_sql( $orderby_input['field'] ) => esc_sql( $orderby_input['order'] ), - ); + ]; } } } @@ -116,10 +116,10 @@ public function get_query_args() { * graphql_wp_term_query_cursor_pagination_support knowns how to handle */ if ( isset( $query_args['orderby'] ) && 'meta_value_num' === $query_args['orderby'] ) { - $query_args['orderby'] = array( + $query_args['orderby'] = [ + //phpcs:ignore WordPress.DB.SlowDBQuery 'meta_value' => empty( $query_args['order'] ) ? 'DESC' : $query_args['order'], - // WPCS: slow query OK. - ); + ]; unset( $query_args['order'] ); $query_args['meta_type'] = 'NUMERIC'; } @@ -167,7 +167,7 @@ public function get_query() { */ public function get_ids() { $results = $this->get_query()->get_results(); - return ! empty( $results ) ? $results : array(); + return ! empty( $results ) ? $results : []; } /** @@ -181,16 +181,16 @@ public function get_ids() { * @return array */ public function sanitize_input_fields( array $where_args ) { - $args = array(); + $args = []; - $key_mapping = array( + $key_mapping = [ 'search' => 'search', 'exclude' => 'exclude', 'include' => 'include', 'role' => 'role', 'roleIn' => 'role__in', 'roleNotIn' => 'role__not_in', - ); + ]; foreach ( $key_mapping as $key => $field ) { if ( ! empty( $where_args[ $key ] ) ) { @@ -201,7 +201,7 @@ public function sanitize_input_fields( array $where_args ) { // Filter by email. if ( ! empty( $where_args['email'] ) ) { $args['search'] = $where_args['email']; - $args['search_columns'] = array( 'user_email' ); + $args['search_columns'] = [ 'user_email' ]; } /** @@ -236,7 +236,7 @@ public function is_valid_offset( $offset ) { if ( ! empty( wp_cache_get( $offset, 'users' ) ) ) { return true; } - + // phpcs:ignore WordPress.DB.DirectDatabaseQuery return $wpdb->get_var( $wpdb->prepare( "SELECT EXISTS (SELECT 1 FROM $wpdb->users WHERE ID = %d)", $offset ) ); } } diff --git a/includes/data/connection/class-downloadable-item-connection-resolver.php b/includes/data/connection/class-downloadable-item-connection-resolver.php index 4bc8583f6..3d350d7ca 100644 --- a/includes/data/connection/class-downloadable-item-connection-resolver.php +++ b/includes/data/connection/class-downloadable-item-connection-resolver.php @@ -47,7 +47,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = array( 'filters' => array() ); + $query_args = [ 'filters' => [] ]; if ( ! empty( $this->args['where'] ) ) { $where_args = $this->args['where']; if ( isset( $where_args['active'] ) ) { @@ -118,7 +118,7 @@ public function get_query() { } if ( empty( $items ) ) { - return array(); + return []; } if ( ! empty( $this->query_args['filters'] ) && is_array( $this->query_args['filters'] ) ) { @@ -127,27 +127,6 @@ public function get_query() { } } - $cursor = $this->get_offset(); - $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; - $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; - - // MUST DO FOR SANITY ~ If last, reverse list for correct slicing. - if ( $last ) { - $items = array_reverse( $items ); - } - - // Set offset. - $offset = $cursor - ? array_search( $cursor, array_column( $items, 'download_id' ), true ) - : 0; - - // If cursor set, move index up one to ensure cursor not included in keys. - if ( $cursor ) { - $offset++; - } - - $items = array_slice( $items, $offset, $this->query_amount + 1 ); - // Cache items for later. foreach ( $items as $item ) { $this->loader->prime( $item['download_id'], $item ); @@ -161,8 +140,10 @@ public function get_query() { * * @return array */ - public function get_ids() { - return ! empty( $this->query ) ? $this->query : array(); + public function get_ids_from_query() { + $ids = ! empty( $this->query ) ? $this->query : []; + + return $ids; } /** @@ -189,36 +170,4 @@ public function is_valid_offset( $offset ) { protected function is_valid_model( $model ) { return isset( $model ) && ! empty( $model['download_id'] ); } - - - /** - * Get_offset - * - * This returns the offset to be used in the $query_args based on the $args passed to the - * GraphQL query. - * - * @return int|mixed - */ - public function get_offset() { - /** - * Defaults - */ - $offset = 0; - - /** - * Get the $after offset - */ - if ( ! empty( $this->args['after'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) ); - } elseif ( ! empty( $this->args['before'] ) ) { - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode - $offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) ); - } - - /** - * Return the higher of the two values - */ - return $offset; - } } diff --git a/includes/data/connection/class-order-connection-resolver.php b/includes/data/connection/class-order-connection-resolver.php index 8a3317ca4..1784b0f53 100644 --- a/includes/data/connection/class-order-connection-resolver.php +++ b/includes/data/connection/class-order-connection-resolver.php @@ -99,12 +99,12 @@ public function get_query_args() { $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; // Set the $query_args based on various defaults and primary input $args. - $query_args = array( + $query_args = [ 'post_type' => 'shop_order', 'no_rows_found' => true, 'return' => 'ids', 'limit' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, - ); + ]; /** * Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support @@ -129,7 +129,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -182,7 +182,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : array(); + return ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : []; } /** @@ -191,14 +191,14 @@ public function get_ids() { * @return array */ public function ordering_meta() { - return array( + return [ '_order_key', '_cart_discount', '_order_total', '_order_tax', '_date_paid', '_date_completed', - ); + ]; } /** @@ -215,11 +215,11 @@ public function sanitize_input_fields( array $where_args ) { global $wpdb; $args = $this->sanitize_common_inputs( $where_args ); - $key_mapping = array( + $key_mapping = [ 'post_parent' => 'parent', 'post_parent__not_in' => 'parent_exclude', 'post__not_in' => 'exclude', - ); + ]; foreach ( $key_mapping as $key => $field ) { if ( isset( $args[ $key ] ) ) { @@ -246,6 +246,7 @@ public function sanitize_input_fields( array $where_args ) { // Search by product. if ( ! empty( $where_args['productId'] ) ) { + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $order_ids = $wpdb->get_col( $wpdb->prepare( "SELECT order_id @@ -257,7 +258,7 @@ public function sanitize_input_fields( array $where_args ) { ); // Force WP_Query return empty if don't found any order. - $args['post__in'] = ! empty( $order_ids ) ? $order_ids : array( 0 ); + $args['post__in'] = ! empty( $order_ids ) ? $order_ids : [ 0 ]; } // Search. diff --git a/includes/data/connection/class-order-item-connection-resolver.php b/includes/data/connection/class-order-item-connection-resolver.php index 10a350ff4..6a6bb135c 100644 --- a/includes/data/connection/class-order-item-connection-resolver.php +++ b/includes/data/connection/class-order-item-connection-resolver.php @@ -47,7 +47,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = array( 'filters' => array() ); + $query_args = [ 'filters' => [] ]; /** * Filter the $query_args to allow folks to customize queries programmatically. @@ -88,7 +88,7 @@ public function get_query() { break; } - $items = array(); + $items = []; foreach ( $this->source->get_items( $type ) as $id => $item ) { $item->cached_order = $this->source; $item->cached_id = $id; @@ -96,7 +96,7 @@ public function get_query() { } if ( empty( $items ) ) { - return array(); + return []; } if ( ! empty( $this->query_args['filters'] ) && is_array( $this->query_args['filters'] ) ) { @@ -147,7 +147,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query ) ? $this->query : array(); + return ! empty( $this->query ) ? $this->query : []; } /** diff --git a/includes/data/connection/class-payment-gateway-connection-resolver.php b/includes/data/connection/class-payment-gateway-connection-resolver.php index 67bdc9f35..0c3abb5be 100644 --- a/includes/data/connection/class-payment-gateway-connection-resolver.php +++ b/includes/data/connection/class-payment-gateway-connection-resolver.php @@ -41,7 +41,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo } $connection = Relay::connectionFromArray( array_values( $gateways ), $args ); - $nodes = array(); + $nodes = []; if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/class-product-attribute-connection-resolver.php b/includes/data/connection/class-product-attribute-connection-resolver.php index c36d507df..3b6262ded 100644 --- a/includes/data/connection/class-product-attribute-connection-resolver.php +++ b/includes/data/connection/class-product-attribute-connection-resolver.php @@ -35,7 +35,7 @@ class Product_Attribute_Connection_Resolver { * @return array */ private function get_items( $attributes, $source, $args, $context, $info ) { - $items = array(); + $items = []; foreach ( $attributes as $attribute_name => $data ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode $data->_relay_id = base64_encode( @@ -86,7 +86,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo $attributes = $this->get_items( $source->attributes, $source, $args, $context, $info ); $connection = Relay::connectionFromArray( $attributes, $args ); - $nodes = array(); + $nodes = []; if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/class-product-connection-resolver.php b/includes/data/connection/class-product-connection-resolver.php index 2be741800..248d37bdc 100644 --- a/includes/data/connection/class-product-connection-resolver.php +++ b/includes/data/connection/class-product-connection-resolver.php @@ -15,6 +15,7 @@ use GraphQL\Type\Definition\ResolveInfo; use WPGraphQL\AppContext; use WPGraphQL\Model\Term; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; use WPGraphQL\WooCommerce\Model\Coupon; use WPGraphQL\WooCommerce\Model\Customer; use WPGraphQL\WooCommerce\Model\Product; @@ -43,12 +44,12 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { * * @var array */ - public static $default_visibility = array( + public static $default_visibility = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], 'operator' => 'NOT IN', - ); + ]; /** * Refund_Connection_Resolver constructor. @@ -119,20 +120,21 @@ public function get_query_args() { // Set the $query_args based on various defaults and primary input $args. $post_type_obj = get_post_type_object( $this->post_type ); - $query_args = array( + $query_args = [ 'post_type' => $this->post_type, 'post_status' => current_user_can( $post_type_obj->cap->edit_posts ) ? 'any' : 'publish', 'perm' => 'readable', 'no_rows_found' => true, 'fields' => 'ids', + // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'posts_per_page' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, 'ignore_sticky_posts' => true, - ); + ]; /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -157,13 +159,13 @@ public function get_query_args() { // Determine where we're at in the Graph and adjust the query context appropriately. if ( isset( $query_args['post__in'] ) && empty( $query_args['post__in'] ) ) { - $query_args['post__in'] = array( '0' ); + $query_args['post__in'] = [ '0' ]; } if ( ! current_user_can( $post_type_obj->cap->read_private_posts ) ) { if ( empty( $query_args['tax_query'] ) ) { - $query_args['tax_query'] = array(); - // WPCS: slow query ok. + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + $query_args['tax_query'] = []; } /** @@ -244,7 +246,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query->posts ) ? $this->query->posts : array(); + return ! empty( $this->query->posts ) ? $this->query->posts : []; } /** @@ -253,7 +255,7 @@ public function get_ids() { * @return array */ public function ordering_meta() { - return array( + return [ '_price', '_regular_price', '_sale_price', @@ -262,7 +264,7 @@ public function ordering_meta() { '_sale_price_dates_from', '_sale_price_dates_to', 'total_sales', - ); + ]; } /** @@ -290,8 +292,8 @@ public function sanitize_input_fields( array $where_args ) { $args['s'] = $where_args['search']; } - $tax_query = array(); - $taxonomy_args = array( + $tax_query = []; + $taxonomy_args = [ 'type' => 'product_type', 'typeIn' => 'product_type', 'typeNotIn' => 'product_type', @@ -307,7 +309,7 @@ public function sanitize_input_fields( array $where_args ) { 'tagId' => 'product_tag', 'tagIdIn' => 'product_tag', 'tagIdNotIn' => 'product_tag', - ); + ]; foreach ( $taxonomy_args as $field => $taxonomy ) { if ( ! empty( $where_args[ $field ] ) ) { @@ -332,12 +334,12 @@ public function sanitize_input_fields( array $where_args ) { case 'tag': case 'tagIn': case 'tagNotIn': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $where_args[ $field ], 'operator' => $operator, - ); + ]; break; case 'categoryId': case 'categoryIdIn': @@ -345,12 +347,12 @@ public function sanitize_input_fields( array $where_args ) { case 'tagId': case 'tagIdIn': case 'tagIdNotIn': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $where_args[ $field ], 'operator' => $operator, - ); + ]; break; }//end switch }//end if @@ -363,48 +365,48 @@ public function sanitize_input_fields( array $where_args ) { // Filter by attribute and term. if ( ! empty( $where_args['attribute'] ) && ! empty( $where_args['attributeTerm'] ) ) { if ( in_array( $where_args['attribute'], \wc_get_attribute_taxonomy_names(), true ) ) { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => $where_args['attribute'], 'field' => 'slug', 'terms' => $where_args['attributeTerm'], - ); + ]; } } if ( empty( $where_args['type'] ) && empty( $where_args['typeIn'] ) && ! empty( $where_args['supportedTypesOnly'] ) && true === $where_args['supportedTypesOnly'] ) { - $supported_types = array_keys( \WP_GraphQL_WooCommerce::get_enabled_product_types() ); + $supported_types = array_keys( WP_GraphQL_WooCommerce::get_enabled_product_types() ); $terms = ! empty( $where_args['typeNotIn'] ) ? array_diff( $supported_types, $where_args['typeNotIn'] ) : $supported_types; - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $terms, - ); + ]; } if ( isset( $where_args['featured'] ) ) { $product_visibility_term_ids = wc_get_product_visibility_term_ids(); if ( $where_args['featured'] ) { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['featured'] ), - ); - $tax_query[] = array( + 'terms' => [ $product_visibility_term_ids['featured'] ], + ]; + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['exclude-from-catalog'] ), + 'terms' => [ $product_visibility_term_ids['exclude-from-catalog'] ], 'operator' => 'NOT IN', - ); + ]; } else { - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', - 'terms' => array( $product_visibility_term_ids['featured'] ), + 'terms' => [ $product_visibility_term_ids['featured'] ], 'operator' => 'NOT IN', - ); + ]; } }//end if @@ -413,36 +415,36 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['visibility'] ) ) { switch ( $where_args['visibility'] ) { case 'search': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-search' ), + 'terms' => [ 'exclude-from-search' ], 'operator' => 'NOT IN', - ); + ]; break; case 'catalog': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog' ), + 'terms' => [ 'exclude-from-catalog' ], 'operator' => 'NOT IN', - ); + ]; break; case 'visible': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], 'operator' => 'NOT IN', - ); + ]; break; case 'hidden': - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'terms' => [ 'exclude-from-catalog', 'exclude-from-search' ], 'operator' => 'AND', - ); + ]; break; }//end switch }//end if @@ -451,12 +453,12 @@ public function sanitize_input_fields( array $where_args ) { if ( ! empty( $where_args['taxonomyFilter'] ) ) { foreach ( $where_args['taxonomyFilter'] as $filter ) { // Holds sub tax query parameters. - $sub_tax_query = array(); + $sub_tax_query = []; // Process parameters. foreach ( $filter as $relation => $filter_args ) { foreach ( $filter_args as $filter_arg ) { - $sub_tax_query[] = array( + $sub_tax_query[] = [ 'taxonomy' => $filter_arg['taxonomy'], 'field' => ! empty( $filter_arg['ids'] ) ? 'term_id' : 'slug', 'terms' => ! empty( $filter_arg['ids'] ) @@ -465,7 +467,7 @@ public function sanitize_input_fields( array $where_args ) { 'operator' => ! empty( $filter_arg['operator'] ) ? $filter_arg['operator'] : 'IN', - ); + ]; } } @@ -483,17 +485,17 @@ public function sanitize_input_fields( array $where_args ) { } if ( ! empty( $tax_query ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query $args['tax_query'] = $tax_query; - // WPCS: slow query ok. } - $meta_query = array(); + $meta_query = []; if ( ! empty( $where_args['sku'] ) ) { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_sku', 'value' => $where_args['sku'], 'compare' => 'LIKE', - ); + ]; } if ( ! empty( $where_args['minPrice'] ) || ! empty( $where_args['maxPrice'] ) ) { @@ -507,34 +509,34 @@ public function sanitize_input_fields( array $where_args ) { $meta_query[] = apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'woocommerce_get_min_max_price_meta_query', - array( + [ 'key' => '_price', - 'value' => array( $current_min_price, $current_max_price ), + 'value' => [ $current_min_price, $current_max_price ], 'compare' => 'BETWEEN', 'type' => 'DECIMAL(10,' . wc_get_price_decimals() . ')', - ), + ], $args ); } if ( isset( $where_args['stockStatus'] ) ) { - $meta_query[] = array( + $meta_query[] = [ 'key' => '_stock_status', 'value' => $where_args['stockStatus'], 'compare' => is_array( $where_args['stockStatus'] ) ? 'IN' : '=', - ); + ]; } if ( ! empty( $meta_query ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query $args['meta_query'] = $meta_query; - // WPCS: slow query ok. } if ( ! empty( $where_args['onSale'] ) && is_bool( $where_args['onSale'] ) ) { $on_sale_key = $where_args['onSale'] ? 'post__in' : 'post__not_in'; $on_sale_ids = \wc_get_product_ids_on_sale(); - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; + $on_sale_ids = empty( $on_sale_ids ) ? [ 0 ] : $on_sale_ids; $args[ $on_sale_key ] = $on_sale_ids; } diff --git a/includes/data/connection/class-refund-connection-resolver.php b/includes/data/connection/class-refund-connection-resolver.php index 4543ffd15..d744e4489 100644 --- a/includes/data/connection/class-refund-connection-resolver.php +++ b/includes/data/connection/class-refund-connection-resolver.php @@ -100,17 +100,17 @@ public function get_query_args() { $first = ! empty( $this->args['first'] ) ? $this->args['first'] : null; // Set the $query_args based on various defaults and primary input $args. - $query_args = array( + $query_args = [ 'post_type' => 'shop_order_refund', 'no_rows_found' => true, 'return' => 'ids', 'limit' => min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1, - ); + ]; /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -148,11 +148,11 @@ public function get_query_args() { case is_a( $this->source, Customer::class ): if ( 'refunds' === $this->info->fieldName ) { $customer_orders = \wc_get_orders( - array( + [ 'customer_id' => $this->source->ID, 'no_rows_found' => true, 'return' => 'ids', - ) + ] ); $query_args['post_parent__in'] = array_map( 'absint', $customer_orders ); } @@ -197,7 +197,7 @@ public function get_query() { * @return array */ public function get_ids() { - return ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : array(); + return ! empty( $this->query->get_orders() ) ? $this->query->get_orders() : []; } /** @@ -206,7 +206,7 @@ public function get_ids() { * @return array */ public function ordering_meta() { - return array(); + return []; } /** @@ -222,11 +222,11 @@ public function ordering_meta() { public function sanitize_input_fields( array $where_args ) { $args = $this->sanitize_common_inputs( $where_args ); - $key_mapping = array( + $key_mapping = [ 'post_parent' => 'parent', 'post_parent__not_in' => 'parent_exclude', 'post__not_in' => 'exclude', - ); + ]; foreach ( $key_mapping as $key => $field ) { if ( isset( $args[ $key ] ) ) { diff --git a/includes/data/connection/class-shipping-method-connection-resolver.php b/includes/data/connection/class-shipping-method-connection-resolver.php index 9675aec6c..35ef6259e 100644 --- a/includes/data/connection/class-shipping-method-connection-resolver.php +++ b/includes/data/connection/class-shipping-method-connection-resolver.php @@ -45,7 +45,7 @@ public function should_execute() { */ public function get_query_args() { // TODO: Implement get_query_args() method. - return array(); + return []; } /** @@ -75,7 +75,7 @@ function( $item ) { * @return array|mixed */ public function get_ids() { - return ! empty( $this->query ) ? $this->query : array(); + return ! empty( $this->query ) ? $this->query : []; } /** diff --git a/includes/data/connection/class-tax-rate-connection-resolver.php b/includes/data/connection/class-tax-rate-connection-resolver.php index ccc72d1d8..3b53401c4 100644 --- a/includes/data/connection/class-tax-rate-connection-resolver.php +++ b/includes/data/connection/class-tax-rate-connection-resolver.php @@ -44,7 +44,7 @@ public function should_execute() { * @return array */ public function get_query_args() { - $query_args = array(); + $query_args = []; // Prepare for later use. $last = ! empty( $this->args['last'] ) ? $this->args['last'] : null; @@ -53,7 +53,7 @@ public function get_query_args() { /** * Collect the input_fields and sanitize them to prepare them for sending to the WP_Query */ - $input_fields = array(); + $input_fields = []; if ( ! empty( $this->args['where'] ) ) { $input_fields = $this->sanitize_input_fields( $this->args['where'] ); } @@ -150,7 +150,7 @@ function( $rate ) { * @return array */ public function get_ids() { - return ! empty( $this->query ) ? $this->query : array(); + return ! empty( $this->query ) ? $this->query : []; } /** @@ -164,13 +164,13 @@ public function get_ids() { * @return array */ public function sanitize_input_fields( array $where_args ) { - $args = array(); + $args = []; if ( ! empty( $where_args['orderby'] ) ) { if ( ! empty( $where_args['orderby']['field'] ) ) { - $orderby_possibles = array( + $orderby_possibles = [ 'id' => 'tax_rate_id', 'order' => 'tax_rate_order', - ); + ]; $args['orderby'] = $orderby_possibles[ $where_args['orderby']['field'] ]; } diff --git a/includes/data/connection/class-variation-attribute-connection-resolver.php b/includes/data/connection/class-variation-attribute-connection-resolver.php index 9a42b2d27..6ee0e3086 100644 --- a/includes/data/connection/class-variation-attribute-connection-resolver.php +++ b/includes/data/connection/class-variation-attribute-connection-resolver.php @@ -28,29 +28,29 @@ class Variation_Attribute_Connection_Resolver { * * @return array */ - public static function to_data_array( $attrs = array(), $parent_id = 0 ) { - $attributes = array(); - if ( array( '0' ) !== $attrs ) { + public static function to_data_array( $attrs = [], $parent_id = 0 ) { + $attributes = []; + if ( [ '0' ] !== $attrs ) { foreach ( $attrs as $name => $value ) { $term = \get_term_by( 'slug', $value, $name ); if ( empty( $term ) ) { - $attributes[] = array( + $attributes[] = [ // ID create for caching only, not object retrieval. // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 'id' => base64_encode( $parent_id . '||' . $name . '||' . $value ), 'attributeId' => 0, 'name' => $name, 'value' => $value, - ); + ]; } else { - $attributes[] = array( + $attributes[] = [ // ID create for caching only, not object retrieval. // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 'id' => base64_encode( $parent_id . '||' . $name . '||' . $value ), 'attributeId' => $term->term_id, 'name' => $term->taxonomy, 'value' => $term->name, - ); + ]; } }//end foreach }//end if @@ -74,7 +74,7 @@ public function resolve( $source, array $args, AppContext $context, ResolveInfo } $connection = Relay::connectionFromArray( $attributes, $args ); - $nodes = array(); + $nodes = []; if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) { foreach ( $connection['edges'] as $edge ) { $nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null; diff --git a/includes/data/connection/trait-wc-cpt-loader-common.php b/includes/data/connection/trait-wc-cpt-loader-common.php index b83afc13a..20e7b75e0 100644 --- a/includes/data/connection/trait-wc-cpt-loader-common.php +++ b/includes/data/connection/trait-wc-cpt-loader-common.php @@ -29,7 +29,7 @@ public function is_valid_post_offset( $offset ) { if ( ! empty( wp_cache_get( $offset, 'posts' ) ) ) { return true; } - + // phpcs:ignore WordPress.DB.DirectDatabaseQuery return $wpdb->get_var( $wpdb->prepare( "SELECT EXISTS (SELECT 1 FROM $wpdb->posts WHERE ID = %d)", $offset ) ); } @@ -41,7 +41,7 @@ public function is_valid_post_offset( $offset ) { * @return array */ public function sanitize_common_inputs( array $input ) { - $args = array(); + $args = []; if ( ! empty( $input['include'] ) ) { $args['post__in'] = $input['include']; } @@ -56,7 +56,7 @@ public function sanitize_common_inputs( array $input ) { if ( ! empty( $input['parentIn'] ) ) { if ( ! isset( $args['post_parent__in'] ) ) { - $args['post_parent__in'] = array(); + $args['post_parent__in'] = []; } $args['post_parent__in'] = array_merge( $args['post_parent__in'], $input['parentIn'] ); } @@ -73,14 +73,14 @@ public function sanitize_common_inputs( array $input ) { * Map the orderby inputArgs to the WP_Query */ if ( ! empty( $input['orderby'] ) && is_array( $input['orderby'] ) ) { - $args['orderby'] = array(); + $args['orderby'] = []; foreach ( $input['orderby'] as $orderby_input ) { /** * These orderby options should not include the order parameter. */ if ( in_array( $orderby_input['field'], - array( 'post__in', 'post_name__in', 'post_parent__in' ), + [ 'post__in', 'post_name__in', 'post_parent__in' ], true ) ) { $args['orderby'] = esc_sql( $orderby_input['field'] ); @@ -88,7 +88,8 @@ public function sanitize_common_inputs( array $input ) { // Handle meta fields. } elseif ( in_array( $orderby_input['field'], $this->ordering_meta(), true ) ) { $args['orderby']['meta_value_num'] = $orderby_input['order']; - $args['meta_key'] = esc_sql( $orderby_input['field'] ); + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + $args['meta_key'] = esc_sql( $orderby_input['field'] ); // WPCS: slow query ok. // Handle post object fields. diff --git a/includes/data/loader/class-wc-cpt-loader.php b/includes/data/loader/class-wc-cpt-loader.php index 276753f16..8f50bf7a9 100644 --- a/includes/data/loader/class-wc-cpt-loader.php +++ b/includes/data/loader/class-wc-cpt-loader.php @@ -13,6 +13,7 @@ use GraphQL\Deferred; use GraphQL\Error\UserError; use WPGraphQL\Data\Loader\AbstractDataLoader; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; use WPGraphQL\WooCommerce\Data\Factory; use WPGraphQL\WooCommerce\Model\Coupon; use WPGraphQL\WooCommerce\Model\Product; @@ -83,7 +84,7 @@ public function loadKeys( array $keys ) { return $keys; } - $wc_post_types = \WP_GraphQL_WooCommerce::get_post_types(); + $wc_post_types = WP_GraphQL_WooCommerce::get_post_types(); /** * Prepare the args for the query. We're provided a specific * set of IDs, so we want to query as efficiently as possible with @@ -92,16 +93,17 @@ public function loadKeys( array $keys ) { * to the count of the keys provided. The query must also return results * in the same order the keys were provided in. */ - $args = array( + $args = [ 'post_type' => $wc_post_types, 'post_status' => 'any', + //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page 'posts_per_page' => count( $keys ), 'post__in' => $keys, 'orderby' => 'post__in', 'no_found_rows' => true, 'split_the_query' => false, 'ignore_sticky_posts' => true, - ); + ]; /** * Ensure that WP_Query doesn't first ask for IDs since we already have them. @@ -119,7 +121,7 @@ function ( $split, \WP_Query $query ) { ); new \WP_Query( $args ); - $loaded_posts = array(); + $loaded_posts = []; /** * Loop over the posts and return an array of all_posts, @@ -156,13 +158,13 @@ function ( $split, \WP_Query $query ) { case 'shop_order': $customer_id = get_post_meta( $key, '_customer_user', true ); if ( ! empty( $customer_id ) ) { - $this->context->getLoader( 'wc_customer' )->buffer( array( $customer_id ) ); + $this->context->getLoader( 'wc_customer' )->buffer( [ $customer_id ] ); } break; case 'product_variation': case 'shop_refund': $parent_id = get_post_field( 'post_parent', $key ); - $this->buffer( array( $parent_id ) ); + $this->buffer( [ $parent_id ] ); break; } @@ -204,7 +206,7 @@ function() use ( $post_type, $key ) { ); }//end foreach - return ! empty( $loaded_posts ) ? $loaded_posts : array(); + return ! empty( $loaded_posts ) ? $loaded_posts : []; } /** diff --git a/includes/data/loader/class-wc-customer-loader.php b/includes/data/loader/class-wc-customer-loader.php index 21891a6d6..014425521 100644 --- a/includes/data/loader/class-wc-customer-loader.php +++ b/includes/data/loader/class-wc-customer-loader.php @@ -28,7 +28,7 @@ public function loadKeys( array $keys ) { if ( empty( $keys ) ) { return $keys; } - $all_customers = array(); + $all_customers = []; /** * Prepare the args for the query. We're provided a specific @@ -38,13 +38,13 @@ public function loadKeys( array $keys ) { * to the count of the keys provided. The query must also return results * in the same order the keys were provided in. */ - $args = array( + $args = [ 'include' => $keys, 'number' => count( $keys ), 'orderby' => 'include', 'count_total' => false, 'fields' => 'ids', - ); + ]; /** * Query for the users and get the results @@ -56,7 +56,7 @@ public function loadKeys( array $keys ) { * If no users are returned, return an empty array */ if ( empty( $customers ) || ! is_array( $customers ) ) { - return array(); + return []; } foreach ( $keys as $key ) { diff --git a/includes/data/loader/class-wc-db-loader.php b/includes/data/loader/class-wc-db-loader.php index 1117e7ecd..c26d1d869 100644 --- a/includes/data/loader/class-wc-db-loader.php +++ b/includes/data/loader/class-wc-db-loader.php @@ -59,19 +59,19 @@ public function loadKeys( array $keys ) { $loader = null; switch ( $this->loader_type ) { case 'CART_ITEM': - $loader = array( $this, 'load_cart_item_from_key' ); + $loader = [ $this, 'load_cart_item_from_key' ]; break; case 'DOWNLOADABLE_ITEM': - $loader = array( $this, 'load_downloadable_item_from_id' ); + $loader = [ $this, 'load_downloadable_item_from_id' ]; break; case 'TAX_RATE': - $loader = array( $this, 'load_tax_rate_from_id' ); + $loader = [ $this, 'load_tax_rate_from_id' ]; break; case 'ORDER_ITEM': - $loader = array( $this, 'load_order_item_from_id' ); + $loader = [ $this, 'load_order_item_from_id' ]; break; case 'SHIPPING_METHOD': - $loader = array( $this, 'load_shipping_method_from_id' ); + $loader = [ $this, 'load_shipping_method_from_id' ]; break; default: /** @@ -90,7 +90,7 @@ public function loadKeys( array $keys ) { } }//end switch - $loaded_items = array(); + $loaded_items = []; /** * Loop over the keys and return an array of items. @@ -99,7 +99,7 @@ public function loadKeys( array $keys ) { $loaded_items[ $key ] = call_user_func( $loader, $key ); } - return ! empty( $loaded_items ) ? $loaded_items : array(); + return ! empty( $loaded_items ) ? $loaded_items : []; } /** @@ -139,6 +139,7 @@ public function load_tax_rate_from_id( $id ) { $rate = \WC_Tax::_get_tax_rate( $id, OBJECT ); if ( ! \is_wp_error( $rate ) && ! empty( $rate ) ) { // Get locales from a tax rate. + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $locales = $wpdb->get_results( $wpdb->prepare( "SELECT location_code, location_type @@ -150,7 +151,7 @@ public function load_tax_rate_from_id( $id ) { foreach ( $locales as $locale ) { if ( empty( $rate->{'tax_rate_' . $locale->location_type} ) ) { - $rate->{'tax_rate_' . $locale->location_type} = array(); + $rate->{'tax_rate_' . $locale->location_type} = []; } $rate->{'tax_rate_' . $locale->location_type}[] = $locale->location_code; } diff --git a/includes/data/mutation/class-cart-mutation.php b/includes/data/mutation/class-cart-mutation.php index 91c62a086..ad0c6238a 100644 --- a/includes/data/mutation/class-cart-mutation.php +++ b/includes/data/mutation/class-cart-mutation.php @@ -22,7 +22,7 @@ class Cart_Mutation { * @return array */ public static function get_cart_field( $fallback = false ) { - return array( + return [ 'type' => 'Cart', 'resolve' => function ( $payload ) use ( $fallback ) { $cart = ! empty( $payload['cart'] ) ? $payload['cart'] : null; @@ -32,7 +32,7 @@ public static function get_cart_field( $fallback = false ) { } return $cart; }, - ); + ]; } /** @@ -55,13 +55,13 @@ public static function prepare_cart_item( $input, $context, $info ) { throw new UserError( __( 'No product found matching the ID provided', 'wp-graphql-woocommerce' ) ); } - $cart_item_args = array( $input['productId'] ); + $cart_item_args = [ $input['productId'] ]; $cart_item_args[] = ! empty( $input['quantity'] ) ? $input['quantity'] : 1; $cart_item_args[] = ! empty( $input['variationId'] ) ? $input['variationId'] : 0; - $cart_item_args[] = ! empty( $input['variation'] ) ? self::prepare_attributes( $input['productId'], $input['variation'] ) : array(); + $cart_item_args[] = ! empty( $input['variation'] ) ? self::prepare_attributes( $input['productId'], $input['variation'] ) : []; $cart_item_args[] = ! empty( $input['extraData'] ) ? json_decode( $input['extraData'], true ) - : array(); + : []; return apply_filters( 'graphql_woocommerce_new_cart_item_data', $cart_item_args, $input, $context, $info ); } @@ -76,11 +76,11 @@ public static function prepare_cart_item( $input, $context, $info ) { * * @throws UserError Invalid cart attribute provided. */ - private static function prepare_attributes( $product_id, array $variation_data = array() ) { + private static function prepare_attributes( $product_id, array $variation_data = [] ) { $product = wc_get_product( $product_id ); $attribute_names = array_keys( $product->get_attributes() ); - $attributes = array(); + $attributes = []; foreach ( $variation_data as $attribute ) { $attribute_name = $attribute['attributeName']; if ( in_array( "pa_{$attribute_name}", $attribute_names, true ) ) { @@ -122,7 +122,7 @@ public static function retrieve_cart_items( $input, $context, $info, $mutation = } if ( ! empty( $input['keys'] ) && ! isset( $items ) ) { - $items = array(); + $items = []; foreach ( $input['keys'] as $key ) { $item = \WC()->cart->get_cart_item( $key ); if ( empty( $item ) ) { @@ -146,12 +146,12 @@ public static function retrieve_cart_items( $input, $context, $info, $mutation = * @return array */ public static function prepare_cart_fee( $input, $context, $info ) { - $cart_item_args = array( + $cart_item_args = [ $input['name'], $input['amount'], ! empty( $input['taxable'] ) ? $input['taxable'] : false, ! empty( $input['taxClass'] ) ? $input['taxClass'] : '', - ); + ]; return apply_filters( 'graphql_woocommerce_new_cart_fee_data', $cart_item_args, $input, $context, $info ); } @@ -203,7 +203,7 @@ public static function validate_shipping_method( $shipping_method, $index, &$rea // Get available shipping packages. $available_packages = \WC()->cart->needs_shipping() ? \WC()->shipping()->calculate_shipping( \WC()->cart->get_shipping_packages() ) - : array(); + : []; if ( ! isset( $available_packages[ $index ] ) ) { $reason = sprintf( @@ -222,7 +222,7 @@ public static function validate_shipping_method( $shipping_method, $index, &$rea return true; } - $product_names = array(); + $product_names = []; foreach ( $package['contents'] as $item_id => $values ) { $product_names[ $item_id ] = \html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); } diff --git a/includes/data/mutation/class-checkout-mutation.php b/includes/data/mutation/class-checkout-mutation.php index e2f5dfd89..69d916f6c 100644 --- a/includes/data/mutation/class-checkout-mutation.php +++ b/includes/data/mutation/class-checkout-mutation.php @@ -72,14 +72,14 @@ protected static function maybe_skip_fieldset( $fieldset_key, $data ) { * @return array */ public static function prepare_checkout_args( $input, $context, $info ) { - $data = array( + $data = [ 'terms' => (int) isset( $input['terms'] ), 'createaccount' => (int) ! empty( $input['account'] ), 'payment_method' => isset( $input['paymentMethod'] ) ? $input['paymentMethod'] : '', 'shipping_method' => isset( $input['shippingMethod'] ) ? $input['shippingMethod'] : '', 'ship_to_different_address' => ! empty( $input['shipToDifferentAddress'] ) && ! wc_ship_to_billing_address_only(), - ); - $skipped = array(); + ]; + $skipped = []; foreach ( self::get_checkout_fields() as $fieldset_key => $fieldset ) { if ( self::maybe_skip_fieldset( $fieldset_key, $data ) ) { @@ -122,8 +122,8 @@ public static function prepare_checkout_args( $input, $context, $info ) { * @return bool|array */ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) { - $fields = array( - 'billing' => array( + $fields = [ + 'billing' => [ 'first_name' => 'firstName', 'last_name' => 'lastName', 'company' => 'company', @@ -135,8 +135,8 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) 'country' => 'country', 'phone' => 'phone', 'email' => 'email', - ), - 'shipping' => array( + ], + 'shipping' => [ 'first_name' => 'firstName', 'last_name' => 'lastName', 'company' => 'company', @@ -146,15 +146,15 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) 'postcode' => 'postcode', 'state' => 'state', 'country' => 'country', - ), - 'account' => array( + ], + 'account' => [ 'username' => 'username', 'password' => 'password', - ), - 'order' => array( + ], + 'order' => [ 'comments' => 'customerNote', - ), - ); + ], + ]; if ( $prefixed ) { foreach ( $fields as $prefix => $values ) { @@ -178,7 +178,7 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false ) */ protected static function update_session( $data ) { // Update both shipping and billing to the passed billing address first if set. - $address_fields = array( + $address_fields = [ 'first_name', 'last_name', 'company', @@ -190,7 +190,7 @@ protected static function update_session( $data ) { 'postcode', 'state', 'country', - ); + ]; foreach ( $address_fields as $field ) { self::set_customer_address_fields( $field, $data ); @@ -225,7 +225,7 @@ protected static function clear_customer_address( $type = 'billing' ) { return false; } - $address = array( + $address = [ 'first_name' => '', 'last_name' => '', 'company' => '', @@ -235,15 +235,15 @@ protected static function clear_customer_address( $type = 'billing' ) { 'state' => '', 'postcode' => '', 'country' => '', - ); + ]; if ( 'billing' === $type ) { $address = array_merge( $address, - array( + [ 'email' => '', 'phone' => '', - ) + ] ); } @@ -273,10 +273,10 @@ protected static function process_customer( $data ) { $data['billing_email'], $username, $password, - array( + [ 'first_name' => ! empty( $data['billing_first_name'] ) ? $data['billing_first_name'] : '', 'last_name' => ! empty( $data['billing_last_name'] ) ? $data['billing_last_name'] : '', - ) + ] ); if ( is_wp_error( $customer_id ) ) { @@ -317,7 +317,7 @@ protected static function process_customer( $data ) { foreach ( $data as $key => $value ) { // Use setters where available. - if ( is_callable( array( $customer, "set_{$key}" ) ) ) { + if ( is_callable( [ $customer, "set_{$key}" ] ) ) { $customer->{"set_{$key}"}( $value ); // Store custom fields prefixed with wither shipping_ or billing_. @@ -347,20 +347,20 @@ protected static function set_customer_address_fields( $field, $data ) { $billing_value = null; $shipping_value = null; - if ( isset( $data[ "billing_{$field}" ] ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) { + if ( isset( $data[ "billing_{$field}" ] ) && is_callable( [ WC()->customer, "set_billing_{$field}" ] ) ) { $billing_value = $data[ "billing_{$field}" ]; $shipping_value = $data[ "billing_{$field}" ]; } - if ( isset( $data[ "shipping_{$field}" ] ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) { + if ( isset( $data[ "shipping_{$field}" ] ) && is_callable( [ WC()->customer, "set_shipping_{$field}" ] ) ) { $shipping_value = $data[ "shipping_{$field}" ]; } - if ( ! is_null( $billing_value ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) { + if ( ! is_null( $billing_value ) && is_callable( [ WC()->customer, "set_billing_{$field}" ] ) ) { WC()->customer->{"set_billing_{$field}"}( $billing_value ); } - if ( ! is_null( $shipping_value ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) { + if ( ! is_null( $shipping_value ) && is_callable( [ WC()->customer, "set_shipping_{$field}" ] ) ) { WC()->customer->{"set_shipping_{$field}"}( $shipping_value ); } } @@ -521,7 +521,7 @@ protected static function process_order_payment( $order_id, $payment_method ) { $process_payment_args = apply_filters( "graphql_{$payment_method}_process_payment_args", - array( $order_id ), + [ $order_id ], $payment_method ); @@ -543,11 +543,11 @@ protected static function process_order_without_payment( $order_id, $transaction $order->payment_complete( $transaction_id ); wc_empty_cart(); - return array( + return [ 'result' => 'success', // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'redirect' => apply_filters( 'woocommerce_checkout_no_payment_needed_redirect', $order->get_checkout_order_received_url(), $order ), - ); + ]; } /** @@ -638,7 +638,7 @@ public static function process_checkout( $data, $input, $context, $info, &$resul if ( $valid ) { $results = self::process_order_without_payment( $order_id, $transaction_id ); } else { - $results = array( + $results = [ 'result' => 'failed', 'redirect' => apply_filters( 'graphql_woocommerce_checkout_payment_failed_redirect', @@ -647,7 +647,7 @@ public static function process_checkout( $data, $input, $context, $info, &$resul $order_id, $transaction_id ), - ); + ]; } }//end if @@ -686,7 +686,7 @@ public static function get_value( $input ) { $customer_object = WC()->customer; } - if ( is_callable( array( $customer_object, "get_$input" ) ) ) { + if ( is_callable( [ $customer_object, "get_$input" ] ) ) { $value = $customer_object->{"get_$input"}(); } elseif ( $customer_object->meta_exists( $input ) ) { $value = $customer_object->get_meta( $input, true ); diff --git a/includes/data/mutation/class-coupon-mutation.php b/includes/data/mutation/class-coupon-mutation.php index 9207c1c52..80bd3953e 100644 --- a/includes/data/mutation/class-coupon-mutation.php +++ b/includes/data/mutation/class-coupon-mutation.php @@ -24,7 +24,7 @@ class Coupon_Mutation { * @return array */ public static function prepare_args( array $input ) { - $data_keys = array( + $data_keys = [ 'code' => 'code', 'amount' => 'amount', 'discountType' => 'discount_type', @@ -45,9 +45,9 @@ public static function prepare_args( array $input ) { 'maximumAmount' => 'maximum_amount', 'emailRestrictions' => 'email_restrictions', 'metaData' => 'meta_data', - ); + ]; - $args = array(); + $args = []; foreach ( $input as $input_field => $value ) { if ( empty( $data_keys[ $input_field ] ) ) { continue; diff --git a/includes/data/mutation/class-customer-mutation.php b/includes/data/mutation/class-customer-mutation.php index fddbe2dae..312267e11 100644 --- a/includes/data/mutation/class-customer-mutation.php +++ b/includes/data/mutation/class-customer-mutation.php @@ -27,14 +27,14 @@ class Customer_Mutation { * @return array */ public static function prepare_customer_props( $input, $mutation ) { - $customer_args = array(); + $customer_args = []; if ( ! empty( $input['billing'] ) ) { - $customer_args['billing'] = self::address_input_mapping( 'billing', $input['billing'] ); + $customer_args['billing'] = self::address_input_mapping( $input['billing'], 'billing' ); } if ( ! empty( $input['shipping'] ) ) { - $customer_args['shipping'] = self::address_input_mapping( 'shipping', $input['shipping'] ); + $customer_args['shipping'] = self::address_input_mapping( $input['shipping'], 'shipping' ); } /** @@ -52,26 +52,26 @@ public static function prepare_customer_props( $input, $mutation ) { /** * Formats CustomerAddressInput into a address object to be used by WC_Customer object * - * @param string $type Address type. * @param array $input Customer address input. + * @param string $type Address type. * * @return array; */ - public static function address_input_mapping( $type = 'billing', $input ) { + public static function address_input_mapping( $input, $type = 'billing' ) { // Map GQL input to address props array. - $key_mapping = array( + $key_mapping = [ 'firstName' => 'first_name', 'lastName' => 'last_name', 'address1' => 'address_1', 'address2' => 'address_2', - ); + ]; - $skip = apply_filters( 'graphql_woocommerce_customer_address_input_mapping_skipped', array( 'overwrite' ) ); + $skip = apply_filters( 'graphql_woocommerce_customer_address_input_mapping_skipped', [ 'overwrite' ] ); $type = 'empty_' . $type; $address = ! empty( $input['overwrite'] ) && true === $input['overwrite'] ? self::{$type}() - : array(); + : []; foreach ( $input as $input_field => $value ) { if ( in_array( $input_field, array_keys( $key_mapping ), true ) ) { $address[ $key_mapping[ $input_field ] ] = $value; @@ -91,7 +91,7 @@ public static function address_input_mapping( $type = 'billing', $input ) { * @return array */ public static function empty_shipping() { - return array( + return [ 'first_name' => '', 'last_name' => '', 'company' => '', @@ -101,7 +101,7 @@ public static function empty_shipping() { 'state' => '', 'postcode' => '', 'country' => '', - ); + ]; } /** @@ -112,10 +112,10 @@ public static function empty_shipping() { public static function empty_billing() { return array_merge( self::empty_shipping(), - array( + [ 'email' => '', 'phone' => '', - ) + ] ); } diff --git a/includes/data/mutation/class-order-mutation.php b/includes/data/mutation/class-order-mutation.php index db3c30190..c6d3c6056 100644 --- a/includes/data/mutation/class-order-mutation.php +++ b/includes/data/mutation/class-order-mutation.php @@ -17,15 +17,15 @@ class Order_Mutation { /** * Filterable authentication function. * - * @param string $mutation Mutation being executed. - * @param integer|null $order_id Order ID. * @param array $input Input data describing order. * @param AppContext $context AppContext instance. * @param ResolveInfo $info ResolveInfo instance. + * @param string $mutation Mutation being executed. + * @param integer|null $order_id Order ID. * * @return boolean */ - public static function authorized( $mutation = 'create', $order_id = null, $input, $context, $info ) { + public static function authorized( $input, $context, $info, $mutation = 'create', $order_id = null ) { $post_type_object = get_post_type_object( 'shop_order' ); return apply_filters( @@ -54,16 +54,16 @@ public static function authorized( $mutation = 'create', $order_id = null, $inpu * @throws UserError Error creating order. */ public static function create_order( $input, $context, $info ) { - $order_keys = array( + $order_keys = [ 'status' => 'status', 'customerId' => 'customer_id', 'customerNote' => 'customer_note', 'parent' => 'parent', 'createdVia' => 'created_via', 'orderId' => 'order_id', - ); + ]; - $args = array(); + $args = []; foreach ( $input as $key => $value ) { if ( array_key_exists( $key, $order_keys ) ) { $args[ $order_keys[ $key ] ] = $value; @@ -107,13 +107,13 @@ public static function create_order( $input, $context, $info ) { * @param ResolveInfo $info ResolveInfo instance. */ public static function add_items( $input, $order_id, $context, $info ) { - $item_group_keys = array( + $item_group_keys = [ 'lineItems' => 'line_item', 'shippingLines' => 'shipping', 'feeLines' => 'fee', - ); + ]; - $item_groups = array(); + $item_groups = []; foreach ( $input as $key => $items ) { if ( array_key_exists( $key, $item_group_keys ) ) { $type = $item_group_keys[ $key ]; @@ -132,7 +132,7 @@ public static function add_items( $input, $order_id, $context, $info ) { // Create Order item. $item_id = ( ! empty( $item_data['id'] ) && \WC_Order_Factory::get_order_item( $item_data['id'] ) ) ? $item_data['id'] - : \wc_add_order_item( $order_id, array( 'order_item_type' => $type ) ); + : \wc_add_order_item( $order_id, [ 'order_item_type' => $type ] ); // Continue if order item creation failed. if ( ! $item_id ) { @@ -168,7 +168,7 @@ public static function add_items( $input, $order_id, $context, $info ) { */ protected static function map_input_to_item( $item_id, $input, $item_keys, $context, $info ) { $order_item = \WC_Order_Factory::get_order_item( $item_id ); - $args = array(); + $args = []; $meta_data = null; foreach ( $input as $key => $value ) { if ( array_key_exists( $key, $item_keys ) ) { @@ -185,14 +185,14 @@ protected static function map_input_to_item( $item_id, $input, $item_keys, $cont $product = ( ! empty( $order_item['product_id'] ) ) ? wc_get_product( $order_item['product_id'] ) : wc_get_product( self::get_product_id( $args ) ); - $total = wc_get_price_excluding_tax( $product, array( 'qty' => $args['quantity'] ) ); + $total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ] ); $args['subtotal'] = ! empty( $args['subtotal'] ) ? $args['subtotal'] : $total; $args['total'] = ! empty( $args['total'] ) ? $args['total'] : $total; } // Set item props. foreach ( $args as $key => $value ) { - if ( is_callable( array( $order_item, "set_{$key}" ) ) ) { + if ( is_callable( [ $order_item, "set_{$key}" ] ) ) { $order_item->{"set_{$key}"}( $value ); } } @@ -216,26 +216,26 @@ protected static function map_input_to_item( $item_id, $input, $item_keys, $cont protected static function get_order_item_keys( $type ) { switch ( $type ) { case 'line_item': - return array( + return [ 'productId' => 'product_id', 'variationId' => 'variation_id', 'taxClass' => 'tax_class', - ); + ]; case 'shipping': - return array( + return [ 'name' => 'order_item_name', 'methodTitle' => 'method_title', 'methodId' => 'method_id', 'instanceId' => 'instance_id', - ); + ]; case 'fee': - return array( + return [ 'name' => 'name', 'taxClass' => 'tax_class', 'taxStatus' => 'tax_status', - ); + ]; }//end switch } @@ -316,7 +316,7 @@ public static function add_order_meta( $order_id, $input, $context, $info ) { break; default: $prop = \wc_graphql_camel_case_to_underscore( $key ); - if ( is_callable( array( $order, "set_{$prop}" ) ) ) { + if ( is_callable( [ $order, "set_{$prop}" ] ) ) { $order->{"set_{$prop}"}( $value ); } break; @@ -346,9 +346,9 @@ public static function add_order_meta( $order_id, $input, $context, $info ) { protected static function update_address( $address, $order_id, $type = 'billing' ) { $order = \WC_Order_Factory::get_order( $order_id ); - $formatted_address = Customer_Mutation::address_input_mapping( $type, $address ); + $formatted_address = Customer_Mutation::address_input_mapping( $address, $type ); foreach ( $formatted_address as $key => $value ) { - if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { + if ( is_callable( [ $order, "set_{$type}_{$key}" ] ) ) { $order->{"set_{$type}_{$key}"}( $value ); } } @@ -413,7 +413,7 @@ public static function validate_customer( $input ) { * @throws UserError Failed to delete order. */ public static function purge( $order, $force_delete = true ) { - if ( is_callable( array( $order, 'delete' ) ) ) { + if ( is_callable( [ $order, 'delete' ] ) ) { return $order->delete( $force_delete ); } diff --git a/includes/functions.php b/includes/functions.php index 69528f461..005bec260 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -38,12 +38,12 @@ function( $type_name ) { return 'Product' !== $type_name; } ), - array( + [ 'SimpleProduct', 'VariableProduct', 'GroupProduct', 'ExternalProduct', - ) + ] ); } diff --git a/includes/model/class-coupon.php b/includes/model/class-coupon.php index e6a11d821..7c0c4d6f1 100644 --- a/includes/model/class-coupon.php +++ b/includes/model/class-coupon.php @@ -36,7 +36,7 @@ protected function init() { if ( empty( $this->fields ) ) { parent::init(); - $fields = array( + $fields = [ 'id' => function() { return ! empty( $this->wc_data->get_id() ) ? Relay::toGlobalId( 'shop_coupon', $this->wc_data->get_id() ) : null; }, @@ -98,21 +98,21 @@ protected function init() { * Note: underscore naming style is used as a quick identifier */ 'product_ids' => function() { - return ! empty( $this->wc_data->get_product_ids() ) ? $this->wc_data->get_product_ids() : array( '0' ); + return ! empty( $this->wc_data->get_product_ids() ) ? $this->wc_data->get_product_ids() : [ '0' ]; }, 'excluded_product_ids' => function() { - return ! empty( $this->wc_data->get_excluded_product_ids() ) ? $this->wc_data->get_excluded_product_ids() : array( '0' ); + return ! empty( $this->wc_data->get_excluded_product_ids() ) ? $this->wc_data->get_excluded_product_ids() : [ '0' ]; }, 'product_category_ids' => function() { - return ! empty( $this->wc_data->get_product_categories() ) ? $this->wc_data->get_product_categories() : array( '0' ); + return ! empty( $this->wc_data->get_product_categories() ) ? $this->wc_data->get_product_categories() : [ '0' ]; }, 'excluded_product_category_ids' => function() { - return ! empty( $this->wc_data->get_excluded_product_categories() ) ? $this->wc_data->get_excluded_product_categories() : array( '0' ); + return ! empty( $this->wc_data->get_excluded_product_categories() ) ? $this->wc_data->get_excluded_product_categories() : [ '0' ]; }, 'used_by_ids' => function() { - return ! empty( $this->wc_data->get_used_by() ) ? $this->wc_data->get_used_by() : array( '0' ); + return ! empty( $this->wc_data->get_used_by() ) ? $this->wc_data->get_used_by() : [ '0' ]; }, - ); + ]; $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-customer.php b/includes/model/class-customer.php index 538cecae4..d7908bb3b 100644 --- a/includes/model/class-customer.php +++ b/includes/model/class-customer.php @@ -26,13 +26,13 @@ class Customer extends Model { */ public function __construct( $id = 'session' ) { $this->data = 'session' === $id ? \WC()->customer : new WC_Customer( $id ); - $allowed_restricted_fields = array( + $allowed_restricted_fields = [ 'isRestricted', 'isPrivate', 'isPublic', 'id', 'customerId', - ); + ]; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'customer_restricted_cap', 'session' === $id ? '' : 'list_users' ); @@ -56,7 +56,7 @@ public function __call( $method, $args ) { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = array( + $this->fields = [ 'ID' => function() { return ( ! empty( $this->data->get_id() ) ) ? $this->data->get_id() : \WC()->session->_customer_id; }, @@ -125,7 +125,7 @@ protected function init() { 'last_order_id' => function() { return ( ! empty( $this->data->get_last_order() ) ) ? $this->data->get_last_order()->get_id() : null; }, - ); + ]; }//end if parent::prepare_fields(); diff --git a/includes/model/class-order-item.php b/includes/model/class-order-item.php index dcae34cfd..744cf4564 100644 --- a/includes/model/class-order-item.php +++ b/includes/model/class-order-item.php @@ -42,13 +42,13 @@ public function __construct( $item ) { $order_id = $item->get_order_id(); $author_id = get_post_field( 'post_author', $order_id ); $this->order = ! empty( $item->cached_order ) ? $item->cached_order : new Order( $order_id ); - $allowed_restricted_fields = array( + $allowed_restricted_fields = [ 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ); + ]; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'order_item_restricted_cap', '' ); @@ -72,7 +72,7 @@ public function __call( $method, $args ) { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = array( + $this->fields = [ 'ID' => function() { return $this->data->get_id(); }, @@ -85,13 +85,13 @@ protected function init() { 'type' => function() { return ! empty( $this->data->get_type() ) ? $this->data->get_type() : null; }, - ); + ]; switch ( $this->item_type ) { case 'coupon': $this->fields = array_merge( $this->fields, - array( + [ 'code' => function() { return ! empty( $this->data->get_code() ) ? $this->data->get_code() : null; }, @@ -101,21 +101,21 @@ protected function init() { 'discountTax' => function() { return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : null; }, - 'coupon_id' => array( + 'coupon_id' => [ 'callback' => function() { $coupon_id = \wc_get_coupon_id_by_code( $this->data->get_code() ); return ! empty( $coupon_id ) ? $coupon_id : null; }, 'capability' => 'edit_shop_orders', - ), - ) + ], + ] ); break; case 'fee': $this->fields = array_merge( $this->fields, - array( + [ 'amount' => function() { return ! empty( $this->data->get_amount() ) ? $this->data->get_amount() : null; }, @@ -144,14 +144,14 @@ protected function init() { ? \wc_graphql_map_tax_statements( $this->data->get_taxes() ) : null; }, - ) + ] ); break; case 'shipping': $this->fields = array_merge( $this->fields, - array( + [ 'name' => function() { return ! empty( $this->data->get_name() ) ? $this->data->get_name() : null; }, @@ -175,14 +175,14 @@ protected function init() { 'method_id' => function() { return ! empty( $this->data->get_method_id() ) ? $this->data->get_method_id() : null; }, - ) + ] ); break; case 'tax': $this->fields = array_merge( $this->fields, - array( + [ 'rateCode' => function() { return ! empty( $this->data->get_rate_code() ) ? $this->data->get_rate_code() : null; }, @@ -201,13 +201,13 @@ protected function init() { 'rate_id' => function() { return ! empty( $this->data->get_rate_id() ) ? $this->data->get_rate_id() : null; }, - ) + ] ); break; default: $this->fields = array_merge( $this->fields, - array( + [ 'productId' => function() { return ! empty( $this->data->get_product_id() ) ? $this->data->get_product_id() : null; }, @@ -248,7 +248,7 @@ protected function init() { } return null; }, - ) + ] ); break; }//end switch diff --git a/includes/model/class-order.php b/includes/model/class-order.php index fc0c84eb3..c94877c60 100644 --- a/includes/model/class-order.php +++ b/includes/model/class-order.php @@ -131,8 +131,8 @@ public function is_private() { * * @return array */ - protected static function get_allowed_restricted_fields( $allowed_restricted_fields = array() ) { - return array( + protected static function get_allowed_restricted_fields( $allowed_restricted_fields = [] ) { + return [ 'isRestricted', 'isPrivate', 'isPublic', @@ -165,7 +165,7 @@ protected static function get_allowed_restricted_fields( $allowed_restricted_fie 'downloadable_items', 'commentCount', 'commentStatus', - ); + ]; } /** @@ -175,7 +175,7 @@ protected function init() { if ( empty( $this->fields ) ) { parent::init(); - $fields = array( + $fields = [ 'id' => function() { return ! empty( $this->wc_data->get_id() ) ? Relay::toGlobalId( 'shop_order', $this->wc_data->get_id() ) : null; }, @@ -217,84 +217,84 @@ protected function init() { }, 'discountTotal' => function() { $price = ! empty( $this->wc_data->get_discount_total() ) ? $this->wc_data->get_discount_total() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'discountTotalRaw' => array( + 'discountTotalRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_discount_total() ) ? $this->wc_data->get_discount_total() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'discountTax' => function() { $price = ! empty( $this->wc_data->get_discount_tax() ) ? $this->wc_data->get_discount_tax() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'discountTaxRaw' => array( + 'discountTaxRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_discount_tax() ) ? $this->wc_data->get_discount_tax() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'shippingTotal' => function() { $price = ! empty( $this->wc_data->get_shipping_total() ) ? $this->wc_data->get_shipping_total() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'shippingTotalRaw' => array( + 'shippingTotalRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_shipping_total() ) ? $this->wc_data->get_shipping_total() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'shippingTax' => function() { $price = ! empty( $this->wc_data->get_shipping_tax() ) ? $this->wc_data->get_shipping_tax() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'shippingTaxRaw' => array( + 'shippingTaxRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_shipping_tax() ) ? $this->wc_data->get_shipping_tax() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'cartTax' => function() { $price = ! empty( $this->wc_data->get_cart_tax() ) ? $this->wc_data->get_cart_tax() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'cartTaxRaw' => array( + 'cartTaxRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_cart_tax() ) ? $this->wc_data->get_cart_tax() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'total' => function() { $price = ! empty( $this->wc_data->get_total() ) ? $this->wc_data->get_total() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'totalRaw' => array( + 'totalRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_total() ) ? $this->wc_data->get_total() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'totalTax' => function() { $price = ! empty( $this->wc_data->get_total_tax() ) ? $this->wc_data->get_total_tax() : 0; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'totalTaxRaw' => array( + 'totalTaxRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_total_tax() ) ? $this->wc_data->get_total_tax() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'subtotal' => function() { $price = ! empty( $this->wc_data->get_subtotal() ) ? $this->wc_data->get_subtotal() : null; - return \wc_graphql_price( $price, array( 'currency' => $this->wc_data->get_currency() ) ); + return \wc_graphql_price( $price, [ 'currency' => $this->wc_data->get_currency() ] ); }, - 'subtotalRaw' => array( + 'subtotalRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_subtotal() ) ? $this->wc_data->get_subtotal() : 0; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], 'orderNumber' => function() { return ! empty( $this->wc_data->get_order_number() ) ? $this->wc_data->get_order_number() : null; }, @@ -365,32 +365,34 @@ protected function init() { * and some fields act as aliases/decorator for existing fields. */ 'commentCount' => function() { - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); + remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); - $args = array( + $args = [ 'post_id' => $this->ID, 'approve' => 'approve', 'fields' => 'ids', 'type' => '', - ); + ]; if ( ! current_user_can( $this->post_type_object->cap->edit_posts, $this->ID ) ) { - $args += array( + $args += [ + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'meta_key' => 'is_customer_note', + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 'meta_value' => true, - ); + ]; } $notes = get_comments( $args ); - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); + add_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); return count( $notes ); }, 'commentStatus' => function() { return current_user_can( $this->post_type_object->cap->edit_posts, $this->ID ) ? 'open' : 'closed'; }, - ); + ]; $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-product-variation.php b/includes/model/class-product-variation.php index d11d2c6db..dcd83c6e9 100644 --- a/includes/model/class-product-variation.php +++ b/includes/model/class-product-variation.php @@ -36,7 +36,7 @@ protected function init() { if ( empty( $this->fields ) ) { parent::init(); - $fields = array( + $fields = [ 'id' => function() { return ! empty( $this->wc_data->get_id() ) ? Relay::toGlobalId( 'product_variation', $this->wc_data->get_id() ) : null; }, @@ -152,24 +152,24 @@ protected function init() { /** * Editor/Shop Manager only fields */ - 'priceRaw' => array( + 'priceRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_price() ) ? $this->wc_data->get_price() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), - 'regularPriceRaw' => array( + ], + 'regularPriceRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_regular_price() ) ? $this->wc_data->get_regular_price() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), - 'salePriceRaw' => array( + ], + 'salePriceRaw' => [ 'callback' => function() { return ! empty( $this->wc_data->get_sale_price() ) ? $this->wc_data->get_sale_price() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], /** * Connection resolvers fields @@ -192,7 +192,7 @@ protected function init() { 'attributes' => function() { return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : null; }, - ); + ]; $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-product.php b/includes/model/class-product.php index 77cbfe6fd..6b828fb70 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -94,7 +94,7 @@ protected function init() { parent::init(); $type = $this->wc_data->get_type(); - $fields = array( + $fields = [ 'id' => function() { return ! empty( $this->wc_data->get_id() ) ? Relay::toGlobalId( 'product', $this->wc_data->get_id() ) : null; }, @@ -178,18 +178,18 @@ protected function init() { /** * Editor/Shop Manager only fields */ - 'catalogVisibility' => array( + 'catalogVisibility' => [ 'callback' => function() { return ! empty( $this->wc_data->get_catalog_visibility() ) ? $this->wc_data->get_catalog_visibility() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), - 'totalSales' => array( + ], + 'totalSales' => [ 'callback' => function() { return ! is_null( $this->wc_data->get_total_sales() ) ? $this->wc_data->get_total_sales() : null; }, 'capability' => $this->post_type_object->cap->edit_posts, - ), + ], /** * Connection resolvers fields @@ -200,25 +200,25 @@ protected function init() { 'upsell_ids' => function() { return ! empty( $this->wc_data->get_upsell_ids() ) ? array_map( 'absint', $this->wc_data->get_upsell_ids() ) - : array( '0' ); + : [ '0' ]; }, 'attributes' => function() { - return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : array(); + return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : []; }, 'default_attributes' => function() { - return ! empty( $this->wc_data->get_default_attributes() ) ? $this->wc_data->get_default_attributes() : array( '0' ); + return ! empty( $this->wc_data->get_default_attributes() ) ? $this->wc_data->get_default_attributes() : [ '0' ]; }, 'image_id' => function () { return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null; }, 'gallery_image_ids' => function() { - return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : array( '0' ); + return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : [ '0' ]; }, 'category_ids' => function() { - return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : array( '0' ); + return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : [ '0' ]; }, 'tag_ids' => function() { - return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : array( '0' ); + return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : [ '0' ]; }, 'parent_id' => function() { return ! empty( $this->wc_data->get_parent_id() ) ? $this->wc_data->get_parent_id() : null; @@ -226,7 +226,7 @@ protected function init() { 'post' => function() { return ! empty( $this->wc_data->post ) ? $this->wc_data->post : null; }, - ); + ]; if ( apply_filters( @@ -234,7 +234,7 @@ protected function init() { 'grouped' !== $this->wc_data->get_type() ) ) { - $fields += array( + $fields += [ 'price' => function() { return ! empty( $this->wc_data->get_price() ) ? \wc_graphql_price( $this->wc_data->get_price() ) @@ -265,7 +265,7 @@ protected function init() { 'taxClass' => function() { return ! is_null( $this->wc_data->get_tax_class() ) ? $this->wc_data->get_tax_class() : ''; }, - ); + ]; }//end if if ( @@ -274,7 +274,7 @@ protected function init() { 'simple' === $type || 'variable' === $type ) ) { - $fields += array( + $fields += [ 'manageStock' => function() { return ! is_null( $this->wc_data->get_manage_stock() ) ? $this->wc_data->get_manage_stock() : null; }, @@ -314,17 +314,17 @@ protected function init() { 'cross_sell_ids' => function() { return ! empty( $this->wc_data->get_cross_sell_ids() ) ? array_map( 'absint', $this->wc_data->get_cross_sell_ids() ) - : array( '0' ); + : [ '0' ]; }, 'stockStatus' => function() { return ! empty( $this->wc_data->get_stock_status() ) ? $this->wc_data->get_stock_status() : null; }, - ); + ]; }//end if switch ( true ) { case apply_filters( "graphql_{$type}_product_model_use_virtual_data_fields", 'simple' === $type ): - $fields += array( + $fields += [ 'virtual' => function() { return ! is_null( $this->wc_data->is_virtual() ) ? $this->wc_data->is_virtual() : null; }, @@ -340,10 +340,10 @@ protected function init() { 'downloads' => function() { return ! empty( $this->wc_data->get_downloads() ) ? $this->wc_data->get_downloads() : null; }, - ); + ]; break; case apply_filters( "graphql_{$type}_product_model_use_variation_pricing_fields", 'variable' === $type ): - $fields = array( + $fields = [ 'price' => function() { return $this->get_variation_price(); }, @@ -356,7 +356,7 @@ protected function init() { 'variation_ids' => function() { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) - : array( '0' ); + : [ '0' ]; }, 'priceRaw' => function() { return $this->get_variation_price( '', true ); @@ -367,20 +367,20 @@ protected function init() { 'salePriceRaw' => function() { return $this->get_variation_price( 'sale', true ); }, - ) + $fields; + ] + $fields; break; case apply_filters( "graphql_{$type}_product_model_use_external_fields", 'external' === $type ): - $fields += array( + $fields += [ 'externalUrl' => function() { return ! empty( $this->wc_data->get_product_url() ) ? $this->wc_data->get_product_url() : null; }, 'buttonText' => function() { return ! empty( $this->wc_data->get_button_text() ) ? $this->wc_data->get_button_text() : null; }, - ); + ]; break; case apply_filters( "graphql_{$type}_product_model_use_grouped_fields", 'grouped' === $type ): - $fields += array( + $fields += [ 'addToCartText' => function() { return ! empty( $this->wc_data->add_to_cart_text() ) ? $this->wc_data->add_to_cart_text() : null; }, @@ -392,9 +392,9 @@ protected function init() { 'grouped_ids' => function() { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) - : array( '0' ); + : [ '0' ]; }, - ); + ]; break; }//end switch @@ -404,7 +404,7 @@ protected function init() { * These fields are used primarily by WPGraphQL core Node* interfaces * and some fields act as aliases/decorator for existing fields. */ - $fields += array( + $fields += [ 'commentCount' => function() { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return $this->reviewCount; @@ -413,7 +413,7 @@ protected function init() { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return $this->reviewsAllowed ? 'open' : 'closed'; }, - ); + ]; $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-refund.php b/includes/model/class-refund.php index 16d8a03bd..ead75be7d 100644 --- a/includes/model/class-refund.php +++ b/includes/model/class-refund.php @@ -33,7 +33,7 @@ protected function init() { if ( empty( $this->fields ) ) { Post::init(); - $fields = array( + $fields = [ 'id' => function() { return ! empty( $this->wc_data->get_id() ) ? Relay::toGlobalId( 'shop_order_refund', $this->wc_data->get_id() ) : null; }, @@ -46,16 +46,16 @@ protected function init() { 'reason' => function() { return ! empty( $this->wc_data->get_reason() ) ? $this->wc_data->get_reason() : null; }, - 'refunded_by_id' => array( + 'refunded_by_id' => [ 'callback' => function() { return ! empty( $this->wc_data->get_refunded_by() ) ? $this->wc_data->get_refunded_by() : null; }, 'capability' => 'list_users', - ), + ], 'date' => function() { return ! empty( $this->wc_data->get_date_modified() ) ? $this->wc_data->get_date_modified() : null; }, - ); + ]; $this->fields = array_merge( $this->fields, $fields ); }//end if diff --git a/includes/model/class-shipping-method.php b/includes/model/class-shipping-method.php index 6d04ad88d..3e1800bec 100644 --- a/includes/model/class-shipping-method.php +++ b/includes/model/class-shipping-method.php @@ -25,13 +25,13 @@ class Shipping_Method extends Model { */ public function __construct( $method ) { $this->data = $method; - $allowed_restricted_fields = array( + $allowed_restricted_fields = [ 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ); + ]; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'shipping_method_restricted_cap', '' ); @@ -53,7 +53,7 @@ protected function is_private() { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = array( + $this->fields = [ 'ID' => function() { return $this->data->id; }, @@ -69,7 +69,7 @@ protected function init() { 'description' => function() { return ! empty( $this->data->method_description ) ? $this->data->method_description : null; }, - ); + ]; } } } diff --git a/includes/model/class-tax-rate.php b/includes/model/class-tax-rate.php index 9a1411e2a..b69aeca53 100644 --- a/includes/model/class-tax-rate.php +++ b/includes/model/class-tax-rate.php @@ -25,13 +25,13 @@ class Tax_Rate extends Model { */ public function __construct( $rate ) { $this->data = $rate; - $allowed_restricted_fields = array( + $allowed_restricted_fields = [ 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ); + ]; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'tax_rate_restricted_cap', '' ); @@ -53,7 +53,7 @@ protected function is_private() { */ protected function init() { if ( empty( $this->fields ) ) { - $this->fields = array( + $this->fields = [ 'ID' => function() { return $this->data->tax_rate_id; }, @@ -70,10 +70,10 @@ protected function init() { return ! empty( $this->data->tax_rate_state ) ? $this->data->tax_rate_state : null; }, 'city' => function() { - return ! empty( $this->data->tax_rate_city ) ? $this->data->tax_rate_city : array( '*' ); + return ! empty( $this->data->tax_rate_city ) ? $this->data->tax_rate_city : [ '*' ]; }, 'postcode' => function() { - return ! empty( $this->data->tax_rate_postcode ) ? $this->data->tax_rate_postcode : array( '*' ); + return ! empty( $this->data->tax_rate_postcode ) ? $this->data->tax_rate_postcode : [ '*' ]; }, 'rate' => function() { return ! empty( $this->data->tax_rate ) ? $this->data->tax_rate : null; @@ -96,7 +96,7 @@ protected function init() { 'class' => function() { return ! is_null( $this->data->tax_rate_class ) ? $this->data->tax_rate_class : ''; }, - ); + ]; }//end if } } diff --git a/includes/model/class-wc-post.php b/includes/model/class-wc-post.php index 7db80a4e4..5197bebf2 100644 --- a/includes/model/class-wc-post.php +++ b/includes/model/class-wc-post.php @@ -39,8 +39,8 @@ public function __construct( $data ) { $post = get_post( $data->get_id() ); // Add $allowed_restricted_fields. - if ( ! has_filter( 'graphql_allowed_fields_on_restricted_type', array( static::class, 'add_allowed_restricted_fields' ) ) ) { - add_filter( 'graphql_allowed_fields_on_restricted_type', array( static::class, 'add_allowed_restricted_fields' ), 10, 2 ); + if ( ! has_filter( 'graphql_allowed_fields_on_restricted_type', [ static::class, 'add_allowed_restricted_fields' ] ) ) { + add_filter( 'graphql_allowed_fields_on_restricted_type', [ static::class, 'add_allowed_restricted_fields' ], 10, 2 ); } // Execute Post Model constructor. @@ -71,14 +71,14 @@ public static function add_allowed_restricted_fields( $allowed_restricted_fields * * @return array */ - protected static function get_allowed_restricted_fields( $allowed_restricted_fields = array() ) { - return array( + protected static function get_allowed_restricted_fields( $allowed_restricted_fields = [] ) { + return [ 'isRestricted', 'isPrivate', 'isPublic', 'id', 'databaseId', - ); + ]; } /** @@ -92,7 +92,7 @@ protected static function get_allowed_restricted_fields( $allowed_restricted_fie * @throws BadMethodCallException Method not found on WC data object. */ public function __call( $method, $args ) { - if ( \is_callable( array( $this->wc_data, $method ) ) ) { + if ( \is_callable( [ $this->wc_data, $method ] ) ) { return $this->wc_data->$method( ...$args ); } diff --git a/includes/mutation/class-cart-add-fee.php b/includes/mutation/class-cart-add-fee.php index 7e433374e..c7984ae0e 100644 --- a/includes/mutation/class-cart-add-fee.php +++ b/includes/mutation/class-cart-add-fee.php @@ -26,11 +26,11 @@ class Cart_Add_Fee { public static function register_mutation() { register_graphql_mutation( 'addFee', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -40,24 +40,24 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - $input_fields = array( - 'name' => array( - 'type' => array( 'non_null' => 'String' ), + $input_fields = [ + 'name' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Unique name for the fee.', 'wp-graphql-woocommerce' ), - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - ), - 'taxable' => array( + ], + 'taxable' => [ 'type' => 'Boolean', 'description' => __( 'Is the fee taxable?', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'The tax class for the fee if taxable.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; return $input_fields; } @@ -68,16 +68,16 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'cartFee' => array( + return [ + 'cartFee' => [ 'type' => 'CartFee', 'resolve' => function ( $payload ) { $fees = \WC()->cart->get_fees(); return $fees[ $payload['id'] ]; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -108,7 +108,7 @@ public static function mutate_and_get_payload() { \WC()->cart->add_fee( ...$cart_fee_args ); // Return payload. - return array( 'id' => \sanitize_title( $input['name'] ) ); + return [ 'id' => \sanitize_title( $input['name'] ) ]; }; } } diff --git a/includes/mutation/class-cart-add-item.php b/includes/mutation/class-cart-add-item.php index 88366a7ee..a57f613b1 100644 --- a/includes/mutation/class-cart-add-item.php +++ b/includes/mutation/class-cart-add-item.php @@ -26,11 +26,11 @@ class Cart_Add_Item { public static function register_mutation() { register_graphql_mutation( 'addToCart', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -40,28 +40,28 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'productId' => array( - 'type' => array( 'non_null' => 'Int' ), + return [ + 'productId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - ), - 'variationId' => array( + ], + 'variationId' => [ 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - ), - 'variation' => array( - 'type' => array( 'list_of' => 'ProductAttributeInput' ), + ], + 'variation' => [ + 'type' => [ 'list_of' => 'ProductAttributeInput' ], 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - ), - 'extraData' => array( + ], + 'extraData' => [ 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -70,17 +70,17 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'cartItem' => array( + return [ + 'cartItem' => [ 'type' => 'CartItem', 'resolve' => function ( $payload ) { $item = \WC()->cart->get_cart_item( $payload['key'] ); return $item; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -105,7 +105,7 @@ public static function mutate_and_get_payload() { // If cart item key valid return payload. if ( false !== $cart_item_key ) { - return array( 'key' => $cart_item_key ); + return [ 'key' => $cart_item_key ]; } // Process errors. diff --git a/includes/mutation/class-cart-add-items.php b/includes/mutation/class-cart-add-items.php index 94cdcca5b..059c5fd92 100644 --- a/includes/mutation/class-cart-add-items.php +++ b/includes/mutation/class-cart-add-items.php @@ -25,11 +25,11 @@ class Cart_Add_Items { public static function register_mutation() { register_graphql_mutation( 'addCartItems', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -39,12 +39,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'items' => array( - 'type' => array( 'list_of' => 'CartItemInput' ), + return [ + 'items' => [ + 'type' => [ 'list_of' => 'CartItemInput' ], 'description' => __( 'Cart items to be added', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -53,22 +53,22 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'added' => array( - 'type' => array( 'list_of' => 'CartItem' ), + return [ + 'added' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { - $items = array(); + $items = []; foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); } return $items; }, - ), - 'cartErrors' => array( - 'type' => array( 'list_of' => 'CartItemError' ), + ], + 'cartErrors' => [ + 'type' => [ 'list_of' => 'CartItemError' ], 'resolve' => function ( $payload ) { - $errors = array(); + $errors = []; foreach ( $payload['failure'] as $error_data ) { $cart_error = $error_data['cart_item_data']; $cart_error['type'] = 'INVALID_CART_ITEM'; @@ -76,7 +76,7 @@ public static function get_output_fields() { if ( ! empty( $error_data['reasons'] ) ) { $cart_error['reasons'] = $error_data['reasons']; } elseif ( $error_data['reason'] ) { - $cart_error['reasons'] = array( $error_data['reason'] ); + $cart_error['reasons'] = [ $error_data['reason'] ]; } $errors[] = $cart_error; @@ -84,9 +84,9 @@ public static function get_output_fields() { return $errors; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -104,8 +104,8 @@ public static function mutate_and_get_payload() { } // Validate cart item input. - $added = array(); - $failure = array(); + $added = []; + $failure = []; foreach ( $input['items'] as $cart_item_data ) { try { // Prepare args for "add_to_cart" from input data. @@ -142,7 +142,7 @@ public static function mutate_and_get_payload() { // Log captured errors. if ( ! empty( $failure ) ) { - graphql_debug( $failure, array( 'type' => 'INVALID_CART_ITEMS' ) ); + graphql_debug( $failure, [ 'type' => 'INVALID_CART_ITEMS' ] ); } // Throw error, if no items added. diff --git a/includes/mutation/class-cart-apply-coupon.php b/includes/mutation/class-cart-apply-coupon.php index 9322cee6d..9dcb49875 100644 --- a/includes/mutation/class-cart-apply-coupon.php +++ b/includes/mutation/class-cart-apply-coupon.php @@ -25,11 +25,11 @@ class Cart_Apply_Coupon { public static function register_mutation() { register_graphql_mutation( 'applyCoupon', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -39,12 +39,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'code' => array( - 'type' => array( 'non_null' => 'String' ), + return [ + 'code' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Code of coupon being applied', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -53,15 +53,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'applied' => array( + return [ + 'applied' => [ 'type' => 'AppliedCoupon', 'resolve' => function( $payload ) { return $payload['code']; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -76,7 +76,7 @@ public static function mutate_and_get_payload() { $reason = ''; // If validate and successful applied to cart, return payload. if ( Cart_Mutation::validate_coupon( $input['code'], $reason ) && \WC()->cart->apply_coupon( $input['code'] ) ) { - return array( 'code' => $input['code'] ); + return [ 'code' => $input['code'] ]; } // If any session error notices, capture them. diff --git a/includes/mutation/class-cart-empty.php b/includes/mutation/class-cart-empty.php index ca74358f4..8e22ee155 100644 --- a/includes/mutation/class-cart-empty.php +++ b/includes/mutation/class-cart-empty.php @@ -26,13 +26,13 @@ class Cart_Empty { public static function register_mutation() { register_graphql_mutation( 'emptyCart', - array( - 'inputFields' => array( - 'clearPersistentCart' => array( 'type' => 'Boolean' ), - ), + [ + 'inputFields' => [ + 'clearPersistentCart' => [ 'type' => 'Boolean' ], + ], 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -42,15 +42,15 @@ public static function register_mutation() { * @return array */ public static function get_output_fields() { - return array( + return [ 'deletedCart' => Cart_Mutation::get_cart_field(), - 'cart' => array( + 'cart' => [ 'type' => 'Cart', 'resolve' => function () { return \WC()->cart; }, - ), - ); + ], + ]; } /** @@ -93,7 +93,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_empty_cart', $cloned_cart, $input, $context, $info ); - return array( 'cart' => $cloned_cart ); + return [ 'cart' => $cloned_cart ]; }; } } diff --git a/includes/mutation/class-cart-fill.php b/includes/mutation/class-cart-fill.php index 5b3525934..684ab68d6 100644 --- a/includes/mutation/class-cart-fill.php +++ b/includes/mutation/class-cart-fill.php @@ -26,11 +26,11 @@ class Cart_Fill { public static function register_mutation() { register_graphql_mutation( 'fillCart', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -40,20 +40,20 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'shippingMethods' => array( - 'type' => array( 'list_of' => 'String' ), + return [ + 'shippingMethods' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Shipping methods to be used.', 'wp-graphql-woocommerce' ), - ), - 'coupons' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'coupons' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Coupons to be applied to the cart', 'wp-graphql-woocommerce' ), - ), - 'items' => array( - 'type' => array( 'list_of' => 'CartItemInput' ), + ], + 'items' => [ + 'type' => [ 'list_of' => 'CartItemInput' ], 'description' => __( 'Cart items to be added', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -62,36 +62,36 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'added' => array( - 'type' => array( 'list_of' => 'CartItem' ), + return [ + 'added' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { - $items = array(); + $items = []; foreach ( $payload['added'] as $key ) { $items[] = \WC()->cart->get_cart_item( $key ); } return $items; }, - ), - 'applied' => array( - 'type' => array( 'list_of' => 'AppliedCoupon' ), + ], + 'applied' => [ + 'type' => [ 'list_of' => 'AppliedCoupon' ], 'resolve' => function( $payload ) { $codes = $payload['applied']; return ! empty( $codes ) ? $codes : null; }, - ), - 'chosenShippingMethods' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'chosenShippingMethods' => [ + 'type' => [ 'list_of' => 'String' ], 'resolve' => function( $payload ) { $methods = $payload['chosen_shipping_methods']; return ! empty( $methods ) ? $methods : null; }, - ), - 'cartErrors' => array( - 'type' => array( 'list_of' => 'CartError' ), + ], + 'cartErrors' => [ + 'type' => [ 'list_of' => 'CartError' ], 'resolve' => function ( $payload ) { - $errors = array(); + $errors = []; $all_error_data = array_merge( $payload['invalid_cart_items'], $payload['invalid_coupons'], @@ -105,14 +105,14 @@ public static function get_output_fields() { $cart_error['type'] = 'INVALID_CART_ITEM'; break; case isset( $error_data['code'] ): - $cart_error = array( 'code' => $error_data['code'] ); + $cart_error = [ 'code' => $error_data['code'] ]; $cart_error['type'] = 'INVALID_COUPON'; break; case isset( $error_data['package'] ): - $cart_error = array( + $cart_error = [ 'package' => $error_data['package'], 'chosen_method' => $error_data['chosen_method'], - ); + ]; $cart_error['type'] = 'INVALID_SHIPPING_METHOD'; break; } @@ -120,7 +120,7 @@ public static function get_output_fields() { if ( ! empty( $error_data['reasons'] ) ) { $cart_error['reasons'] = $error_data['reasons']; } elseif ( $error_data['reason'] ) { - $cart_error['reasons'] = array( $error_data['reason'] ); + $cart_error['reasons'] = [ $error_data['reason'] ]; } $errors[] = $cart_error; @@ -128,9 +128,9 @@ public static function get_output_fields() { return $errors; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -148,8 +148,8 @@ public static function mutate_and_get_payload() { } // Validate cart item input. - $added = array(); - $invalid_cart_items = array(); + $added = []; + $invalid_cart_items = []; foreach ( $input['items'] as $cart_item_data ) { try { // Prepare args for "add_to_cart" from input data. @@ -186,7 +186,7 @@ public static function mutate_and_get_payload() { // Log captured errors. if ( ! empty( $invalid_cart_items ) ) { - graphql_debug( $invalid_cart_items, array( 'type' => 'INVALID_CART_ITEMS' ) ); + graphql_debug( $invalid_cart_items, [ 'type' => 'INVALID_CART_ITEMS' ] ); } // Throw error, if no items added. @@ -194,8 +194,8 @@ public static function mutate_and_get_payload() { throw new UserError( __( 'Failed to add any cart items. Please check input.', 'wp-graphql-woocommerce' ) ); } - $applied = array(); - $invalid_coupons = array(); + $applied = []; + $invalid_coupons = []; if ( ! empty( $input['coupons'] ) ) { foreach ( $input['coupons'] as $code ) { $reason = ''; @@ -220,12 +220,12 @@ public static function mutate_and_get_payload() { }//end foreach if ( ! empty( $invalid_coupons ) ) { - graphql_debug( $invalid_coupons, array( 'type' => 'INVALID_COUPONS' ) ); + graphql_debug( $invalid_coupons, [ 'type' => 'INVALID_COUPONS' ] ); } }//end if - $chosen_shipping_methods = array(); - $invalid_shipping_methods = array(); + $chosen_shipping_methods = []; + $invalid_shipping_methods = []; if ( ! empty( $input['shippingMethods'] ) ) { $posted_shipping_methods = $input['shippingMethods']; @@ -251,7 +251,7 @@ public static function mutate_and_get_payload() { \WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); if ( ! empty( $invalid_shipping_methods ) ) { - graphql_debug( $invalid_shipping_methods, array( 'type' => 'INVALID_SHIPPING_METHODS' ) ); + graphql_debug( $invalid_shipping_methods, [ 'type' => 'INVALID_SHIPPING_METHODS' ] ); } }//end if diff --git a/includes/mutation/class-cart-remove-coupons.php b/includes/mutation/class-cart-remove-coupons.php index b564697eb..0db2a57f3 100644 --- a/includes/mutation/class-cart-remove-coupons.php +++ b/includes/mutation/class-cart-remove-coupons.php @@ -24,11 +24,11 @@ class Cart_Remove_Coupons { public static function register_mutation() { register_graphql_mutation( 'removeCoupons', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -38,12 +38,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'codes' => array( - 'type' => array( 'list_of' => 'String' ), + return [ + 'codes' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Code of coupon being applied', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -52,9 +52,9 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( + return [ 'cart' => Cart_Mutation::get_cart_field(), - ); + ]; } /** @@ -86,7 +86,7 @@ public static function mutate_and_get_payload() { } // Return payload. - return array( 'cart' => \WC()->cart ); + return [ 'cart' => \WC()->cart ]; }; } } diff --git a/includes/mutation/class-cart-remove-items.php b/includes/mutation/class-cart-remove-items.php index d6b5743d5..dba77fb9b 100644 --- a/includes/mutation/class-cart-remove-items.php +++ b/includes/mutation/class-cart-remove-items.php @@ -26,11 +26,11 @@ class Cart_Remove_Items { public static function register_mutation() { register_graphql_mutation( 'removeItemsFromCart', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -40,16 +40,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'keys' => array( - 'type' => array( 'list_of' => 'ID' ), + return [ + 'keys' => [ + 'type' => [ 'list_of' => 'ID' ], 'description' => __( 'Item keys of the items being removed', 'wp-graphql-woocommerce' ), - ), - 'all' => array( + ], + 'all' => [ 'type' => 'Boolean', 'description' => __( 'Remove all cart items', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -58,15 +58,15 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'cartItems' => array( - 'type' => array( 'list_of' => 'CartItem' ), + return [ + 'cartItems' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { return $payload['items']; }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -96,7 +96,7 @@ public static function mutate_and_get_payload() { } // Return payload. - return array( 'items' => $cart_items ); + return [ 'items' => $cart_items ]; }; } } diff --git a/includes/mutation/class-cart-restore-items.php b/includes/mutation/class-cart-restore-items.php index 473aa6742..0ef1712bf 100644 --- a/includes/mutation/class-cart-restore-items.php +++ b/includes/mutation/class-cart-restore-items.php @@ -26,11 +26,11 @@ class Cart_Restore_Items { public static function register_mutation() { register_graphql_mutation( 'restoreCartItems', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -40,12 +40,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'keys' => array( - 'type' => array( 'list_of' => 'ID' ), + return [ + 'keys' => [ + 'type' => [ 'list_of' => 'ID' ], 'description' => __( 'Cart item key of the item being removed', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -82,7 +82,7 @@ public static function mutate_and_get_payload() { $cart_items = Cart_Mutation::retrieve_cart_items( $input, $context, $info, 'restore' ); // Return payload. - return array( 'items' => $cart_items ); + return [ 'items' => $cart_items ]; }; } } diff --git a/includes/mutation/class-cart-update-item-quantities.php b/includes/mutation/class-cart-update-item-quantities.php index f3021bcbd..75c0efb2f 100644 --- a/includes/mutation/class-cart-update-item-quantities.php +++ b/includes/mutation/class-cart-update-item-quantities.php @@ -27,11 +27,11 @@ class Cart_Update_Item_Quantities { public static function register_mutation() { register_graphql_mutation( 'updateItemQuantities', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -41,12 +41,12 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'items' => array( - 'type' => array( 'list_of' => 'CartItemQuantityInput' ), + return [ + 'items' => [ + 'type' => [ 'list_of' => 'CartItemQuantityInput' ], 'description' => __( 'Cart item being updated', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -55,37 +55,37 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'updated' => array( - 'type' => array( 'list_of' => 'CartItem' ), + return [ + 'updated' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { - $items = array(); + $items = []; foreach ( $payload['updated'] as $key ) { $items[] = WC()->cart->get_cart_item( $key ); } return $items; }, - ), - 'removed' => array( - 'type' => array( 'list_of' => 'CartItem' ), + ], + 'removed' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { return $payload['removed']; }, - ), - 'items' => array( - 'type' => array( 'list_of' => 'CartItem' ), + ], + 'items' => [ + 'type' => [ 'list_of' => 'CartItem' ], 'resolve' => function ( $payload ) { - $updated = array(); + $updated = []; foreach ( $payload['updated'] as $key ) { $updated[] = \WC()->cart->get_cart_item( $key ); } return array_merge( $updated, $payload['removed'] ); }, - ), + ], 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -110,9 +110,9 @@ public static function mutate_and_get_payload() { do_action( 'graphql_woocommerce_before_set_item_quantities', $input['items'], $input, $context, $info ); // Update quantities. If quantity set to 0, the items in removed. - $removed = array(); - $updated = array(); - $removed_items = array(); + $removed = []; + $updated = []; + $removed_items = []; foreach ( $input['items'] as $item ) { if ( Cart_Mutation::item_is_valid( $item ) ) { $key = $item['key']; @@ -163,10 +163,10 @@ function( $value ) { $info ); - return array( + return [ 'removed' => $removed_items, 'updated' => array_keys( $updated ), - ); + ]; }; } } diff --git a/includes/mutation/class-cart-update-shipping-method.php b/includes/mutation/class-cart-update-shipping-method.php index e1c3353f3..3fae06d5c 100644 --- a/includes/mutation/class-cart-update-shipping-method.php +++ b/includes/mutation/class-cart-update-shipping-method.php @@ -24,11 +24,11 @@ class Cart_Update_Shipping_Method { public static function register_mutation() { register_graphql_mutation( 'updateShippingMethod', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -38,11 +38,11 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'shippingMethods' => array( - 'type' => array( 'list_of' => 'String' ), - ), - ); + return [ + 'shippingMethods' => [ + 'type' => [ 'list_of' => 'String' ], + ], + ]; } /** @@ -51,9 +51,9 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( + return [ 'cart' => Cart_Mutation::get_cart_field( true ), - ); + ]; } /** @@ -77,7 +77,7 @@ public static function mutate_and_get_payload() { // Recalculate totals. \WC()->cart->calculate_totals(); - return array(); + return []; }; } } diff --git a/includes/mutation/class-checkout.php b/includes/mutation/class-checkout.php index 8a0e8a95b..ba5bfc2d8 100644 --- a/includes/mutation/class-checkout.php +++ b/includes/mutation/class-checkout.php @@ -30,11 +30,11 @@ class Checkout { public static function register_mutation() { register_graphql_mutation( 'checkout', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -44,48 +44,48 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'paymentMethod' => array( + return [ + 'paymentMethod' => [ 'type' => 'String', 'description' => __( 'Payment method ID.', 'wp-graphql-woocommerce' ), - ), - 'shippingMethod' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'shippingMethod' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Order shipping method', 'wp-graphql-woocommerce' ), - ), - 'shipToDifferentAddress' => array( + ], + 'shipToDifferentAddress' => [ 'type' => 'Boolean', 'description' => __( 'Ship to a separate address', 'wp-graphql-woocommerce' ), - ), - 'billing' => array( + ], + 'billing' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Order billing address', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Order shipping address', 'wp-graphql-woocommerce' ), - ), - 'account' => array( + ], + 'account' => [ 'type' => 'CreateAccountInput', 'description' => __( 'Create new customer account', 'wp-graphql-woocommerce' ), - ), - 'transactionId' => array( + ], + 'transactionId' => [ 'type' => 'String', 'description' => __( 'Order transaction ID', 'wp-graphql-woocommerce' ), - ), - 'isPaid' => array( + ], + 'isPaid' => [ 'type' => 'Boolean', 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( - 'type' => array( 'list_of' => 'MetaDataInput' ), + ], + 'metaData' => [ + 'type' => [ 'list_of' => 'MetaDataInput' ], 'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ), - ), - 'customerNote' => array( + ], + 'customerNote' => [ 'type' => 'String', 'description' => __( 'Order customer note', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -94,32 +94,32 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'order' => array( + return [ + 'order' => [ 'type' => 'Order', 'resolve' => function( $payload ) { return new Order( $payload['id'] ); }, - ), - 'customer' => array( + ], + 'customer' => [ 'type' => 'Customer', 'resolve' => function() { return is_user_logged_in() ? new Customer( get_current_user_id() ) : null; }, - ), - 'result' => array( + ], + 'result' => [ 'type' => 'String', 'resolve' => function( $payload ) { return $payload['result']; }, - ), - 'redirect' => array( + ], + 'redirect' => [ 'type' => 'String', 'resolve' => function( $payload ) { return $payload['redirect']; }, - ), - ); + ], + ]; } /** @@ -161,7 +161,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_checkout', $order, $input, $context, $info ); - return array_merge( array( 'id' => $order_id ), $results ); + return array_merge( [ 'id' => $order_id ], $results ); } catch ( Exception $e ) { Order_Mutation::purge( $order ); throw new UserError( $e->getMessage() ); diff --git a/includes/mutation/class-coupon-create.php b/includes/mutation/class-coupon-create.php index f8799c697..59fc530f4 100644 --- a/includes/mutation/class-coupon-create.php +++ b/includes/mutation/class-coupon-create.php @@ -28,11 +28,11 @@ class Coupon_Create { public static function register_mutation() { register_graphql_mutation( 'createCoupon', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => array( __CLASS__, 'mutate_and_get_payload' ), - ) + 'mutateAndGetPayload' => [ __CLASS__, 'mutate_and_get_payload' ], + ] ); } @@ -42,88 +42,88 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'code' => array( - 'type' => array( 'non_null' => 'String' ), + return [ + 'code' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'wp-graphql-woocommerce' ), - ), - 'discountType' => array( + ], + 'discountType' => [ 'type' => 'DiscountTypeEnum', 'description' => __( 'Determines the type of discount that will be applied.', 'wp-graphql-woocommerce' ), - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Coupon description.', 'wp-graphql-woocommerce' ), - ), - 'dateExpires' => array( + ], + 'dateExpires' => [ 'type' => 'String', 'description' => __( 'The date the coupon expires, in the site\'s timezone.', 'wp-graphql-woocommerce' ), - ), - 'dateExpiresGmt' => array( + ], + 'dateExpiresGmt' => [ 'type' => 'String', 'description' => __( 'The date the coupon expires, as GMT.', 'wp-graphql-woocommerce' ), - ), - 'individualUse' => array( + ], + 'individualUse' => [ 'type' => 'Boolean', 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'wp-graphql-woocommerce' ), - ), - 'productIds' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'productIds' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'List of product IDs the coupon can be used on.', 'wp-graphql-woocommerce' ), - ), - 'excludedProductIds' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'excludedProductIds' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'List of product IDs the coupon cannot be used on.', 'wp-graphql-woocommerce' ), - ), - 'usageLimit' => array( + ], + 'usageLimit' => [ 'type' => 'Int', 'description' => __( 'How many times the coupon can be used in total.', 'wp-graphql-woocommerce' ), - ), - 'usageLimitPerUser' => array( + ], + 'usageLimitPerUser' => [ 'type' => 'Int', 'description' => __( 'How many times the coupon can be used per customer.', 'wp-graphql-woocommerce' ), - ), - 'limitUsageToXItems' => array( + ], + 'limitUsageToXItems' => [ 'type' => 'Int', 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'wp-graphql-woocommerce' ), - ), - 'freeShipping' => array( + ], + 'freeShipping' => [ 'type' => 'Boolean', 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'wp-graphql-woocommerce' ), - ), - 'productCategories' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'productCategories' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'List of category IDs the coupon applies to.', 'wp-graphql-woocommerce' ), - ), - 'excludedProductCategories' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'excludedProductCategories' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'List of category IDs the coupon does not apply to.', 'wp-graphql-woocommerce' ), - ), - 'excludeSaleItems' => array( + ], + 'excludeSaleItems' => [ 'type' => 'Boolean', 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'wp-graphql-woocommerce' ), - ), - 'minimumAmount' => array( + ], + 'minimumAmount' => [ 'type' => 'String', 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'wp-graphql-woocommerce' ), - ), - 'maximumAmount' => array( + ], + 'maximumAmount' => [ 'type' => 'String', 'description' => __( 'Maximum order amount allowed when using the coupon.', 'wp-graphql-woocommerce' ), - ), - 'emailRestrictions' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'emailRestrictions' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'List of email addresses that can use this coupon.', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( - 'type' => array( 'list_of' => 'MetaDataInput' ), + ], + 'metaData' => [ + 'type' => [ 'list_of' => 'MetaDataInput' ], 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -132,20 +132,20 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'coupon' => array( + return [ + 'coupon' => [ 'type' => 'Coupon', 'resolve' => function( $payload ) { return new Coupon( $payload['id'] ); }, - ), - 'code' => array( + ], + 'code' => [ 'type' => 'String', 'resolve' => function( $payload ) { return $payload['code']; }, - ), - ); + ], + ]; } /** @@ -210,13 +210,13 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso $coupon->set_description( wp_filter_post_kses( $value ) ); break; default: - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { + if ( is_callable( [ $coupon, "set_{$key}" ] ) ) { $coupon->{"set_{$key}"}( $value ); } break; }//end switch }//end foreach - return array( 'id' => $coupon->save() ); + return [ 'id' => $coupon->save() ]; } } diff --git a/includes/mutation/class-coupon-delete.php b/includes/mutation/class-coupon-delete.php index 37f74da2e..2d946b67c 100644 --- a/includes/mutation/class-coupon-delete.php +++ b/includes/mutation/class-coupon-delete.php @@ -27,11 +27,11 @@ class Coupon_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteCoupon', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => array( __CLASS__, 'mutate_and_get_payload' ), - ) + 'mutateAndGetPayload' => [ __CLASS__, 'mutate_and_get_payload' ], + ] ); } @@ -41,16 +41,16 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - return array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + return [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Unique identifier for the object.', 'wp-graphql-woocommerce' ), - ), - 'forceDelete' => array( + ], + 'forceDelete' => [ 'type' => 'Boolean', 'description' => __( 'Delete the object. Set to "false" by default.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -61,14 +61,14 @@ public static function get_input_fields() { public static function get_output_fields() { return array_merge( Coupon_Create::get_output_fields(), - array( - 'coupon' => array( + [ + 'coupon' => [ 'type' => 'Coupon', 'resolve' => function( $payload ) { return ! empty( $payload['coupon'] ) ? $payload['coupon'] : null; }, - ), - ) + ], + ] ); } diff --git a/includes/mutation/class-coupon-update.php b/includes/mutation/class-coupon-update.php index 5e1f49246..779f94950 100644 --- a/includes/mutation/class-coupon-update.php +++ b/includes/mutation/class-coupon-update.php @@ -21,11 +21,11 @@ class Coupon_Update { public static function register_mutation() { register_graphql_mutation( 'updateCoupon', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => Coupon_Create::get_output_fields(), - 'mutateAndGetPayload' => array( Coupon_Create::class, 'mutate_and_get_payload' ), - ) + 'mutateAndGetPayload' => [ Coupon_Create::class, 'mutate_and_get_payload' ], + ] ); } @@ -37,16 +37,16 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Coupon_Create::get_input_fields(), - array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Unique identifier for the object.', 'wp-graphql-woocommerce' ), - ), - 'code' => array( + ], + 'code' => [ 'type' => 'String', 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } } diff --git a/includes/mutation/class-customer-register.php b/includes/mutation/class-customer-register.php index 1c7b99dad..219466c0d 100644 --- a/includes/mutation/class-customer-register.php +++ b/includes/mutation/class-customer-register.php @@ -29,11 +29,11 @@ class Customer_Register { public static function register_mutation() { register_graphql_mutation( 'registerCustomer', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -45,24 +45,24 @@ public static function register_mutation() { public static function get_input_fields() { $result = array_merge( UserRegister::get_input_fields(), - array( - 'billing' => array( + [ + 'billing' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Customer billing information', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Customer shipping address', 'wp-graphql-woocommerce' ), - ), - 'shippingSameAsBilling' => array( + ], + 'shippingSameAsBilling' => [ 'type' => 'Boolean', 'description' => __( 'Customer shipping is identical to billing address', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( + ], + 'metaData' => [ 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'type' => array( 'list_of' => 'MetaDataInput' ), - ), - ) + 'type' => [ 'list_of' => 'MetaDataInput' ], + ], + ] ); // Make the username field optional. @@ -77,21 +77,21 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'customer' => array( + return [ + 'customer' => [ 'type' => 'Customer', 'resolve' => function ( $payload ) { return new Customer( $payload['id'] ); }, - ), - 'viewer' => array( + ], + 'viewer' => [ 'type' => 'User', 'resolve' => function ( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); return new User( $user ); }, - ), - ); + ], + ]; } /** @@ -190,7 +190,7 @@ public static function mutate_and_get_payload() { } // Return payload. - return array( 'id' => $user_id ); + return [ 'id' => $user_id ]; }; } } diff --git a/includes/mutation/class-customer-update.php b/includes/mutation/class-customer-update.php index a7d76d500..2f5f155df 100644 --- a/includes/mutation/class-customer-update.php +++ b/includes/mutation/class-customer-update.php @@ -28,11 +28,11 @@ class Customer_Update { public static function register_mutation() { register_graphql_mutation( 'updateCustomer', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -44,28 +44,28 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( UserCreate::get_input_fields(), - array( - 'id' => array( + [ + 'id' => [ 'type' => 'ID', 'description' => __( 'The ID of the user', 'wp-graphql-woocommerce' ), - ), - 'billing' => array( + ], + 'billing' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Customer billing information', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Customer shipping address', 'wp-graphql-woocommerce' ), - ), - 'shippingSameAsBilling' => array( + ], + 'shippingSameAsBilling' => [ 'type' => 'Boolean', 'description' => __( 'Customer shipping is identical to billing address', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( + ], + 'metaData' => [ 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'type' => array( 'list_of' => 'MetaDataInput' ), - ), - ) + 'type' => [ 'list_of' => 'MetaDataInput' ], + ], + ] ); } @@ -75,14 +75,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'customer' => array( + return [ + 'customer' => [ 'type' => 'Customer', 'resolve' => function ( $payload ) { return new Customer( $payload['id'] ); }, - ), - ); + ], + ]; } /** @@ -129,13 +129,13 @@ public static function mutate_and_get_payload() { // Check if group field has set function and assigns new value. foreach ( $value as $field => $field_value ) { - if ( is_callable( array( $customer, "set_{$prop}_{$field}" ) ) ) { + if ( is_callable( [ $customer, "set_{$prop}_{$field}" ] ) ) { $customer->{"set_{$prop}_{$field}"}( $field_value ); } } // If field has set function and assigns new value. - } elseif ( is_callable( array( $customer, "set_{$prop}" ) ) ) { + } elseif ( is_callable( [ $customer, "set_{$prop}" ] ) ) { $customer->{"set_{$prop}"}( $value ); } } @@ -149,7 +149,7 @@ public static function mutate_and_get_payload() { $customer->save(); // Return payload. - return ! empty( $payload ) ? $payload : array( 'id' => 'session' ); + return ! empty( $payload ) ? $payload : [ 'id' => 'session' ]; }; } } diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index e82b3caaf..6ca4f8e51 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -29,11 +29,11 @@ class Order_Create { public static function register_mutation() { register_graphql_mutation( 'createOrder', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -43,72 +43,72 @@ public static function register_mutation() { * @return array */ public static function get_input_fields() { - $input_fields = array( - 'parentId' => array( + $input_fields = [ + 'parentId' => [ 'type' => 'Int', 'description' => __( 'Parent order ID.', 'wp-graphql-woocommerce' ), - ), - 'currency' => array( + ], + 'currency' => [ 'type' => 'String', 'description' => __( 'Currency the order was created with, in ISO format.', 'wp-graphql-woocommerce' ), - ), - 'customerId' => array( + ], + 'customerId' => [ 'type' => 'Int', 'description' => __( 'Order customer ID', 'wp-graphql-woocommerce' ), - ), - 'customerNote' => array( + ], + 'customerNote' => [ 'type' => 'String', 'description' => __( 'Note left by customer during checkout.', 'wp-graphql-woocommerce' ), - ), - 'coupons' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'coupons' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Coupons codes to be applied to order', 'wp-graphql-woocommerce' ), - ), - 'status' => array( + ], + 'status' => [ 'type' => 'OrderStatusEnum', 'description' => __( 'Order status', 'wp-graphql-woocommerce' ), - ), - 'paymentMethod' => array( + ], + 'paymentMethod' => [ 'type' => 'String', 'description' => __( 'Payment method ID.', 'wp-graphql-woocommerce' ), - ), - 'paymentMethodTitle' => array( + ], + 'paymentMethodTitle' => [ 'type' => 'String', 'description' => __( 'Payment method title.', 'wp-graphql-woocommerce' ), - ), - 'transactionId' => array( + ], + 'transactionId' => [ 'type' => 'String', 'description' => __( 'Order transaction ID', 'wp-graphql-woocommerce' ), - ), - 'billing' => array( + ], + 'billing' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Order billing address', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddressInput', 'description' => __( 'Order shipping address', 'wp-graphql-woocommerce' ), - ), - 'lineItems' => array( - 'type' => array( 'list_of' => 'LineItemInput' ), + ], + 'lineItems' => [ + 'type' => [ 'list_of' => 'LineItemInput' ], 'description' => __( 'Order line items', 'wp-graphql-woocommerce' ), - ), - 'shippingLines' => array( - 'type' => array( 'list_of' => 'ShippingLineInput' ), + ], + 'shippingLines' => [ + 'type' => [ 'list_of' => 'ShippingLineInput' ], 'description' => __( 'Order shipping lines', 'wp-graphql-woocommerce' ), - ), - 'feeLines' => array( - 'type' => array( 'list_of' => 'FeeLineInput' ), + ], + 'feeLines' => [ + 'type' => [ 'list_of' => 'FeeLineInput' ], 'description' => __( 'Order shipping lines', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( - 'type' => array( 'list_of' => 'MetaDataInput' ), + ], + 'metaData' => [ + 'type' => [ 'list_of' => 'MetaDataInput' ], 'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ), - ), - 'isPaid' => array( + ], + 'isPaid' => [ 'type' => 'Boolean', 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; return $input_fields; } @@ -119,20 +119,20 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'order' => array( + return [ + 'order' => [ 'type' => 'Order', 'resolve' => function( $payload ) { return new Order( $payload['id'] ); }, - ), - 'orderId' => array( + ], + 'orderId' => [ 'type' => 'Int', 'resolve' => function( $payload ) { return $payload['id']; }, - ), - ); + ], + ]; } /** @@ -143,7 +143,7 @@ public static function get_output_fields() { public static function mutate_and_get_payload() { return function( $input, AppContext $context, ResolveInfo $info ) { // Check if authorized to create this order. - if ( ! Order_Mutation::authorized( 'create', null, $input, $context, $info ) ) { + 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' ) ); } @@ -195,7 +195,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_create', $order, $input, $context, $info ); - return array( 'id' => $order->get_id() ); + return [ 'id' => $order->get_id() ]; } catch ( Exception $e ) { Order_Mutation::purge( $order ); throw new UserError( $e->getMessage() ); diff --git a/includes/mutation/class-order-delete-items.php b/includes/mutation/class-order-delete-items.php index b081496dc..42104b08b 100644 --- a/includes/mutation/class-order-delete-items.php +++ b/includes/mutation/class-order-delete-items.php @@ -28,11 +28,11 @@ class Order_Delete_Items { public static function register_mutation() { register_graphql_mutation( 'deleteOrderItems', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -43,20 +43,20 @@ public static function register_mutation() { */ public static function get_input_fields() { return array_merge( - array( - 'id' => array( + [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Order global ID', 'wp-graphql-woocommerce' ), - ), - 'orderId' => array( + ], + 'orderId' => [ 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), - ), - 'itemIds' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'itemIds' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'ID Order items being deleted', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -66,14 +66,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'order' => array( + return [ + 'order' => [ 'type' => 'Order', 'resolve' => function( $payload ) { return $payload['order']; }, - ), - ); + ], + ]; } /** @@ -98,7 +98,7 @@ public static function mutate_and_get_payload() { } // Check if authorized to delete items on this order. - if ( ! Order_Mutation::authorized( 'delete-items', $order_id, $input, $context, $info ) ) { + if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete-items', $order_id ) ) { throw new UserError( __( 'User does not have the capabilities necessary to delete an order.', 'wp-graphql-woocommerce' ) ); } @@ -153,7 +153,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_delete', $ids, $working_order, $input, $context, $info ); - return array( 'order' => $order ); + return [ 'order' => $order ]; }; } } diff --git a/includes/mutation/class-order-delete.php b/includes/mutation/class-order-delete.php index e22ec897b..da432f474 100644 --- a/includes/mutation/class-order-delete.php +++ b/includes/mutation/class-order-delete.php @@ -29,11 +29,11 @@ class Order_Delete { public static function register_mutation() { register_graphql_mutation( 'deleteOrder', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -44,20 +44,20 @@ public static function register_mutation() { */ public static function get_input_fields() { return array_merge( - array( - 'id' => array( + [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Order global ID', 'wp-graphql-woocommerce' ), - ), - 'orderId' => array( + ], + 'orderId' => [ 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), - ), - 'forceDelete' => array( + ], + 'forceDelete' => [ 'type' => 'Boolean', 'description' => __( 'Delete or simply place in trash.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -67,14 +67,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'order' => array( + return [ + 'order' => [ 'type' => 'Order', 'resolve' => function( $payload ) { return $payload['order']; }, - ), - ); + ], + ]; } /** @@ -99,7 +99,7 @@ public static function mutate_and_get_payload() { } // Check if authorized to delete this order. - if ( ! Order_Mutation::authorized( 'delete', $order_id, $input, $context, $info ) ) { + if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete', $order_id ) ) { throw new UserError( __( 'User does not have the capabilities necessary to delete an order.', 'wp-graphql-woocommerce' ) ); } @@ -154,7 +154,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_delete', $order, $input, $context, $info ); - return array( 'order' => $order ); + return [ 'order' => $order ]; }; } } diff --git a/includes/mutation/class-order-update.php b/includes/mutation/class-order-update.php index 68601fd81..bf04320ca 100644 --- a/includes/mutation/class-order-update.php +++ b/includes/mutation/class-order-update.php @@ -29,11 +29,11 @@ class Order_Update { public static function register_mutation() { register_graphql_mutation( 'updateOrder', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -45,20 +45,20 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Order_Create::get_input_fields(), - array( - 'id' => array( + [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Order global ID', 'wp-graphql-woocommerce' ), - ), - 'orderId' => array( + ], + 'orderId' => [ 'type' => 'Int', 'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ), - ), - 'customerId' => array( + ], + 'customerId' => [ 'type' => 'Int', 'description' => __( 'Order customer ID', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -68,14 +68,14 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'order' => array( + return [ + 'order' => [ 'type' => 'Order', 'resolve' => function( $payload ) { return new Order( $payload['id'] ); }, - ), - ); + ], + ]; } /** @@ -100,7 +100,7 @@ public static function mutate_and_get_payload() { } // Check if authorized to update this order. - if ( ! Order_Mutation::authorized( 'update', $order_id, $input, $context, $info ) ) { + if ( ! Order_Mutation::authorized( $input, $context, $info, 'update', $order_id ) ) { throw new UserError( __( 'User does not have the capabilities necessary to update an order.', 'wp-graphql-woocommerce' ) ); } @@ -160,7 +160,7 @@ public static function mutate_and_get_payload() { */ do_action( 'graphql_woocommerce_after_order_update', $order, $input, $context, $info ); - return array( 'id' => $order->get_id() ); + return [ 'id' => $order->get_id() ]; }; } } diff --git a/includes/mutation/class-review-delete-restore.php b/includes/mutation/class-review-delete-restore.php index 7f603b80f..6b0809f67 100644 --- a/includes/mutation/class-review-delete-restore.php +++ b/includes/mutation/class-review-delete-restore.php @@ -28,21 +28,21 @@ public static function register_mutation() { // Trash/Delete mutation. register_graphql_mutation( 'deleteReview', - array( + [ 'inputFields' => self::get_input_fields( true ), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); // Restore mutation. register_graphql_mutation( 'restoreReview', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields( true ), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -54,20 +54,20 @@ public static function register_mutation() { * @return array */ public static function get_input_fields( $delete = false ) { - $fields = array( - 'id' => array( - 'type' => array( + $fields = [ + 'id' => [ + 'type' => [ 'non_null' => 'ID', - ), + ], 'description' => __( 'The ID of the target product review', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; if ( $delete ) { - $fields['forceDelete'] = array( + $fields['forceDelete'] = [ 'type' => 'Boolean', 'description' => __( 'Whether the product review should be force deleted instead of being moved to the trash', 'wp-graphql-woocommerce' ), - ); + ]; } return $fields; @@ -81,8 +81,8 @@ public static function get_input_fields( $delete = false ) { * @return array */ public static function get_output_fields( $restore = false ) { - return array( - 'rating' => array( + return [ + 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the affected product review', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload ) { @@ -92,8 +92,8 @@ public static function get_output_fields( $restore = false ) { return floatval( $payload['rating'] ); }, - ), - 'affectedId' => array( + ], + 'affectedId' => [ 'type' => 'Id', 'description' => __( 'The affected product review ID', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload ) { @@ -101,8 +101,8 @@ public static function get_output_fields( $restore = false ) { return ! empty( $deleted->comment_ID ) ? Relay::toGlobalId( 'comment', absint( $deleted->comment_ID ) ) : null; }, - ), - 'review' => array( + ], + 'review' => [ 'type' => 'Comment', 'description' => __( 'The affected product review', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload, $args, AppContext $context, ResolveInfo $info ) use ( $restore ) { @@ -118,8 +118,8 @@ public static function get_output_fields( $restore = false ) { return $payload['commentObject']; }, - ), - ); + ], + ]; } /** diff --git a/includes/mutation/class-review-update.php b/includes/mutation/class-review-update.php index 15d411704..d24b92bde 100644 --- a/includes/mutation/class-review-update.php +++ b/includes/mutation/class-review-update.php @@ -28,11 +28,11 @@ class Review_Update { public static function register_mutation() { register_graphql_mutation( 'updateReview', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -44,12 +44,12 @@ public static function register_mutation() { public static function get_input_fields() { return array_merge( Review_Write::get_input_fields(), - array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The ID of the review being updated.', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -72,14 +72,14 @@ public static function mutate_and_get_payload() { // Set comment type to "review". $input['type'] = 'review'; - $skip = array( + $skip = [ 'type' => 'review', 'id' => 1, 'rating' => 1, 'clientMutationId' => 1, - ); + ]; - $payload = array(); + $payload = []; $id_parts = ! empty( $input['id'] ) ? Relay::fromGlobalId( $input['id'] ) : null; $payload['id'] = isset( $id_parts['id'] ) && absint( $id_parts['id'] ) ? absint( $id_parts['id'] ) : null; diff --git a/includes/mutation/class-review-write.php b/includes/mutation/class-review-write.php index 6b8af4f57..5dc870b52 100644 --- a/includes/mutation/class-review-write.php +++ b/includes/mutation/class-review-write.php @@ -29,11 +29,11 @@ class Review_Write { public static function register_mutation() { register_graphql_mutation( 'writeReview', - array( + [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), - ) + ] ); } @@ -48,12 +48,12 @@ public static function get_input_fields() { return array_merge( $comment_input_fields, - array( - 'rating' => array( - 'type' => array( 'non_null' => 'Int' ), + [ + 'rating' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Product rating', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } @@ -63,8 +63,8 @@ public static function get_input_fields() { * @return array */ public static function get_output_fields() { - return array( - 'rating' => array( + return [ + 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the review that was created', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload ) { @@ -73,8 +73,8 @@ public static function get_output_fields() { } return (float) get_comment_meta( $payload['id'], 'rating', true ); }, - ), - 'review' => array( + ], + 'review' => [ 'type' => 'Comment', 'description' => __( 'The product review that was created', 'wp-graphql-woocommerce' ), 'resolve' => function( $payload, $args, AppContext $context ) { @@ -84,8 +84,8 @@ public static function get_output_fields() { $comment = get_comment( $payload['id'] ); return new Comment( $comment ); }, - ), - ); + ], + ]; } /** diff --git a/includes/type/enum/class-backorders.php b/includes/type/enum/class-backorders.php index 3184b63ac..4b8fe80b6 100644 --- a/includes/type/enum/class-backorders.php +++ b/includes/type/enum/class-backorders.php @@ -16,18 +16,18 @@ class Backorders { * Registers type */ public static function register() { - $values = array( - 'NO' => array( 'value' => 'no' ), - 'NOTIFY' => array( 'value' => 'notify' ), - 'YES' => array( 'value' => 'yes' ), - ); + $values = [ + 'NO' => [ 'value' => 'no' ], + 'NOTIFY' => [ 'value' => 'notify' ], + 'YES' => [ 'value' => 'yes' ], + ]; register_graphql_enum_type( 'BackordersEnum', - array( + [ 'description' => __( 'Product backorder enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-cart-error-type.php b/includes/type/enum/class-cart-error-type.php index 7dc0b6868..4f0418680 100644 --- a/includes/type/enum/class-cart-error-type.php +++ b/includes/type/enum/class-cart-error-type.php @@ -16,18 +16,18 @@ class Cart_Error_Type { * Registers type */ public static function register() { - $values = array( - 'INVALID_CART_ITEM' => array( 'value' => 'INVALID_CART_ITEM' ), - 'INVALID_COUPON' => array( 'value' => 'INVALID_COUPON' ), - 'INVALID_SHIPPING_METHOD' => array( 'value' => 'INVALID_SHIPPING_METHOD' ), - ); + $values = [ + 'INVALID_CART_ITEM' => [ 'value' => 'INVALID_CART_ITEM' ], + 'INVALID_COUPON' => [ 'value' => 'INVALID_COUPON' ], + 'INVALID_SHIPPING_METHOD' => [ 'value' => 'INVALID_SHIPPING_METHOD' ], + ]; register_graphql_enum_type( 'CartErrorType', - array( + [ 'description' => __( 'Cart error type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-catalog-visibility.php b/includes/type/enum/class-catalog-visibility.php index 9556c0358..e8c0f295f 100644 --- a/includes/type/enum/class-catalog-visibility.php +++ b/includes/type/enum/class-catalog-visibility.php @@ -16,19 +16,19 @@ class Catalog_Visibility { * Registers type */ public static function register() { - $values = array( - 'VISIBLE' => array( 'value' => 'visible' ), - 'CATALOG' => array( 'value' => 'catalog' ), - 'SEARCH' => array( 'value' => 'search' ), - 'HIDDEN' => array( 'value' => 'hidden' ), - ); + $values = [ + 'VISIBLE' => [ 'value' => 'visible' ], + 'CATALOG' => [ 'value' => 'catalog' ], + 'SEARCH' => [ 'value' => 'search' ], + 'HIDDEN' => [ 'value' => 'hidden' ], + ]; register_graphql_enum_type( 'CatalogVisibilityEnum', - array( + [ 'description' => __( 'Product catalog visibility enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-countries.php b/includes/type/enum/class-countries.php index 8f0ec0e6c..d08010557 100644 --- a/includes/type/enum/class-countries.php +++ b/includes/type/enum/class-countries.php @@ -21,16 +21,16 @@ public static function register() { array_walk( $countries, function( &$value, $code ) { - $value = array( 'value' => $code ); + $value = [ 'value' => $code ]; } ); register_graphql_enum_type( 'CountriesEnum', - array( + [ 'description' => __( 'Countries enumeration', 'wp-graphql-woocommerce' ), 'values' => $countries, - ) + ] ); } } diff --git a/includes/type/enum/class-customer-connection-orderby-enum.php b/includes/type/enum/class-customer-connection-orderby-enum.php index 05aea6407..25d4b5646 100644 --- a/includes/type/enum/class-customer-connection-orderby-enum.php +++ b/includes/type/enum/class-customer-connection-orderby-enum.php @@ -18,35 +18,35 @@ class Customer_Connection_Orderby_Enum { public static function register() { register_graphql_enum_type( 'CustomerConnectionOrderbyEnum', - array( + [ 'description' => __( 'Field to order the connection by', 'wp-graphql-woocommerce' ), - 'values' => array( - 'ID' => array( + 'values' => [ + 'ID' => [ 'value' => 'ID', 'description' => __( 'Order by customer ID', 'wp-graphql-woocommerce' ), - ), - 'INCLUDE' => array( + ], + 'INCLUDE' => [ 'value' => 'include', 'description' => __( 'Order by include field', 'wp-graphql-woocommerce' ), - ), - 'NAME' => array( + ], + 'NAME' => [ 'value' => 'display_name', 'description' => __( 'Order by customer display name', 'wp-graphql-woocommerce' ), - ), - 'USERNAME' => array( + ], + 'USERNAME' => [ 'value' => 'username', 'description' => __( 'Order by customer username', 'wp-graphql-woocommerce' ), - ), - 'EMAIL' => array( + ], + 'EMAIL' => [ 'value' => 'email', 'description' => __( 'Order by customer email', 'wp-graphql-woocommerce' ), - ), - 'REGISTERED_DATE' => array( + ], + 'REGISTERED_DATE' => [ 'value' => 'registered', 'description' => __( 'Order by customer registration date', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/enum/class-discount-type.php b/includes/type/enum/class-discount-type.php index ae10d73aa..79924724f 100644 --- a/includes/type/enum/class-discount-type.php +++ b/includes/type/enum/class-discount-type.php @@ -16,17 +16,17 @@ class Discount_Type { * Registers type */ public static function register() { - $values = array(); + $values = []; foreach ( \wc_get_coupon_types() as $value => $description ) { $values[ strtoupper( $value ) ] = compact( 'value', 'description' ); } register_graphql_enum_type( 'DiscountTypeEnum', - array( + [ 'description' => __( 'Coupon discount type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-id-type-enums.php b/includes/type/enum/class-id-type-enums.php index 99acd0854..1abd91faa 100644 --- a/includes/type/enum/class-id-type-enums.php +++ b/includes/type/enum/class-id-type-enums.php @@ -22,95 +22,95 @@ class Id_Type_Enums { public static function register() { register_graphql_enum_type( 'CouponIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Coupon. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - 'code' => array( + 'code' => [ 'name' => 'CODE', 'value' => 'code', 'description' => __( 'Coupon code.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); register_graphql_enum_type( 'OrderIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Order. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - 'order_number' => array( + 'order_number' => [ 'name' => 'ORDER_NUMBER', 'value' => 'order_number', 'description' => __( 'Order number.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); register_graphql_enum_type( 'ProductIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Product. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), 'slug' => self::get_value( 'slug' ), - 'sku' => array( + 'sku' => [ 'name' => 'SKU', 'value' => 'sku', 'description' => __( 'Unique store identifier for product.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); register_graphql_enum_type( 'ProductVariationIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single ProductVariation. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ), - ) + ], + ] ); register_graphql_enum_type( 'RefundIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Refund. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ), - ) + ], + ] ); register_graphql_enum_type( 'ShippingMethodIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Shipping Method. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ), - ) + ], + ] ); register_graphql_enum_type( 'TaxRateIdTypeEnum', - array( + [ 'description' => __( 'The Type of Identifier used to fetch a single Tax rate. Default is ID.', 'wp-graphql-woocommerce' ), - 'values' => array( + 'values' => [ 'id' => self::get_value( 'id' ), 'database_id' => self::get_value( 'database_id' ), - ), - ) + ], + ] ); } @@ -123,32 +123,32 @@ public static function register() { private static function get_value( $value ) { switch ( $value ) { case 'slug': - return array( + return [ 'name' => 'SLUG', 'value' => 'slug', 'description' => __( 'Identify a resource by the slug. Available to non-hierarchcial Types where the slug is a unique identifier.', 'wp-graphql-woocommerce' ), - ); + ]; case 'id': - return array( + return [ 'name' => 'ID', 'value' => 'global_id', 'description' => __( 'Identify a resource by the (hashed) Global ID.', 'wp-graphql-woocommerce' ), - ); + ]; case 'database_id': - return array( + return [ 'name' => 'DATABASE_ID', 'value' => 'database_id', 'description' => __( 'Identify a resource by the Database ID.', 'wp-graphql-woocommerce' ), - ); + ]; case 'uri': - return array( + return [ 'name' => 'URI', 'value' => 'uri', 'description' => __( 'Identify a resource by the URI.', 'wp-graphql-woocommerce' ), - ); + ]; }//end switch } } diff --git a/includes/type/enum/class-manage-stock.php b/includes/type/enum/class-manage-stock.php index b351c2554..79b4ad6cd 100644 --- a/includes/type/enum/class-manage-stock.php +++ b/includes/type/enum/class-manage-stock.php @@ -16,18 +16,18 @@ class Manage_Stock { * Registers type */ public static function register() { - $values = array( - 'TRUE' => array( 'value' => true ), - 'FALSE' => array( 'value' => false ), - 'PARENT' => array( 'value' => 'parent' ), - ); + $values = [ + 'TRUE' => [ 'value' => true ], + 'FALSE' => [ 'value' => false ], + 'PARENT' => [ 'value' => 'parent' ], + ]; register_graphql_enum_type( 'ManageStockEnum', - array( + [ 'description' => __( 'Product manage stock enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-order-status.php b/includes/type/enum/class-order-status.php index 4fb623bda..cf9ae68eb 100644 --- a/includes/type/enum/class-order-status.php +++ b/includes/type/enum/class-order-status.php @@ -18,7 +18,7 @@ class Order_Status { public static function register() { $statuses = \wc_get_order_statuses(); - $values = array(); + $values = []; foreach ( $statuses as $status => $description ) { $split_status_slug = explode( 'wc-', $status ); $value = array_pop( $split_status_slug ); @@ -28,10 +28,10 @@ public static function register() { register_graphql_enum_type( 'OrderStatusEnum', - array( + [ 'description' => __( 'Order status enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-orders-orderby-enum.php b/includes/type/enum/class-orders-orderby-enum.php index 5a5d89ca7..e4020e62e 100644 --- a/includes/type/enum/class-orders-orderby-enum.php +++ b/includes/type/enum/class-orders-orderby-enum.php @@ -27,32 +27,32 @@ class Orders_Orderby_Enum extends Post_Type_Orderby_Enum { protected static function values() { return array_merge( self::post_type_values(), - array( - 'ORDER_KEY' => array( + [ + 'ORDER_KEY' => [ 'value' => '_order_key', 'description' => __( 'Order by order key', 'wp-graphql-woocommerce' ), - ), - 'DISCOUNT' => array( + ], + 'DISCOUNT' => [ 'value' => '_cart_discount', 'description' => __( 'Order by order discount amount', 'wp-graphql-woocommerce' ), - ), - 'TOTAL' => array( + ], + 'TOTAL' => [ 'value' => '_order_total', 'description' => __( 'Order by order total', 'wp-graphql-woocommerce' ), - ), - 'TAX' => array( + ], + 'TAX' => [ 'value' => '_order_tax', 'description' => __( 'Order by order total', 'wp-graphql-woocommerce' ), - ), - 'DATE_PAID' => array( + ], + 'DATE_PAID' => [ 'value' => '_date_paid', 'description' => __( 'Order by date the order was paid', 'wp-graphql-woocommerce' ), - ), - 'DATE_COMPLETED' => array( + ], + 'DATE_COMPLETED' => [ 'value' => '_date_completed', 'description' => __( 'Order by date the order was completed', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } } diff --git a/includes/type/enum/class-post-type-orderby-enum.php b/includes/type/enum/class-post-type-orderby-enum.php index 0100bec07..9fefcd283 100644 --- a/includes/type/enum/class-post-type-orderby-enum.php +++ b/includes/type/enum/class-post-type-orderby-enum.php @@ -26,36 +26,36 @@ class Post_Type_Orderby_Enum { * @return array */ protected static function post_type_values() { - return array( - 'SLUG' => array( + return [ + 'SLUG' => [ 'value' => 'post_name', 'description' => __( 'Order by slug', 'wp-graphql-woocommerce' ), - ), - 'MODIFIED' => array( + ], + 'MODIFIED' => [ 'value' => 'post_modified', 'description' => __( 'Order by last modified date', 'wp-graphql-woocommerce' ), - ), - 'DATE' => array( + ], + 'DATE' => [ 'value' => 'post_date', 'description' => __( 'Order by publish date', 'wp-graphql-woocommerce' ), - ), - 'PARENT' => array( + ], + 'PARENT' => [ 'value' => 'post_parent', 'description' => __( 'Order by parent ID', 'wp-graphql-woocommerce' ), - ), - 'IN' => array( + ], + 'IN' => [ 'value' => 'post__in', 'description' => __( 'Preserve the ID order given in the IN array', 'wp-graphql-woocommerce' ), - ), - 'NAME_IN' => array( + ], + 'NAME_IN' => [ 'value' => 'post_name__in', 'description' => __( 'Preserve slug order given in the NAME_IN array', 'wp-graphql-woocommerce' ), - ), - 'MENU_ORDER' => array( + ], + 'MENU_ORDER' => [ 'value' => 'menu_order', 'description' => __( 'Order by the menu order value', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; } /** @@ -74,7 +74,7 @@ public static function register() { $name = static::$name; register_graphql_enum_type( $name . 'OrderByEnum', - array( + [ 'description' => sprintf( /* translators: ordering enumeration description */ __( 'Fields to order the %s connection by', 'wp-graphql-woocommerce' ), @@ -82,7 +82,7 @@ public static function register() { ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound 'values' => apply_filters( "{$name}_orderby_enum_values", static::values() ), - ) + ] ); } } diff --git a/includes/type/enum/class-pricing-field-format.php b/includes/type/enum/class-pricing-field-format.php index 1db053cb4..321c687b3 100644 --- a/includes/type/enum/class-pricing-field-format.php +++ b/includes/type/enum/class-pricing-field-format.php @@ -16,17 +16,17 @@ class Pricing_Field_Format { * Registers type */ public static function register() { - $values = array( - 'FORMATTED' => array( 'value' => 'formatted' ), - 'RAW' => array( 'value' => 'raw' ), - ); + $values = [ + 'FORMATTED' => [ 'value' => 'formatted' ], + 'RAW' => [ 'value' => 'raw' ], + ]; register_graphql_enum_type( 'PricingFieldFormatEnum', - array( + [ 'description' => __( 'Pricing field format enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-product-attribute-types.php b/includes/type/enum/class-product-attribute-types.php index 2a25cac23..cf15a3c88 100644 --- a/includes/type/enum/class-product-attribute-types.php +++ b/includes/type/enum/class-product-attribute-types.php @@ -18,19 +18,19 @@ class Product_Attribute_Types { public static function register() { register_graphql_enum_type( 'ProductAttributeTypesEnum', - array( + [ 'description' => __( 'Product attribute type enumeration', 'wp-graphql-woocommerce' ), - 'values' => array( - 'LOCAL' => array( + 'values' => [ + 'LOCAL' => [ 'value' => 'local', 'description' => __( 'A local product attribute', 'wp-graphql-woocommerce' ), - ), - 'GLOBAL' => array( + ], + 'GLOBAL' => [ 'value' => 'global', 'description' => __( 'A global product attribute', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/enum/class-product-category-display.php b/includes/type/enum/class-product-category-display.php index 4b98ec4c6..13a35750e 100644 --- a/includes/type/enum/class-product-category-display.php +++ b/includes/type/enum/class-product-category-display.php @@ -18,27 +18,27 @@ class Product_Category_Display { public static function register() { register_graphql_enum_type( 'ProductCategoryDisplay', - array( + [ 'description' => __( 'Product category display type enumeration', 'wp-graphql-woocommerce' ), - 'values' => array( - 'DEFAULT' => array( + 'values' => [ + 'DEFAULT' => [ 'value' => 'default', 'description' => __( 'Display default content connected to this category.', 'wp-graphql-woocommerce' ), - ), - 'PRODUCTS' => array( + ], + 'PRODUCTS' => [ 'value' => 'products', 'description' => __( 'Display products associated with this category.', 'wp-graphql-woocommerce' ), - ), - 'SUBCATEGORIES' => array( + ], + 'SUBCATEGORIES' => [ 'value' => 'subcategories', 'description' => __( 'Display subcategories of this category.', 'wp-graphql-woocommerce' ), - ), - 'BOTH' => array( + ], + 'BOTH' => [ 'value' => 'both', 'description' => __( 'Display both products and subcategories of this category.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/enum/class-product-taxonomy.php b/includes/type/enum/class-product-taxonomy.php index 050d09e5c..76db80408 100644 --- a/includes/type/enum/class-product-taxonomy.php +++ b/includes/type/enum/class-product-taxonomy.php @@ -19,23 +19,23 @@ class Product_Taxonomy { */ public static function register() { // Get values from taxonomies connected to products. - $taxonomy_values = array(); + $taxonomy_values = []; $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies(); if ( ! empty( $allowed_taxonomies && is_array( $allowed_taxonomies ) ) ) { foreach ( $allowed_taxonomies as $taxonomy ) { $tax_object = get_taxonomy( $taxonomy ); if ( in_array( 'product', $tax_object->object_type, true ) ) { - $taxonomy_values[ WPEnumType::get_safe_name( $tax_object->graphql_single_name ) ] = array( 'value' => $taxonomy ); + $taxonomy_values[ WPEnumType::get_safe_name( $tax_object->graphql_single_name ) ] = [ 'value' => $taxonomy ]; } } } register_graphql_enum_type( 'ProductTaxonomyEnum', - array( + [ 'description' => __( 'Product taxonomies', 'wp-graphql-woocommerce' ), 'values' => $taxonomy_values, - ) + ] ); } } diff --git a/includes/type/enum/class-product-types.php b/includes/type/enum/class-product-types.php index d14e9eb10..e2167bc44 100644 --- a/includes/type/enum/class-product-types.php +++ b/includes/type/enum/class-product-types.php @@ -18,36 +18,36 @@ class Product_Types { public static function register() { $values = apply_filters( 'graphql_product_types_enum_values', - array( - 'SIMPLE' => array( + [ + 'SIMPLE' => [ 'value' => 'simple', 'description' => __( 'A simple product', 'wp-graphql-woocommerce' ), - ), - 'GROUPED' => array( + ], + 'GROUPED' => [ 'value' => 'grouped', 'description' => __( 'A product group', 'wp-graphql-woocommerce' ), - ), - 'EXTERNAL' => array( + ], + 'EXTERNAL' => [ 'value' => 'external', 'description' => __( 'An external product', 'wp-graphql-woocommerce' ), - ), - 'VARIABLE' => array( + ], + 'VARIABLE' => [ 'value' => 'variable', 'description' => __( 'A variable product', 'wp-graphql-woocommerce' ), - ), - 'VARIATION' => array( + ], + 'VARIATION' => [ 'value' => 'variation', 'description' => __( 'A product variation', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); register_graphql_enum_type( 'ProductTypesEnum', - array( + [ 'description' => __( 'Product type enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-products-orderby-enum.php b/includes/type/enum/class-products-orderby-enum.php index b1211fea1..f14d316e4 100644 --- a/includes/type/enum/class-products-orderby-enum.php +++ b/includes/type/enum/class-products-orderby-enum.php @@ -27,40 +27,40 @@ class Products_Orderby_Enum extends Post_Type_Orderby_Enum { protected static function values() { return array_merge( self::post_type_values(), - array( - 'PRICE' => array( + [ + 'PRICE' => [ 'value' => '_price', 'description' => __( 'Order by product\'s current price', 'wp-graphql-woocommerce' ), - ), - 'REGULAR_PRICE' => array( + ], + 'REGULAR_PRICE' => [ 'value' => '_regular_price', 'description' => __( 'Order by product\'s regular price', 'wp-graphql-woocommerce' ), - ), - 'SALE_PRICE' => array( + ], + 'SALE_PRICE' => [ 'value' => '_sale_price', 'description' => __( 'Order by product\'s sale price', 'wp-graphql-woocommerce' ), - ), - 'REVIEW_COUNT' => array( + ], + 'REVIEW_COUNT' => [ 'value' => '_wc_rating_count', 'description' => __( 'Order by number of reviews on product', 'wp-graphql-woocommerce' ), - ), - 'RATING' => array( + ], + 'RATING' => [ 'value' => '_wc_average_rating', 'description' => __( 'Order by product average rating', 'wp-graphql-woocommerce' ), - ), - 'ON_SALE_FROM' => array( + ], + 'ON_SALE_FROM' => [ 'value' => '_sale_price_dates_from', 'description' => __( 'Order by date product sale starts', 'wp-graphql-woocommerce' ), - ), - 'ON_SALE_TO' => array( + ], + 'ON_SALE_TO' => [ 'value' => '_sale_price_dates_to', 'description' => __( 'Order by date product sale ends', 'wp-graphql-woocommerce' ), - ), - 'TOTAL_SALES' => array( + ], + 'TOTAL_SALES' => [ 'value' => 'total_sales', 'description' => __( 'Order by total sales of products sold', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ); } } diff --git a/includes/type/enum/class-stock-status.php b/includes/type/enum/class-stock-status.php index dd31f15fa..fe3a3dc86 100644 --- a/includes/type/enum/class-stock-status.php +++ b/includes/type/enum/class-stock-status.php @@ -16,18 +16,18 @@ class Stock_Status { * Registers type */ public static function register() { - $values = array( - 'IN_STOCK' => array( 'value' => 'instock' ), - 'OUT_OF_STOCK' => array( 'value' => 'outofstock' ), - 'ON_BACKORDER' => array( 'value' => 'onbackorder' ), - ); + $values = [ + 'IN_STOCK' => [ 'value' => 'instock' ], + 'OUT_OF_STOCK' => [ 'value' => 'outofstock' ], + 'ON_BACKORDER' => [ 'value' => 'onbackorder' ], + ]; register_graphql_enum_type( 'StockStatusEnum', - array( + [ 'description' => __( 'Product stock status enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-tax-class.php b/includes/type/enum/class-tax-class.php index bbb75026d..d9017077c 100644 --- a/includes/type/enum/class-tax-class.php +++ b/includes/type/enum/class-tax-class.php @@ -18,28 +18,28 @@ class Tax_Class { * Registers type */ public static function register() { - $values = array( - 'INHERIT_CART' => array( + $values = [ + 'INHERIT_CART' => [ 'value' => 'inherit', 'description' => __( 'Inherits Tax class from cart', 'wp-graphql-woocommerce' ), - ), - 'STANDARD' => array( + ], + 'STANDARD' => [ 'value' => '', 'description' => __( 'Standard Tax rate', 'wp-graphql-woocommerce' ), - ), - ); + ], + ]; $classes = \WC_Tax::get_tax_classes(); foreach ( $classes as $class ) { - $values[ WPEnumType::get_safe_name( $class ) ] = array( 'value' => sanitize_title( $class ) ); + $values[ WPEnumType::get_safe_name( $class ) ] = [ 'value' => sanitize_title( $class ) ]; } register_graphql_enum_type( 'TaxClassEnum', - array( + [ 'description' => __( 'Tax class enumeration', 'wp-graphql-woocommerce' ), 'values' => $values, - ) + ] ); } } diff --git a/includes/type/enum/class-tax-rate-connection-orderby-enum.php b/includes/type/enum/class-tax-rate-connection-orderby-enum.php index 31ac433b3..e943afecf 100644 --- a/includes/type/enum/class-tax-rate-connection-orderby-enum.php +++ b/includes/type/enum/class-tax-rate-connection-orderby-enum.php @@ -18,13 +18,13 @@ class Tax_Rate_Connection_Orderby_Enum { public static function register() { register_graphql_enum_type( 'TaxRateConnectionOrderbyEnum', - array( + [ 'description' => __( 'Field to order the connection by', 'wp-graphql-woocommerce' ), - 'values' => array( - 'ID' => array( 'value' => 'id' ), - 'ORDER' => array( 'value' => 'order' ), - ), - ) + 'values' => [ + 'ID' => [ 'value' => 'id' ], + 'ORDER' => [ 'value' => 'order' ], + ], + ] ); } } diff --git a/includes/type/enum/class-tax-status.php b/includes/type/enum/class-tax-status.php index 3c312f48d..166d8bc6c 100644 --- a/includes/type/enum/class-tax-status.php +++ b/includes/type/enum/class-tax-status.php @@ -18,14 +18,14 @@ class Tax_Status { public static function register() { register_graphql_enum_type( 'TaxStatusEnum', - array( + [ 'description' => __( 'Product tax status enumeration', 'wp-graphql-woocommerce' ), - 'values' => array( - 'TAXABLE' => array( 'value' => 'taxable' ), - 'SHIPPING' => array( 'value' => 'shipping' ), - 'NONE' => array( 'value' => 'none' ), - ), - ) + 'values' => [ + 'TAXABLE' => [ 'value' => 'taxable' ], + 'SHIPPING' => [ 'value' => 'shipping' ], + 'NONE' => [ 'value' => 'none' ], + ], + ] ); } } diff --git a/includes/type/enum/class-taxonomy-operator.php b/includes/type/enum/class-taxonomy-operator.php index 68451b9a4..5c305c037 100644 --- a/includes/type/enum/class-taxonomy-operator.php +++ b/includes/type/enum/class-taxonomy-operator.php @@ -18,16 +18,16 @@ class Taxonomy_Operator { public static function register() { register_graphql_enum_type( 'TaxonomyOperatorEnum', - array( + [ 'description' => __( 'Taxonomy query operators', 'wp-graphql-woocommerce' ), - 'values' => array( - 'IN' => array( 'value' => 'IN' ), - 'NOT_IN' => array( 'value' => 'NOT IN' ), - 'AND' => array( 'value' => 'AND' ), - 'EXISTS' => array( 'value' => 'EXISTS' ), - 'NOT_EXISTS' => array( 'value' => 'NOT EXISTS' ), - ), - ) + 'values' => [ + 'IN' => [ 'value' => 'IN' ], + 'NOT_IN' => [ 'value' => 'NOT IN' ], + 'AND' => [ 'value' => 'AND' ], + 'EXISTS' => [ 'value' => 'EXISTS' ], + 'NOT_EXISTS' => [ 'value' => 'NOT EXISTS' ], + ], + ] ); } } diff --git a/includes/type/input/class-cart-item-input.php b/includes/type/input/class-cart-item-input.php index db945c097..91aaf4f20 100644 --- a/includes/type/input/class-cart-item-input.php +++ b/includes/type/input/class-cart-item-input.php @@ -19,31 +19,31 @@ class Cart_Item_Input { public static function register() { register_graphql_input_type( 'CartItemInput', - array( + [ 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'productId' => array( - 'type' => array( 'non_null' => 'Int' ), + 'fields' => [ + 'productId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - ), - 'variationId' => array( + ], + 'variationId' => [ 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - ), - 'variation' => array( - 'type' => array( 'list_of' => 'ProductAttributeInput' ), + ], + 'variation' => [ + 'type' => [ 'list_of' => 'ProductAttributeInput' ], 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - ), - 'extraData' => array( + ], + 'extraData' => [ 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-cart-item-quantity-input.php b/includes/type/input/class-cart-item-quantity-input.php index 3532cc0c7..faddda509 100644 --- a/includes/type/input/class-cart-item-quantity-input.php +++ b/includes/type/input/class-cart-item-quantity-input.php @@ -19,19 +19,19 @@ class Cart_Item_Quantity_Input { public static function register() { register_graphql_input_type( 'CartItemQuantityInput', - array( + [ 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'key' => array( - 'type' => array( 'non_null' => 'ID' ), + 'fields' => [ + 'key' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Cart item being updated', 'wp-graphql-woocommerce' ), - ), - 'quantity' => array( - 'type' => array( 'non_null' => 'Int' ), + ], + 'quantity' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item\'s new quantity', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-create-account-input.php b/includes/type/input/class-create-account-input.php index 2ff949e1d..a52272293 100644 --- a/includes/type/input/class-create-account-input.php +++ b/includes/type/input/class-create-account-input.php @@ -19,19 +19,19 @@ class Create_Account_Input { public static function register() { register_graphql_input_type( 'CreateAccountInput', - array( + [ 'description' => __( 'Customer account credentials', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'username' => array( - 'type' => array( 'non_null' => 'String' ), + 'fields' => [ + 'username' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Customer username', 'wp-graphql-woocommerce' ), - ), - 'password' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'password' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Customer password', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-customer-address-input.php b/includes/type/input/class-customer-address-input.php index 55cdf2626..4d0684307 100644 --- a/includes/type/input/class-customer-address-input.php +++ b/includes/type/input/class-customer-address-input.php @@ -19,59 +19,59 @@ class Customer_Address_Input { public static function register() { register_graphql_input_type( 'CustomerAddressInput', - array( + [ 'description' => __( 'Customer address information', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'firstName' => array( + 'fields' => [ + 'firstName' => [ 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), - ), - 'lastName' => array( + ], + 'lastName' => [ 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), - ), - 'company' => array( + ], + 'company' => [ 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), - ), - 'address1' => array( + ], + 'address1' => [ 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), - ), - 'address2' => array( + ], + 'address2' => [ 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), - ), - 'city' => array( + ], + 'city' => [ 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), - ), - 'state' => array( + ], + 'state' => [ 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), - ), - 'postcode' => array( + ], + 'postcode' => [ 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), - ), - 'country' => array( + ], + 'country' => [ 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), - ), - 'email' => array( + ], + 'email' => [ 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), - ), - 'phone' => array( + ], + 'phone' => [ 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), - ), - 'overwrite' => array( + ], + 'overwrite' => [ 'type' => 'Boolean', 'description' => __( 'Clear old address data', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-fee-line-input.php b/includes/type/input/class-fee-line-input.php index 3db122bd4..bdb868797 100644 --- a/includes/type/input/class-fee-line-input.php +++ b/includes/type/input/class-fee-line-input.php @@ -19,35 +19,35 @@ class Fee_Line_Input { public static function register() { register_graphql_input_type( 'FeeLineInput', - array( + [ 'description' => __( 'Fee line data.', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( + 'fields' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Fee Line ID', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Fee name.', 'wp-graphql-woocommerce' ), - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'String', 'description' => __( 'Fee amount.', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Tax class of fee.', 'wp-graphql-woocommerce' ), - ), - 'taxStatus' => array( + ], + 'taxStatus' => [ 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status of fee.', 'wp-graphql-woocommerce' ), - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-line-item-input.php b/includes/type/input/class-line-item-input.php index ca4146692..23e1dd787 100644 --- a/includes/type/input/class-line-item-input.php +++ b/includes/type/input/class-line-item-input.php @@ -19,51 +19,51 @@ class Line_Item_Input { public static function register() { register_graphql_input_type( 'LineItemInput', - array( + [ 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( + 'fields' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Line Item ID', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Line name', 'wp-graphql-woocommerce' ), - ), - 'productId' => array( + ], + 'productId' => [ 'type' => 'Int', 'description' => __( 'Product ID.', 'wp-graphql-woocommerce' ), - ), - 'variationId' => array( + ], + 'variationId' => [ 'type' => 'Int', 'description' => __( 'Variation ID, if applicable.', 'wp-graphql-woocommerce' ), - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Quantity ordered.', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Tax class of product.', 'wp-graphql-woocommerce' ), - ), - 'subtotal' => array( + ], + 'subtotal' => [ 'type' => 'String', 'description' => __( 'Line subtotal (before discounts).', 'wp-graphql-woocommerce' ), - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( - 'type' => array( 'list_of' => 'MetaDataInput' ), + ], + 'metaData' => [ + 'type' => [ 'list_of' => 'MetaDataInput' ], 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ), - 'sku' => array( + ], + 'sku' => [ 'type' => 'string', 'description' => __( 'Product SKU.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-meta-data-input.php b/includes/type/input/class-meta-data-input.php index 927879916..c86ed6216 100644 --- a/includes/type/input/class-meta-data-input.php +++ b/includes/type/input/class-meta-data-input.php @@ -19,23 +19,23 @@ class Meta_Data_Input { public static function register() { register_graphql_input_type( 'MetaDataInput', - array( + [ 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( + 'fields' => [ + 'id' => [ 'type' => 'String', 'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ), - ), - 'key' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'key' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ), - ), - 'value' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'value' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-orderby-inputs.php b/includes/type/input/class-orderby-inputs.php index e5eefff9c..cf6856da3 100644 --- a/includes/type/input/class-orderby-inputs.php +++ b/includes/type/input/class-orderby-inputs.php @@ -24,17 +24,17 @@ class Orderby_Inputs { public static function register_orderby_input( $base_name ) { register_graphql_input_type( $base_name . 'OrderbyInput', - array( + [ 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'field' => array( - 'type' => array( 'non_null' => $base_name . 'OrderbyEnum' ), - ), - 'order' => array( + 'fields' => [ + 'field' => [ + 'type' => [ 'non_null' => $base_name . 'OrderbyEnum' ], + ], + 'order' => [ 'type' => 'OrderEnum', - ), - ), - ) + ], + ], + ] ); } @@ -42,11 +42,11 @@ public static function register_orderby_input( $base_name ) { * Registers type */ public static function register() { - $input_types = array( + $input_types = [ 'PostType', 'Products', 'Orders', - ); + ]; foreach ( $input_types as $name ) { self::register_orderby_input( $name ); diff --git a/includes/type/input/class-product-attribute-input.php b/includes/type/input/class-product-attribute-input.php index e631311cc..595ab9581 100644 --- a/includes/type/input/class-product-attribute-input.php +++ b/includes/type/input/class-product-attribute-input.php @@ -19,17 +19,17 @@ class Product_Attribute_Input { public static function register() { register_graphql_input_type( 'ProductAttributeInput', - array( + [ 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'attributeName' => array( - 'type' => array( 'non_null' => 'String' ), - ), - 'attributeValue' => array( + 'fields' => [ + 'attributeName' => [ + 'type' => [ 'non_null' => 'String' ], + ], + 'attributeValue' => [ 'type' => 'String', - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-product-taxonomy-filter-input.php b/includes/type/input/class-product-taxonomy-filter-input.php index 264a8513c..ab2f434fa 100644 --- a/includes/type/input/class-product-taxonomy-filter-input.php +++ b/includes/type/input/class-product-taxonomy-filter-input.php @@ -19,27 +19,27 @@ class Product_Taxonomy_Filter_Input { public static function register() { register_graphql_input_type( 'ProductTaxonomyFilterInput', - array( + [ 'description' => __( 'Product filter', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'taxonomy' => array( - 'type' => array( 'non_null' => 'ProductTaxonomyEnum' ), + 'fields' => [ + 'taxonomy' => [ + 'type' => [ 'non_null' => 'ProductTaxonomyEnum' ], 'description' => __( 'Which field to select taxonomy term by.', 'wp-graphql-woocommerce' ), - ), - 'terms' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'terms' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'A list of term slugs', 'wp-graphql-woocommerce' ), - ), - 'ids' => array( - 'type' => array( 'list_of' => 'Int' ), + ], + 'ids' => [ + 'type' => [ 'list_of' => 'Int' ], 'description' => __( 'A list of term ids', 'wp-graphql-woocommerce' ), - ), - 'operator' => array( + ], + 'operator' => [ 'type' => 'TaxonomyOperatorEnum', 'description' => __( 'Filter operation type', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-product-taxonomy-input.php b/includes/type/input/class-product-taxonomy-input.php index 393847793..db23e28f5 100644 --- a/includes/type/input/class-product-taxonomy-input.php +++ b/includes/type/input/class-product-taxonomy-input.php @@ -19,19 +19,19 @@ class Product_Taxonomy_Input { public static function register() { register_graphql_input_type( 'ProductTaxonomyInput', - array( + [ 'description' => __( 'Product taxonomy filter type', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'relation' => array( + 'fields' => [ + 'relation' => [ 'type' => 'RelationEnum', 'description' => __( 'Logic relation between each filter.', 'wp-graphql-woocommerce' ), - ), - 'filters' => array( - 'type' => array( 'list_of' => 'ProductTaxonomyFilterInput' ), + ], + 'filters' => [ + 'type' => [ 'list_of' => 'ProductTaxonomyFilterInput' ], 'description' => __( 'Product taxonomy rules to be filter results by', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-shipping-line-input.php b/includes/type/input/class-shipping-line-input.php index a8e386384..17d0460fb 100644 --- a/includes/type/input/class-shipping-line-input.php +++ b/includes/type/input/class-shipping-line-input.php @@ -19,35 +19,35 @@ class Shipping_Line_Input { public static function register() { register_graphql_input_type( 'ShippingLineInput', - array( + [ 'description' => __( 'Shipping lines data.', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( + 'fields' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Shipping Line ID', 'wp-graphql-woocommerce' ), - ), - 'methodTitle' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'methodTitle' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Shipping method name.', 'wp-graphql-woocommerce' ), - ), - 'methodId' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'methodId' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Shipping method ID.', 'wp-graphql-woocommerce' ), - ), - 'instanceId' => array( + ], + 'instanceId' => [ 'type' => 'String', 'description' => __( 'Shipping instance ID.', 'wp-graphql-woocommerce' ), - ), - 'total' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'total' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Line total (after discounts).', 'wp-graphql-woocommerce' ), - ), - 'metaData' => array( - 'type' => array( 'list_of' => 'MetaDataInput' ), + ], + 'metaData' => [ + 'type' => [ 'list_of' => 'MetaDataInput' ], 'description' => __( 'Meta data.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/input/class-tax-rate-connection-orderby-input.php b/includes/type/input/class-tax-rate-connection-orderby-input.php index 600b8a030..bca4814a9 100644 --- a/includes/type/input/class-tax-rate-connection-orderby-input.php +++ b/includes/type/input/class-tax-rate-connection-orderby-input.php @@ -19,17 +19,17 @@ class Tax_Rate_Connection_Orderby_Input { public static function register() { register_graphql_input_type( 'TaxRateConnectionOrderbyInput', - array( + [ 'description' => __( 'Options for ordering the connection', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'field' => array( - 'type' => array( 'non_null' => 'TaxRateConnectionOrderbyEnum' ), - ), - 'order' => array( + 'fields' => [ + 'field' => [ + 'type' => [ 'non_null' => 'TaxRateConnectionOrderbyEnum' ], + ], + 'order' => [ 'type' => 'OrderEnum', - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/interface/class-attribute.php b/includes/type/interface/class-attribute.php index cc56c7444..bfa15ae21 100644 --- a/includes/type/interface/class-attribute.php +++ b/includes/type/interface/class-attribute.php @@ -21,24 +21,24 @@ class Attribute { public static function register_interface( &$type_registry ) { register_graphql_interface_type( 'Attribute', - array( + [ 'description' => __( 'Attribute object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'name' => array( + 'fields' => [ + 'name' => [ 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, - ), - 'value' => array( + ], + 'value' => [ 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return isset( $source['value'] ) ? $source['value'] : null; }, - ), - ), + ], + ], 'resolveType' => function( $value ) use ( &$type_registry ) { if ( $value->is_taxonomy() ) { return $type_registry->get_type( 'SimpleAttribute' ); @@ -46,7 +46,7 @@ public static function register_interface( &$type_registry ) { return $type_registry->get_type( 'VariationAttribute' ); } }, - ) + ] ); } } diff --git a/includes/type/interface/class-cart-error.php b/includes/type/interface/class-cart-error.php index bc3d75753..4a7ce47cf 100644 --- a/includes/type/interface/class-cart-error.php +++ b/includes/type/interface/class-cart-error.php @@ -21,7 +21,7 @@ class Cart_Error { public static function register_interface( &$type_registry ) { register_graphql_interface_type( 'CartError', - array( + [ 'description' => __( 'An error that occurred when updating the cart', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), 'resolveType' => function( array $value ) use ( &$type_registry ) { @@ -34,7 +34,7 @@ public static function register_interface( &$type_registry ) { return $type_registry->get_type( 'ShippingMethodError' ); } }, - ) + ] ); } @@ -44,21 +44,21 @@ public static function register_interface( &$type_registry ) { * @return array */ public static function get_fields() { - return array( - 'type' => array( - 'type' => array( 'non_null' => 'CartErrorType' ), + return [ + 'type' => [ + 'type' => [ 'non_null' => 'CartErrorType' ], 'description' => __( 'Type of error', 'wp-graphql-woocommerce' ), 'resolve' => function ( array $error ) { return ! empty( $error['type'] ) ? $error['type'] : null; }, - ), - 'reasons' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'reasons' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Reason for error', 'wp-graphql-woocommerce' ), 'resolve' => function ( $error ) { - return ! empty( $error['reasons'] ) ? $error['reasons'] : array( 'Reasons for error unknown, sorry.' ); + return ! empty( $error['reasons'] ) ? $error['reasons'] : [ 'Reasons for error unknown, sorry.' ]; }, - ), - ); + ], + ]; } } diff --git a/includes/type/interface/class-product-attribute.php b/includes/type/interface/class-product-attribute.php index 4c8ac8457..7bf488e0b 100644 --- a/includes/type/interface/class-product-attribute.php +++ b/includes/type/interface/class-product-attribute.php @@ -21,7 +21,7 @@ class Product_Attribute { public static function register_interface( &$type_registry ) { register_graphql_interface_type( 'ProductAttribute', - array( + [ 'description' => __( 'Product attribute object', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), 'resolveType' => function( $value ) use ( &$type_registry ) { @@ -31,7 +31,7 @@ public static function register_interface( &$type_registry ) { return $type_registry->get_type( 'LocalProductAttribute' ); } }, - ) + ] ); } @@ -41,71 +41,71 @@ public static function register_interface( &$type_registry ) { * @return array */ public static function get_fields() { - return array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + return [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Attribute Global ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! empty( $attribute->_relay_id ) ? $attribute->_relay_id : null; }, - ), - 'attributeId' => array( - 'type' => array( 'non_null' => 'Int' ), + ], + 'attributeId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Attribute ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! is_null( $attribute->get_id() ) ? $attribute->get_id() : null; }, - ), - 'name' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'name' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Attribute name', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, - ), - 'label' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'label' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! empty( $attribute->get_name() ) ? ucwords( $attribute->get_name() ) : null; }, - ), - 'options' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'options' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Attribute options', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { $slugs = $attribute->get_slugs(); return ! empty( $slugs ) ? $slugs : null; }, - ), - 'position' => array( - 'type' => array( 'non_null' => 'Int' ), + ], + 'position' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Attribute position', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! is_null( $attribute->get_position() ) ? $attribute->get_position() : null; }, - ), - 'visible' => array( - 'type' => array( 'non_null' => 'Boolean' ), + ], + 'visible' => [ + 'type' => [ 'non_null' => 'Boolean' ], 'description' => __( 'Is attribute visible', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! is_null( $attribute->get_visible() ) ? $attribute->get_visible() : null; }, - ), - 'variation' => array( - 'type' => array( 'non_null' => 'Boolean' ), + ], + 'variation' => [ + 'type' => [ 'non_null' => 'Boolean' ], 'description' => __( 'Is attribute on product variation', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! is_null( $attribute->get_variation() ) ? $attribute->get_variation() : null; }, - ), - 'scope' => array( - 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), + ], + 'scope' => [ + 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => 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 c9ff0dec0..5ab0b76cb 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -15,7 +15,7 @@ use WPGraphQL\AppContext; use WPGraphQL\Data\DataSource; use WPGraphQL\WooCommerce\Data\Factory; -use WP_GraphQL_WooCommerce; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; /** * Class - Product @@ -30,7 +30,7 @@ class Product { public static function register_interface( &$type_registry ) { register_graphql_interface_type( 'Product', - array( + [ 'description' => __( 'Product object', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), 'resolveType' => function( $value ) use ( &$type_registry ) { @@ -46,27 +46,27 @@ public static function register_interface( &$type_registry ) { ) ); }, - ) + ] ); register_graphql_field( 'RootQuery', 'product', - array( + [ 'type' => 'Product', 'description' => __( 'A product object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'args' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The ID for identifying the product', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'ProductIdTypeEnum', 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { - $id = isset( $args['id'] ) ? $args['id'] : null; + $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; $product_id = null; @@ -101,7 +101,7 @@ public static function register_interface( &$type_registry ) { return Factory::resolve_crud_object( $product_id, $context ); }, - ) + ] ); } @@ -111,56 +111,56 @@ public static function register_interface( &$type_registry ) { * @return array */ public static function get_fields() { - return array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + return [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the product', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( - 'type' => array( 'non_null' => 'Int' ), + ], + 'databaseId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'The ID of the product in the database', 'wp-graphql-woocommerce' ), - ), - 'slug' => array( + ], + 'slug' => [ 'type' => 'String', 'description' => __( 'Product slug', 'wp-graphql-woocommerce' ), - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'Date product created', 'wp-graphql-woocommerce' ), - ), - 'modified' => array( + ], + 'modified' => [ 'type' => 'String', 'description' => __( 'Date product last updated', 'wp-graphql-woocommerce' ), - ), - 'type' => array( + ], + 'type' => [ 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Product name', 'wp-graphql-woocommerce' ), - ), - 'status' => array( + ], + 'status' => [ 'type' => 'String', 'description' => __( 'Product status', 'wp-graphql-woocommerce' ), - ), - 'featured' => array( + ], + 'featured' => [ 'type' => 'Boolean', 'description' => __( 'If the product is featured', 'wp-graphql-woocommerce' ), - ), - 'catalogVisibility' => array( + ], + 'catalogVisibility' => [ 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Catalog visibility', 'wp-graphql-woocommerce' ), - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Product description', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PostObjectFieldFormatEnum', 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -168,16 +168,16 @@ public static function get_fields() { } return $source->description; }, - ), - 'shortDescription' => array( + ], + 'shortDescription' => [ 'type' => 'String', 'description' => __( 'Product short description', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PostObjectFieldFormatEnum', 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -186,51 +186,51 @@ public static function get_fields() { // @codingStandardsIgnoreLine. return $source->shortDescription; }, - ), - 'sku' => array( + ], + 'sku' => [ 'type' => 'String', 'description' => __( 'Product SKU', 'wp-graphql-woocommerce' ), - ), - 'dateOnSaleFrom' => array( + ], + 'dateOnSaleFrom' => [ 'type' => 'String', 'description' => __( 'Date on sale from', 'wp-graphql-woocommerce' ), - ), - 'dateOnSaleTo' => array( + ], + 'dateOnSaleTo' => [ 'type' => 'String', 'description' => __( 'Date on sale to', 'wp-graphql-woocommerce' ), - ), - 'totalSales' => array( + ], + 'totalSales' => [ 'type' => 'Int', 'description' => __( 'Number total of sales', 'wp-graphql-woocommerce' ), - ), - 'reviewsAllowed' => array( + ], + 'reviewsAllowed' => [ 'type' => 'Boolean', 'description' => __( 'If reviews are allowed', 'wp-graphql-woocommerce' ), - ), - 'purchaseNote' => array( + ], + 'purchaseNote' => [ 'type' => 'String', 'description' => __( 'Purchase note', 'wp-graphql-woocommerce' ), - ), - 'menuOrder' => array( + ], + 'menuOrder' => [ 'type' => 'Int', 'description' => __( 'Menu order', 'wp-graphql-woocommerce' ), - ), - 'averageRating' => array( + ], + 'averageRating' => [ 'type' => 'Float', 'description' => __( 'Product average count', 'wp-graphql-woocommerce' ), - ), - 'reviewCount' => array( + ], + 'reviewCount' => [ 'type' => 'Int', 'description' => __( 'Product review count', 'wp-graphql-woocommerce' ), - ), - 'parent' => array( + ], + 'parent' => [ 'type' => 'Product', 'description' => __( 'Parent product', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->parent_id, $context ); }, - ), - 'image' => array( + ], + 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Main image', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { @@ -240,24 +240,24 @@ public static function get_fields() { } return DataSource::resolve_post_object( $source->image_id, $context ); }, - ), - 'onSale' => array( + ], + 'onSale' => [ 'type' => 'Boolean', 'description' => __( 'Is product on sale?', 'wp-graphql-woocommerce' ), - ), - 'purchasable' => array( + ], + 'purchasable' => [ 'type' => 'Boolean', 'description' => __( 'Can product be purchased?', 'wp-graphql-woocommerce' ), - ), - 'link' => array( + ], + 'link' => [ 'type' => 'String', 'description' => __( 'The permalink of the post', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $permalink = get_post_permalink( $source->ID ); return ! empty( $permalink ) ? $permalink : null; }, - ), + ], 'metaData' => \WPGraphQL\WooCommerce\Type\WPObject\Meta_Data_Type::get_metadata_field_definition(), - ); + ]; } } diff --git a/includes/type/object/class-cart-error-types.php b/includes/type/object/class-cart-error-types.php index d5bc6ee1e..860317664 100644 --- a/includes/type/object/class-cart-error-types.php +++ b/includes/type/object/class-cart-error-types.php @@ -19,88 +19,88 @@ class Cart_Error_Types { public static function register() { register_graphql_object_type( 'CartItemError', - array( + [ 'description' => __( 'Error that occurred when adding an item to the cart.', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'CartError' ), - 'fields' => array( - 'productId' => array( - 'type' => array( 'non_null' => 'Int' ), + 'interfaces' => [ 'CartError' ], + 'fields' => [ + 'productId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['productId'] ) ? $error['productId'] : null; }, - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['quantity'] ) ? $error['quantity'] : null; }, - ), - 'variationId' => array( + ], + 'variationId' => [ 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['variationId'] ) ? $error['variationId'] : null; }, - ), - 'variation' => array( - 'type' => array( 'list_of' => 'ProductAttributeOutput' ), + ], + 'variation' => [ + 'type' => [ 'list_of' => 'ProductAttributeOutput' ], 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['variation'] ) ? $error['variation'] : null; }, - ), - 'extraData' => array( + ], + 'extraData' => [ 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['extraData'] ) ? $error['extraData'] : null; }, - ), - ), - ) + ], + ], + ] ); register_graphql_object_type( 'CouponError', - array( + [ 'description' => __( 'Error that occurred when applying a coupon to the cart.', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'CartError' ), - 'fields' => array( - 'code' => array( - 'type' => array( 'non_null' => 'String' ), + 'interfaces' => [ 'CartError' ], + 'fields' => [ + 'code' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code of the coupon the failed to be applied', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return ! empty( $error['code'] ) ? $error['code'] : null; }, - ), - ), - ) + ], + ], + ] ); register_graphql_object_type( 'ShippingMethodError', - array( + [ 'description' => __( 'Error that occurred when setting the chosen shipping method for the eventually order.', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'CartError' ), - 'fields' => array( - 'package' => array( - 'type' => array( 'non_null' => 'Integer' ), + 'interfaces' => [ 'CartError' ], + 'fields' => [ + 'package' => [ + 'type' => [ 'non_null' => 'Integer' ], 'description' => __( 'Index of package for desired shipping method', 'wp-graphql-woocommerce' ), 'resolve' => function( array $error ) { return isset( $error['package'] ) && is_int( $error['package'] ) ? $error['package'] : null; }, - ), - 'chosenMethod' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'chosenMethod' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'ID of chosen shipping rate', 'wp-graphql-woocommerce' ), 'resolve' => 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 4bfcfa3cd..3b0a3366a 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -40,68 +40,68 @@ public static function register() { public static function register_cart() { register_graphql_object_type( 'Cart', - array( + [ 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'subtotal' => array( + 'fields' => [ + 'subtotal' => [ 'type' => 'String', 'description' => __( 'Cart subtotal', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_subtotal() ) ? $source->get_subtotal() : 0; return \wc_graphql_price( $price ); }, - ), - 'subtotalTax' => array( + ], + 'subtotalTax' => [ 'type' => 'String', 'description' => __( 'Cart subtotal tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_subtotal_tax() ) ? $source->get_subtotal_tax() : 0; return \wc_graphql_price( $price ); }, - ), - 'discountTotal' => array( + ], + 'discountTotal' => [ 'type' => 'String', 'description' => __( 'Cart discount total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_discount_total() ) ? $source->get_discount_total() : 0; return \wc_graphql_price( $price ); }, - ), - 'discountTax' => array( + ], + 'discountTax' => [ 'type' => 'String', 'description' => __( 'Cart discount tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_discount_tax() ) ? $source->get_discount_tax() : 0; return \wc_graphql_price( $price ); }, - ), - 'availableShippingMethods' => array( - 'type' => array( 'list_of' => 'ShippingPackage' ), + ], + 'availableShippingMethods' => [ + 'type' => [ 'list_of' => 'ShippingPackage' ], 'description' => __( 'Available shipping methods for this order.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $packages = array(); + $packages = []; $available_packages = $source->needs_shipping() ? \WC()->shipping()->calculate_shipping( $source->get_shipping_packages() ) - : array(); + : []; foreach ( $available_packages as $index => $package ) { $package['index'] = $index; - $packages[] = $package; + $packages[] = $package; } return $packages; }, - ), - 'chosenShippingMethods' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'chosenShippingMethods' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Shipping method chosen for this order.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $chosen_shipping_methods = array(); + $chosen_shipping_methods = []; $available_packages = $source->needs_shipping() ? \WC()->shipping()->calculate_shipping( $source->get_shipping_packages() ) - : array(); + : []; foreach ( $available_packages as $i => $package ) { if ( isset( \WC()->session->chosen_shipping_methods[ $i ] ) ) { @@ -111,24 +111,24 @@ public static function register_cart() { return $chosen_shipping_methods; }, - ), - 'shippingTotal' => array( + ], + 'shippingTotal' => [ 'type' => 'String', 'description' => __( 'Cart shipping total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_shipping_total() ) ? $source->get_shipping_total() : 0; return \wc_graphql_price( $price ); }, - ), - 'shippingTax' => array( + ], + 'shippingTax' => [ 'type' => 'String', 'description' => __( 'Cart shipping tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_shipping_tax() ) ? $source->get_shipping_tax() : 0; return \wc_graphql_price( $price ); }, - ), - 'contentsTotal' => array( + ], + 'contentsTotal' => [ 'type' => 'String', 'description' => __( 'Cart contents total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -143,8 +143,8 @@ public static function register_cart() { : 0; return \wc_graphql_price( $price ); }, - ), - 'contentsTax' => array( + ], + 'contentsTax' => [ 'type' => 'String', 'description' => __( 'Cart contents tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -153,24 +153,24 @@ public static function register_cart() { : 0; return \wc_graphql_price( $price ); }, - ), - 'feeTotal' => array( + ], + 'feeTotal' => [ 'type' => 'String', 'description' => __( 'Cart fee total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_fee_total() ) ? $source->get_fee_total() : 0; return \wc_graphql_price( $price ); }, - ), - 'feeTax' => array( + ], + 'feeTax' => [ 'type' => 'String', 'description' => __( 'Cart fee tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_fee_tax() ) ? $source->get_fee_tax() : 0; return \wc_graphql_price( $price ); }, - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Cart total after calculation', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -180,31 +180,31 @@ public static function register_cart() { : null; return \wc_graphql_price( $price ); }, - ), - 'totalTax' => array( + ], + 'totalTax' => [ 'type' => 'String', 'description' => __( 'Cart total tax amount', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = ! is_null( $source->get_total_tax() ) ? $source->get_total_tax() : 0; return \wc_graphql_price( $price ); }, - ), - 'totalTaxes' => array( - 'type' => array( 'list_of' => 'CartTax' ), + ], + 'totalTaxes' => [ + 'type' => [ 'list_of' => 'CartTax' ], 'description' => __( 'Cart total taxes itemized', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $taxes = $source->get_tax_totals(); return ! empty( $taxes ) ? array_values( $taxes ) : null; }, - ), - 'isEmpty' => array( + ], + 'isEmpty' => [ 'type' => 'Boolean', 'description' => __( 'Is cart empty', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! is_null( $source->is_empty() ) ? $source->is_empty() : null; }, - ), - 'displayPricesIncludeTax' => array( + ], + 'displayPricesIncludeTax' => [ 'type' => 'Boolean', 'description' => __( 'Do display prices include taxes', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -212,8 +212,8 @@ public static function register_cart() { ? $source->display_prices_including_tax() : null; }, - ), - 'needsShippingAddress' => array( + ], + 'needsShippingAddress' => [ 'type' => 'Boolean', 'description' => __( 'Is customer shipping address needed', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -221,36 +221,36 @@ public static function register_cart() { ? $source->needs_shipping_address() : null; }, - ), - 'fees' => array( - 'type' => array( 'list_of' => 'CartFee' ), + ], + 'fees' => [ + 'type' => [ 'list_of' => 'CartFee' ], 'description' => __( 'Additional fees on the cart.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $fees = $source->get_fees(); return ! empty( $fees ) ? array_values( $fees ) : null; }, - ), - 'appliedCoupons' => array( - 'type' => array( 'list_of' => 'AppliedCoupon' ), + ], + 'appliedCoupons' => [ + 'type' => [ 'list_of' => 'AppliedCoupon' ], 'description' => __( 'Coupons applied to the cart', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $applied_coupons = $source->get_applied_coupons(); return ! empty( $applied_coupons ) ? $applied_coupons : null; }, - ), - ), - 'connections' => array( - 'contents' => array( + ], + ], + 'connections' => [ + 'contents' => [ 'toType' => 'CartItem', - 'connectionArgs' => array( - 'needsShipping' => array( + 'connectionArgs' => [ + 'needsShipping' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to cart items that require shipping', 'wp-graphql-woocommerce' ), - ), - ), - 'connectionFields' => array( - 'itemCount' => array( + ], + ], + 'connectionFields' => [ + 'itemCount' => [ 'type' => 'Int', 'description' => __( 'Total number of items in the cart.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -265,8 +265,8 @@ public static function register_cart() { return array_sum( array_column( $items, 'quantity' ) ); }, - ), - 'productCount' => array( + ], + 'productCount' => [ 'type' => 'Int', 'description' => __( 'Total number of different products in the cart', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -276,16 +276,16 @@ public static function register_cart() { return count( array_values( $source['edges'][0]['source']->get_cart() ) ); }, - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Cart_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ), - ), - ) + ], + ], + ] ); } @@ -295,77 +295,77 @@ public static function register_cart() { public static function register_cart_item() { register_graphql_object_type( 'CartItem', - array( + [ 'description' => __( 'A item in the cart', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'key' => array( - 'type' => array( 'non_null' => 'ID' ), + 'fields' => [ + 'key' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'CartItem ID', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['key'] ) ? $source['key'] : null; }, - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Quantity of the product', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return isset( $source['quantity'] ) ? absint( $source['quantity'] ) : null; }, - ), - 'subtotal' => array( + ], + 'subtotal' => [ 'type' => 'String', 'description' => __( 'Item\'s subtotal', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = isset( $source['line_subtotal'] ) ? floatval( $source['line_subtotal'] ) : 0; return \wc_graphql_price( $price ); }, - ), - 'subtotalTax' => array( + ], + 'subtotalTax' => [ 'type' => 'String', 'description' => __( 'Item\'s subtotal tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = isset( $source['line_subtotal_tax'] ) ? floatval( $source['line_subtotal_tax'] ) : 0; return \wc_graphql_price( $price ); }, - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Item\'s total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : null; - $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : null; - $price = $price_without_tax + $tax; + $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : null; + $price = $price_without_tax + $tax; return \wc_graphql_price( $price ); }, - ), - 'tax' => array( + ], + 'tax' => [ 'type' => 'String', 'description' => __( 'Item\'s tax', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $price = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : null; return \wc_graphql_price( $price ); }, - ), - 'extraData' => array( - 'type' => array( 'list_of' => 'MetaData' ), + ], + 'extraData' => [ + 'type' => [ 'list_of' => 'MetaData' ], 'description' => __( 'Object meta data', 'wp-graphql-woocommerce' ), - 'args' => array( - 'key' => array( + 'args' => [ + 'key' => [ 'type' => 'String', 'description' => __( 'Retrieve meta by key', 'wp-graphql-woocommerce' ), - ), - 'keysIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'keysIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, array $args ) { // Check if "key" argument set and assigns to target "keys" array. if ( ! empty( $args['key'] ) && ! empty( $source[ $args['key'] ] ) ) { - $keys = array( $args['key'] ); + $keys = [ $args['key'] ]; } elseif ( ! empty( $args['keysIn'] ) ) { // Check if "keysIn" argument set and assigns to target "keys" array. - $keys = array(); + $keys = []; foreach ( $args['keysIn'] as $key ) { if ( ! empty( $source[ $key ] ) ) { $keys[] = $key; @@ -375,7 +375,7 @@ public static function register_cart_item() { // If no arguments set, all extra data keys are assigns to target "keys" array. $keys = array_diff( array_keys( $source ), - array( + [ 'key', 'product_id', 'variation_id', @@ -388,36 +388,36 @@ public static function register_cart_item() { 'line_subtotal_tax', 'line_total', 'line_tax', - ) + ] ); }//end if // Create meta ID prefix. $id_prefix = apply_filters( 'graphql_woocommerce_cart_meta_id_prefix', 'cart_' ); // Format meta data for resolution. - $data = array(); + $data = []; foreach ( $keys as $key ) { - $data[] = (object) array( + $data[] = (object) [ 'id' => "{$id_prefix}_{$key}", 'key' => $key, 'value' => is_array( $source[ $key ] ) ? wp_json_encode( $source[ $key ] ) : $source[ $key ], - ); + ]; } return $data; }, - ), - ), - 'connections' => array( - 'product' => array( + ], + ], + 'connections' => [ + 'product' => [ 'toType' => 'Product', 'oneToOne' => true, - 'edgeFields' => array( - 'simpleVariations' => array( - 'type' => array( 'list_of' => 'SimpleAttribute' ), + 'edgeFields' => [ + 'simpleVariations' => [ + 'type' => [ 'list_of' => 'SimpleAttribute' ], 'description' => __( 'Simple variation attribute data', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $attributes = array(); + $attributes = []; $variation = $source['node']; $cart_item_data = $source['source']; @@ -428,8 +428,8 @@ public static function register_cart_item() { return $attributes; }, - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = $source['product_id']; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); @@ -439,16 +439,16 @@ public static function register_cart_item() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ), - 'variation' => array( + ], + 'variation' => [ 'toType' => 'ProductVariation', 'oneToOne' => true, - 'edgeFields' => array( - 'attributes' => array( - 'type' => array( 'list_of' => 'VariationAttribute' ), + 'edgeFields' => [ + 'attributes' => [ + 'type' => [ 'list_of' => 'VariationAttribute' ], 'description' => __( 'Attributes of the variation.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $attributes = array(); + $attributes = []; $variation = $source['node']; $cart_item_data = $source['source']; @@ -463,8 +463,8 @@ public static function register_cart_item() { return Variation_Attribute_Connection_Resolver::to_data_array( $attributes, $variation->ID ); }, - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $id = $source['variation_id']; $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); @@ -478,9 +478,9 @@ public static function register_cart_item() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ), - ), - ) + ], + ], + ] ); } @@ -490,53 +490,53 @@ public static function register_cart_item() { public static function register_cart_fee() { register_graphql_object_type( 'CartFee', - array( + [ 'description' => __( 'An additional fee', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Fee ID', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ), - 'name' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'name' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->name ) ? $source->name : null; }, - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Fee tax class', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->tax_class ) ? $source->tax_class : null; }, - ), - 'taxable' => array( + ], + 'taxable' => [ 'type' => 'Boolean', 'description' => __( 'Is fee taxable?', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! is_null( $source->taxable ) ? $source->taxable : null; }, - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! is_null( $source->amount ) ? $source->amount : 0; }, - ), - 'total' => array( + ], + 'total' => [ 'type' => 'Float', 'description' => __( 'Fee total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! is_null( $source->total ) ? $source->total : 0; }, - ), - ), - ) + ], + ], + ] ); } /** @@ -545,39 +545,39 @@ public static function register_cart_fee() { public static function register_cart_tax() { register_graphql_object_type( 'CartTax', - array( + [ 'description' => __( 'An itemized cart tax item', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Tax Rate ID', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->tax_rate_id ) ? $source->tax_rate_id : null; }, - ), - 'label' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'label' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Tax label', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->label ) ? $source->label : null; }, - ), - 'isCompound' => array( + ], + 'isCompound' => [ 'type' => 'Boolean', 'description' => __( 'Is tax compound?', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->is_compound ) ? $source->is_compound : null; }, - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'String', 'description' => __( 'Tax amount', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->amount ) ? \wc_graphql_price( $source->amount ) : null; }, - ), - ), - ) + ], + ], + ] ); } @@ -587,49 +587,49 @@ public static function register_cart_tax() { public static function register_applied_coupon() { register_graphql_object_type( 'AppliedCoupon', - array( + [ 'description' => __( 'Coupon applied to the shopping cart.', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'code' => array( - 'type' => array( 'non_null' => 'String' ), + 'fields' => [ + 'code' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return $source; }, - ), - 'discountAmount' => array( - 'type' => array( 'non_null' => 'String' ), - 'args' => array( - 'excludeTax' => array( + ], + 'discountAmount' => [ + 'type' => [ 'non_null' => 'String' ], + 'args' => [ + 'excludeTax' => [ 'type' => 'Boolean', 'description' => __( 'Exclude Taxes (Default "true")', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'description' => __( 'Discount applied with this coupon', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args ) { $ex_tax = ! empty( $args['excludeTax'] ) ? $args['excludeTax'] : true; $amount = Factory::resolve_cart()->get_coupon_discount_amount( $source, $ex_tax ); return \wc_graphql_price( $amount ); }, - ), - 'discountTax' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'discountTax' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Taxes on discount applied with this coupon', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args ) { $tax = Factory::resolve_cart()->get_coupon_discount_tax_amount( $source ); return \wc_graphql_price( $tax ); }, - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Description of applied coupon', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args ) { $coupon = new \WC_Coupon( $source ); return $coupon->get_description(); }, - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-coupon-type.php b/includes/type/object/class-coupon-type.php index 7781a038c..affd58a49 100644 --- a/includes/type/object/class-coupon-type.php +++ b/includes/type/object/class-coupon-type.php @@ -26,89 +26,89 @@ class Coupon_Type { public static function register() { register_graphql_object_type( 'Coupon', - array( + [ 'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Node' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Node' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the coupon', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( + ], + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the coupon in the database', 'wp-graphql-woocommerce' ), - ), - 'code' => array( + ], + 'code' => [ 'type' => 'String', 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'Date coupon created', 'wp-graphql-woocommerce' ), - ), - 'modified' => array( + ], + 'modified' => [ 'type' => 'String', 'description' => __( 'Date coupon modified', 'wp-graphql-woocommerce' ), - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Explanation of what the coupon does', 'wp-graphql-woocommerce' ), - ), - 'discountType' => array( + ], + 'discountType' => [ 'type' => 'DiscountTypeEnum', 'description' => __( 'Type of discount', 'wp-graphql-woocommerce' ), - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'Amount off provided by the coupon', 'wp-graphql-woocommerce' ), - ), - 'dateExpiry' => array( + ], + 'dateExpiry' => [ 'type' => 'String', 'description' => __( 'Date coupon expires', 'wp-graphql-woocommerce' ), - ), - 'usageCount' => array( + ], + 'usageCount' => [ 'type' => 'Int', 'description' => __( 'How many times the coupon has been used', 'wp-graphql-woocommerce' ), - ), - 'individualUse' => array( + ], + 'individualUse' => [ 'type' => 'Boolean', 'description' => __( 'Individual use means this coupon cannot be used in conjunction with other coupons', 'wp-graphql-woocommerce' ), - ), - 'usageLimit' => array( + ], + 'usageLimit' => [ 'type' => 'Int', 'description' => __( 'Amount of times this coupon can be used globally', 'wp-graphql-woocommerce' ), - ), - 'usageLimitPerUser' => array( + ], + 'usageLimitPerUser' => [ 'type' => 'Int', 'description' => __( 'Amount of times this coupon can be used by a customer', 'wp-graphql-woocommerce' ), - ), - 'limitUsageToXItems' => array( + ], + 'limitUsageToXItems' => [ 'type' => 'Int', 'description' => __( 'The number of products in your cart this coupon can apply to (for product discounts)', 'wp-graphql-woocommerce' ), - ), - 'freeShipping' => array( + ], + 'freeShipping' => [ 'type' => 'Boolean', 'description' => __( 'Does this coupon grant free shipping?', 'wp-graphql-woocommerce' ), - ), - 'excludeSaleItems' => array( + ], + 'excludeSaleItems' => [ 'type' => 'Boolean', 'description' => __( 'Excluding sale items mean this coupon cannot be used on items that are on sale (or carts that contain on sale items)', 'wp-graphql-woocommerce' ), - ), - 'minimumAmount' => array( + ], + 'minimumAmount' => [ 'type' => 'Float', 'description' => __( 'Minimum spend amount that must be met before this coupon can be used', 'wp-graphql-woocommerce' ), - ), - 'maximumAmount' => array( + ], + 'maximumAmount' => [ 'type' => 'Float', 'description' => __( 'Maximum spend amount that must be met before this coupon can be used ', 'wp-graphql-woocommerce' ), - ), - 'emailRestrictions' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'emailRestrictions' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Only customers with a matching email address can use the coupon', 'wp-graphql-woocommerce' ), - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), - ) + ], + ] ); } } diff --git a/includes/type/object/class-customer-address-type.php b/includes/type/object/class-customer-address-type.php index affc28db3..b68963b95 100644 --- a/includes/type/object/class-customer-address-type.php +++ b/includes/type/object/class-customer-address-type.php @@ -21,88 +21,88 @@ class Customer_Address_Type { public static function register() { register_graphql_object_type( 'CustomerAddress', - array( + [ 'description' => __( 'A customer address object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'firstName' => array( + 'fields' => [ + 'firstName' => [ 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['first_name'] ) ? $address['first_name'] : null; }, - ), - 'lastName' => array( + ], + 'lastName' => [ 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['last_name'] ) ? $address['last_name'] : null; }, - ), - 'company' => array( + ], + 'company' => [ 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['company'] ) ? $address['company'] : null; }, - ), - 'address1' => array( + ], + 'address1' => [ 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['address_1'] ) ? $address['address_1'] : null; }, - ), - 'address2' => array( + ], + 'address2' => [ 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['address_2'] ) ? $address['address_2'] : null; }, - ), - 'city' => array( + ], + 'city' => [ 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['city'] ) ? $address['city'] : null; }, - ), - 'state' => array( + ], + 'state' => [ 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['state'] ) ? $address['state'] : null; }, - ), - 'postcode' => array( + ], + 'postcode' => [ 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['postcode'] ) ? $address['postcode'] : null; }, - ), - 'country' => array( + ], + 'country' => [ 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['country'] ) ? $address['country'] : null; }, - ), - 'email' => array( + ], + 'email' => [ 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), 'resolve' => function( $address ) { return ! empty( $address['email'] ) ? $address['email'] : null; }, - ), - 'phone' => array( + ], + 'phone' => [ 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), 'resolve' => 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 bed452f50..9b19107f0 100644 --- a/includes/type/object/class-customer-type.php +++ b/includes/type/object/class-customer-type.php @@ -28,90 +28,90 @@ class Customer_Type { public static function register() { register_graphql_object_type( 'Customer', - array( + [ 'description' => __( 'A customer object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Node' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Node' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the customer', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( + ], + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - ), - 'isVatExempt' => array( + ], + 'isVatExempt' => [ 'type' => 'Boolean', 'description' => __( 'Is customer VAT exempt?', 'wp-graphql-woocommerce' ), - ), - 'hasCalculatedShipping' => array( + ], + 'hasCalculatedShipping' => [ 'type' => 'Boolean', 'description' => __( 'Has calculated shipping?', 'wp-graphql-woocommerce' ), - ), - 'calculatedShipping' => array( + ], + 'calculatedShipping' => [ 'type' => 'Boolean', 'description' => __( 'Has customer calculated shipping?', 'wp-graphql-woocommerce' ), - ), - 'lastOrder' => array( + ], + 'lastOrder' => [ 'type' => 'Order', 'description' => __( 'Gets the customers last order.', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->last_order_id, $context ); }, - ), - 'orderCount' => array( + ], + 'orderCount' => [ 'type' => 'Int', 'description' => __( 'Return the number of orders this customer has.', 'wp-graphql-woocommerce' ), - ), - 'totalSpent' => array( + ], + 'totalSpent' => [ 'type' => 'Float', 'description' => __( 'Return how much money this customer has spent.', 'wp-graphql-woocommerce' ), - ), - 'username' => array( + ], + 'username' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s username.', 'wp-graphql-woocommerce' ), - ), - 'email' => array( + ], + 'email' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s email.', 'wp-graphql-woocommerce' ), - ), - 'firstName' => array( + ], + 'firstName' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s first name.', 'wp-graphql-woocommerce' ), - ), - 'lastName' => array( + ], + 'lastName' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s last name.', 'wp-graphql-woocommerce' ), - ), - 'displayName' => array( + ], + 'displayName' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s display name.', 'wp-graphql-woocommerce' ), - ), - 'role' => array( + ], + 'role' => [ 'type' => 'String', 'description' => __( 'Return the customer\'s user role.', 'wp-graphql-woocommerce' ), - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'Return the date customer was created', 'wp-graphql-woocommerce' ), - ), - 'modified' => array( + ], + 'modified' => [ 'type' => 'String', 'description' => __( 'Return the date customer was last updated', 'wp-graphql-woocommerce' ), - ), - 'billing' => array( + ], + 'billing' => [ 'type' => 'CustomerAddress', 'description' => __( 'Return the date customer billing address properties', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddress', 'description' => __( 'Return the date customer shipping address properties', 'wp-graphql-woocommerce' ), - ), - 'isPayingCustomer' => array( + ], + 'isPayingCustomer' => [ 'type' => 'Boolean', 'description' => __( 'Return the date customer was last updated', 'wp-graphql-woocommerce' ), - ), - 'sessionToken' => array( + ], + 'sessionToken' => [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -120,35 +120,35 @@ public static function register() { } return null; }, - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), - 'connections' => array( - 'downloadableItems' => array( + ], + 'connections' => [ + 'downloadableItems' => [ 'toType' => 'DownloadableItem', - 'connectionArgs' => array( - 'active' => array( + 'connectionArgs' => [ + 'active' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that can be downloaded now.', 'wp-graphql-woocommerce' ), - ), - 'expired' => array( + ], + 'expired' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that are expired.', 'wp-graphql-woocommerce' ), - ), - 'hasDownloadsRemaining' => array( + ], + 'hasDownloadsRemaining' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Downloadable_Item_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); }, - ), - ), - ) + ], + ], + ] ); /** @@ -157,7 +157,7 @@ public static function register() { register_graphql_field( 'User', 'wooSessionToken', - array( + [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -167,7 +167,7 @@ public static function register() { return null; }, - ) + ] ); } } diff --git a/includes/type/object/class-downloadable-item-type.php b/includes/type/object/class-downloadable-item-type.php index 3332703e3..ac01ebbb8 100644 --- a/includes/type/object/class-downloadable-item-type.php +++ b/includes/type/object/class-downloadable-item-type.php @@ -25,31 +25,31 @@ class Downloadable_Item_Type { public static function register() { register_graphql_object_type( 'DownloadableItem', - array( + [ 'description' => __( 'A downloadable item', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'downloadId' => array( - 'type' => array( 'non_null' => 'String' ), + 'fields' => [ + 'downloadId' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Downloadable item unique identifier', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source['download_id'] ) ? $source['download_id'] : null; }, - ), - 'url' => array( + ], + 'url' => [ 'type' => 'String', 'description' => __( 'Download URL of the downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source['download_url'] ) ? $source['download_url'] : null; }, - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Name of the downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source['download_name'] ) ? $source['download_name'] : null; }, - ), - 'downloadsRemaining' => array( + ], + 'downloadsRemaining' => [ 'type' => 'Int', 'description' => __( 'Number of times the item can be downloaded.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { @@ -57,22 +57,22 @@ public static function register() { ? $source['downloads_remaining'] : null; }, - ), - 'accessExpires' => array( + ], + 'accessExpires' => [ 'type' => 'String', 'description' => __( 'The date the downloadable item expires', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source['access_expires'] ) ? $source['access_expires'] : null; }, - ), - 'product' => array( + ], + 'product' => [ 'type' => 'Product', 'description' => __( 'Product of downloadable item.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source['product_id'], $context ); }, - ), - 'download' => array( + ], + 'download' => [ 'type' => 'ProductDownload', 'description' => __( 'ProductDownload of the downloadable item', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { @@ -88,7 +88,7 @@ public static function register() { } $download_data = $files[ $download_id ]; - $download = new WC_Product_Download(); + $download = new WC_Product_Download(); $download->set_id( $download_id ); $download->set_name( $download_data['name'] @@ -107,9 +107,9 @@ public static function register() { return $download; }, - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-meta-data-type.php b/includes/type/object/class-meta-data-type.php index 758ae3cb5..899db8162 100644 --- a/includes/type/object/class-meta-data-type.php +++ b/includes/type/object/class-meta-data-type.php @@ -10,7 +10,7 @@ namespace WPGraphQL\WooCommerce\Type\WPObject; -use WP_GraphQL_WooCommerce; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; /** * Class Meta_Data_Type @@ -23,32 +23,32 @@ class Meta_Data_Type { public static function register() { register_graphql_object_type( 'MetaData', - array( + [ 'description' => __( 'Extra data defined on the WC object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( + 'fields' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Meta ID.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ), - 'key' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'key' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Meta key.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->key ) ? (string) $source->key : null; }, - ), - 'value' => array( + ], + 'value' => [ 'type' => 'String', 'description' => __( 'Meta value.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->value ) ? (string) $source->value : null; }, - ), - ), - ) + ], + ], + ] ); } @@ -58,23 +58,23 @@ public static function register() { * @return array */ public static function get_metadata_field_definition() { - return array( - 'type' => array( 'list_of' => 'MetaData' ), + return [ + 'type' => [ 'list_of' => 'MetaData' ], 'description' => __( 'Object meta data', 'wp-graphql-woocommerce' ), - 'args' => array( - 'key' => array( + 'args' => [ + 'key' => [ 'type' => 'String', 'description' => __( 'Retrieve meta by key', 'wp-graphql-woocommerce' ), - ), - 'keysIn' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'keysIn' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), - ), - 'multiple' => array( + ], + 'multiple' => [ 'type' => 'Boolean', 'description' => __( 'Retrieve meta with matching keys', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, array $args ) { // Set unique flag. $single = ! empty( $args['multiple'] ) ? ! $args['multiple'] : true; @@ -94,8 +94,8 @@ function( $meta ) use ( $data ) { // Check "keysIn" argument and format meta_data objects. $keys = $args['keysIn']; - $found = array(); - $data = array_filter( + $found = []; + $data = array_filter( $source->get_meta_data(), function( $meta ) use ( $keys, $single, &$found ) { if ( in_array( $meta->key, $keys, true ) ) { @@ -112,8 +112,8 @@ function( $meta ) use ( $keys, $single, &$found ) { ); } else { // If no arguments set return all meta (in accordance with unique flag). - $found = array(); - $data = array_filter( + $found = []; + $data = array_filter( $source->get_meta_data(), function( $meta ) use ( $single, &$found ) { if ( $single ) { @@ -130,6 +130,6 @@ function( $meta ) use ( $single, &$found ) { return ! empty( $data ) ? $data : null; }, - ); + ]; } } diff --git a/includes/type/object/class-order-item-type.php b/includes/type/object/class-order-item-type.php index edab04fe6..25268fd9b 100644 --- a/includes/type/object/class-order-item-type.php +++ b/includes/type/object/class-order-item-type.php @@ -23,189 +23,189 @@ class Order_Item_Type { * Register order item type */ public static function register() { - $types = array( - 'CouponLine' => array( + $types = [ + 'CouponLine' => [ // Description. __( 'a coupon line object', 'wp-graphql-woocommerce' ), // Fields. - array( - 'code' => array( + [ + 'code' => [ 'type' => 'String', 'description' => __( 'Line\'s Coupon code', 'wp-graphql-woocommerce' ), - ), - 'discount' => array( + ], + 'discount' => [ 'type' => 'String', 'description' => __( 'Line\'s Discount total', 'wp-graphql-woocommerce' ), - ), - 'discountTax' => array( + ], + 'discountTax' => [ 'type' => 'String', 'description' => __( 'Line\'s Discount total tax', 'wp-graphql-woocommerce' ), - ), - 'coupon' => array( + ], + 'coupon' => [ 'type' => 'Coupon', 'description' => __( 'Line\'s Coupon', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->coupon_id, $context ); }, - ), - ), - ), - 'FeeLine' => array( + ], + ], + ], + 'FeeLine' => [ // Description. __( 'a fee line object', 'wp-graphql-woocommerce' ), // Fields. - array( - 'amount' => array( + [ + 'amount' => [ 'type' => 'String', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), - ), - 'taxStatus' => array( + ], + 'taxStatus' => [ 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status of fee', 'wp-graphql-woocommerce' ), - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Line total (after discounts)', 'wp-graphql-woocommerce' ), - ), - 'totalTax' => array( + ], + 'totalTax' => [ 'type' => 'String', 'description' => __( 'Line total tax (after discounts)', 'wp-graphql-woocommerce' ), - ), - 'taxes' => array( - 'type' => array( 'list_of' => 'OrderItemTax' ), + ], + 'taxes' => [ + 'type' => [ 'list_of' => 'OrderItemTax' ], 'description' => __( 'Line taxes', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Line tax class', 'wp-graphql-woocommerce' ), - ), - ), - ), - 'ShippingLine' => array( + ], + ], + ], + 'ShippingLine' => [ // Description. __( 'a shipping line object', 'wp-graphql-woocommerce' ), // Fields. - array( - 'methodTitle' => array( + [ + 'methodTitle' => [ 'type' => 'String', 'description' => __( 'Shipping Line\'s shipping method name', 'wp-graphql-woocommerce' ), - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Line total (after discounts)', 'wp-graphql-woocommerce' ), - ), - 'totalTax' => array( + ], + 'totalTax' => [ 'type' => 'String', 'description' => __( 'Line total tax (after discounts)', 'wp-graphql-woocommerce' ), - ), - 'taxes' => array( - 'type' => array( 'list_of' => 'OrderItemTax' ), + ], + 'taxes' => [ + 'type' => [ 'list_of' => 'OrderItemTax' ], 'description' => __( 'Line taxes', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Line tax class', 'wp-graphql-woocommerce' ), - ), - 'shippingMethod' => array( + ], + 'shippingMethod' => [ 'type' => 'ShippingMethod', 'description' => __( 'Shipping Line\'s shipping method', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return Factory::resolve_shipping_method( $source->method_id ); }, - ), - ), - ), - 'TaxLine' => array( + ], + ], + ], + 'TaxLine' => [ // Description. __( 'a tax line object', 'wp-graphql-woocommerce' ), // Fields. - array( - 'rateCode' => array( + [ + 'rateCode' => [ 'type' => 'String', 'description' => __( 'Tax rate code/name', 'wp-graphql-woocommerce' ), - ), - 'label' => array( + ], + 'label' => [ 'type' => 'String', 'description' => __( 'Tax rate label', 'wp-graphql-woocommerce' ), - ), - 'taxTotal' => array( + ], + 'taxTotal' => [ 'type' => 'String', 'description' => __( 'Tax total (not including shipping taxes)', 'wp-graphql-woocommerce' ), - ), - 'shippingTaxTotal' => array( + ], + 'shippingTaxTotal' => [ 'type' => 'String', 'description' => __( 'Tax line\'s shipping tax total', 'wp-graphql-woocommerce' ), - ), - 'isCompound' => array( + ], + 'isCompound' => [ 'type' => 'Boolean', 'description' => __( 'Is this a compound tax rate?', 'wp-graphql-woocommerce' ), - ), - 'taxRate' => array( + ], + 'taxRate' => [ 'type' => 'TaxRate', 'description' => __( 'Tax line\'s tax rate', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return Factory::resolve_tax_rate( $source->rate_id, $context ); }, - ), - ), - ), - 'LineItem' => array( + ], + ], + ], + 'LineItem' => [ // Description. __( 'a line item object', 'wp-graphql-woocommerce' ), // Fields. - array( - 'productId' => array( + [ + 'productId' => [ 'type' => 'Int', 'description' => __( 'Line item\'s product ID', 'wp-graphql-woocommerce' ), - ), - 'variationId' => array( + ], + 'variationId' => [ 'type' => 'Int', 'description' => __( 'Line item\'s product variation ID', 'wp-graphql-woocommerce' ), - ), - 'quantity' => array( + ], + 'quantity' => [ 'type' => 'Int', 'description' => __( 'Line item\'s product quantity', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Line item\'s tax class', 'wp-graphql-woocommerce' ), - ), - 'subtotal' => array( + ], + 'subtotal' => [ 'type' => 'String', 'description' => __( 'Line item\'s subtotal', 'wp-graphql-woocommerce' ), - ), - 'subtotalTax' => array( + ], + 'subtotalTax' => [ 'type' => 'String', 'description' => __( 'Line item\'s subtotal tax', 'wp-graphql-woocommerce' ), - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Line item\'s total', 'wp-graphql-woocommerce' ), - ), - 'totalTax' => array( + ], + 'totalTax' => [ 'type' => 'String', 'description' => __( 'Line item\'s total tax', 'wp-graphql-woocommerce' ), - ), - 'taxes' => array( - 'type' => array( 'list_of' => 'OrderItemTax' ), + ], + 'taxes' => [ + 'type' => [ 'list_of' => 'OrderItemTax' ], 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ), - 'itemDownloads' => array( - 'type' => array( 'list_of' => 'ProductDownload' ), + ], + 'itemDownloads' => [ + 'type' => [ 'list_of' => 'ProductDownload' ], 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ), - 'taxStatus' => array( + ], + 'taxStatus' => [ 'type' => 'TaxStatusEnum', 'description' => __( 'Line item\'s taxes', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], // Connections. - array( - 'product' => array( + [ + 'product' => [ 'toType' => 'Product', 'oneToOne' => true, 'resolve' => function ( $source, array $args, AppContext $context, $info ) { @@ -217,8 +217,8 @@ public static function register() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ), - 'variation' => array( + ], + 'variation' => [ 'toType' => 'ProductVariation', 'oneToOne' => true, 'resolve' => function ( $source, array $args, AppContext $context, $info ) { @@ -234,58 +234,58 @@ public static function register() { ->set_query_arg( 'p', $id ) ->get_connection(); }, - ), - ), - ), - ); + ], + ], + ], + ]; // Registers order item objects. foreach ( $types as $type_name => $config ) { register_graphql_object_type( $type_name, - array( + [ 'description' => $config[0], 'fields' => self::get_fields( $config[1] ), 'connections' => ! empty( $config[2] ) ? $config[2] : null, - ) + ] ); } // Registers tax statement object. register_graphql_object_type( 'OrderItemTax', - array( + [ 'description' => __( 'Order item tax statement', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'taxLineId' => array( - 'type' => array( 'non_null' => 'Int' ), + 'fields' => [ + 'taxLineId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Order item ID for tax line connected to this statement', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['ID'] ) ? $source['ID'] : null; }, - ), - 'subtotal' => array( + ], + 'subtotal' => [ 'type' => 'Float', 'description' => __( 'Subtotal', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['subtotal'] ) ? $source['subtotal'] : null; }, - ), - 'total' => array( + ], + 'total' => [ 'type' => 'Float', 'description' => __( 'Total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['total'] ) ? $source['total'] : null; }, - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'Amount taxed', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['amount'] ) ? $source['amount'] : null; }, - ), - 'taxLine' => array( + ], + 'taxLine' => [ 'type' => 'TaxLine', 'description' => __( 'Tax line connected to this statement', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { @@ -293,9 +293,9 @@ public static function register() { $item->cached_order = $source; return ! empty( $item ) ? Factory::resolve_order_item( $item ) : null; }, - ), - ), - ) + ], + ], + ] ); } @@ -305,20 +305,20 @@ public static function register() { * @param array $fields - type specific fields. * @return array */ - private static function get_fields( $fields = array() ) { + private static function get_fields( $fields = [] ) { return array_merge( - array( - 'databaseId' => array( + [ + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the order item in the database', 'wp-graphql-woocommerce' ), - ), - 'orderId' => array( + ], + 'orderId' => [ 'type' => 'Int', 'description' => __( 'The Id of the order the order item belongs to.', 'wp-graphql-woocommerce' ), - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), + ], $fields ); } diff --git a/includes/type/object/class-order-type.php b/includes/type/object/class-order-type.php index 4988b4f55..1d764b0c4 100644 --- a/includes/type/object/class-order-type.php +++ b/includes/type/object/class-order-type.php @@ -44,78 +44,78 @@ public static function resolve_item_connection( $source, array $args, AppContext public static function register() { register_graphql_object_type( 'Order', - array( + [ 'description' => __( 'A order object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( + 'interfaces' => [ 'Node', 'NodeWithComments', - ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the order', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( + ], + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the order in the database', 'wp-graphql-woocommerce' ), - ), - 'orderKey' => array( + ], + 'orderKey' => [ 'type' => 'String', 'description' => __( 'Order key', 'wp-graphql-woocommerce' ), - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'Date order was created', 'wp-graphql-woocommerce' ), - ), - 'modified' => array( + ], + 'modified' => [ 'type' => 'String', 'description' => __( 'Date order was last updated', 'wp-graphql-woocommerce' ), - ), - 'currency' => array( + ], + 'currency' => [ 'type' => 'String', 'description' => __( 'Order currency', 'wp-graphql-woocommerce' ), - ), - 'paymentMethod' => array( + ], + 'paymentMethod' => [ 'type' => 'String', 'description' => __( 'Payment method', 'wp-graphql-woocommerce' ), - ), - 'paymentMethodTitle' => array( + ], + 'paymentMethodTitle' => [ 'type' => 'String', 'description' => __( 'Payment method title', 'wp-graphql-woocommerce' ), - ), - 'transactionId' => array( + ], + 'transactionId' => [ 'type' => 'String', 'description' => __( 'Transaction ID', 'wp-graphql-woocommerce' ), - ), - 'customerIpAddress' => array( + ], + 'customerIpAddress' => [ 'type' => 'String', 'description' => __( 'Customer IP Address', 'wp-graphql-woocommerce' ), - ), - 'customerUserAgent' => array( + ], + 'customerUserAgent' => [ 'type' => 'String', 'description' => __( 'Customer User Agent', 'wp-graphql-woocommerce' ), - ), - 'createdVia' => array( + ], + 'createdVia' => [ 'type' => 'String', 'description' => __( 'How order was created', 'wp-graphql-woocommerce' ), - ), - 'dateCompleted' => array( + ], + 'dateCompleted' => [ 'type' => 'String', 'description' => __( 'Date order was completed', 'wp-graphql-woocommerce' ), - ), - 'datePaid' => array( + ], + 'datePaid' => [ 'type' => 'String', 'description' => __( 'Date order was paid', 'wp-graphql-woocommerce' ), - ), - 'discountTotal' => array( + ], + 'discountTotal' => [ 'type' => 'String', 'description' => __( 'Discount total amount', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -125,16 +125,16 @@ public static function register() { return $source->discountTotal; } }, - ), - 'discountTax' => array( + ], + 'discountTax' => [ 'type' => 'String', 'description' => __( 'Discount tax amount', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -144,16 +144,16 @@ public static function register() { return $source->discountTax; } }, - ), - 'shippingTotal' => array( + ], + 'shippingTotal' => [ 'type' => 'String', 'description' => __( 'Shipping total amount', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -163,16 +163,16 @@ public static function register() { // @codingStandardsIgnoreLine. return $source->shippingTotal; }, - ), - 'shippingTax' => array( + ], + 'shippingTax' => [ 'type' => 'String', 'description' => __( 'Shipping tax amount', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -182,16 +182,16 @@ public static function register() { // @codingStandardsIgnoreLine. return $source->shippingTax; }, - ), - 'cartTax' => array( + ], + 'cartTax' => [ 'type' => 'String', 'description' => __( 'Cart tax amount', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -201,16 +201,16 @@ public static function register() { return $source->cartTax; } }, - ), - 'total' => array( + ], + 'total' => [ 'type' => 'String', 'description' => __( 'Order grand total', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -219,16 +219,16 @@ public static function register() { return $source->total; } }, - ), - 'totalTax' => array( + ], + 'totalTax' => [ 'type' => 'String', 'description' => __( 'Order taxes', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -238,16 +238,16 @@ public static function register() { return $source->totalTax; } }, - ), - 'subtotal' => array( + ], + 'subtotal' => [ 'type' => 'String', 'description' => __( 'Order subtotal', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -256,51 +256,51 @@ public static function register() { return $source->subtotal; } }, - ), - 'orderNumber' => array( + ], + 'orderNumber' => [ 'type' => 'String', 'description' => __( 'Order number', 'wp-graphql-woocommerce' ), - ), - 'orderVersion' => array( + ], + 'orderVersion' => [ 'type' => 'String', 'description' => __( 'Order version', 'wp-graphql-woocommerce' ), - ), - 'pricesIncludeTax' => array( + ], + 'pricesIncludeTax' => [ 'type' => 'Boolean', 'description' => __( 'Prices include taxes?', 'wp-graphql-woocommerce' ), - ), - 'cartHash' => array( + ], + 'cartHash' => [ 'type' => 'String', 'description' => __( 'Cart hash', 'wp-graphql-woocommerce' ), - ), - 'customerNote' => array( + ], + 'customerNote' => [ 'type' => 'String', 'description' => __( 'Customer note', 'wp-graphql-woocommerce' ), - ), - 'isDownloadPermitted' => array( + ], + 'isDownloadPermitted' => [ 'type' => 'Boolean', 'description' => __( 'Is product download is permitted', 'wp-graphql-woocommerce' ), - ), - 'billing' => array( + ], + 'billing' => [ 'type' => 'CustomerAddress', 'description' => __( 'Order billing properties', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'CustomerAddress', 'description' => __( 'Order shipping properties', 'wp-graphql-woocommerce' ), - ), - 'status' => array( + ], + 'status' => [ 'type' => 'OrderStatusEnum', 'description' => __( 'Order status', 'wp-graphql-woocommerce' ), - ), - 'parent' => array( + ], + 'parent' => [ 'type' => 'Order', 'description' => __( 'Parent order', 'wp-graphql-woocommerce' ), 'resolve' => function( $order, array $args, AppContext $context ) { return Factory::resolve_crud_object( $order->parent_id, $context ); }, - ), - 'customer' => array( + ], + 'customer' => [ 'type' => 'Customer', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), 'resolve' => function( $order, array $args, AppContext $context ) { @@ -311,87 +311,87 @@ public static function register() { return Factory::resolve_customer( $order->customer_id, $context ); }, - ), - 'shippingAddressMapUrl' => array( + ], + 'shippingAddressMapUrl' => [ 'type' => 'String', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), - ), - 'hasBillingAddress' => array( + ], + 'hasBillingAddress' => [ 'type' => 'Boolean', 'description' => __( 'Order has a billing address?', 'wp-graphql-woocommerce' ), - ), - 'hasShippingAddress' => array( + ], + 'hasShippingAddress' => [ 'type' => 'Boolean', 'description' => __( 'Order has a shipping address?', 'wp-graphql-woocommerce' ), - ), - 'needsShippingAddress' => array( + ], + 'needsShippingAddress' => [ 'type' => 'Boolean', 'description' => __( 'If order needs shipping address', 'wp-graphql-woocommerce' ), - ), - 'hasDownloadableItem' => array( + ], + 'hasDownloadableItem' => [ 'type' => 'Boolean', 'description' => __( 'If order contains a downloadable product', 'wp-graphql-woocommerce' ), - ), - 'needsPayment' => array( + ], + 'needsPayment' => [ 'type' => 'Boolean', 'description' => __( 'If order needs payment', 'wp-graphql-woocommerce' ), - ), - 'needsProcessing' => array( + ], + 'needsProcessing' => [ 'type' => 'Boolean', 'description' => __( 'If order needs processing before it can be completed', 'wp-graphql-woocommerce' ), - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), - 'connections' => array( - 'taxLines' => array( + ], + 'connections' => [ + 'taxLines' => [ 'toType' => 'TaxLine', - 'connectionArgs' => array(), - 'resolve' => array( __CLASS__, 'resolve_item_connection' ), - ), - 'feeLines' => array( + 'connectionArgs' => [], + 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + ], + 'feeLines' => [ 'toType' => 'FeeLine', - 'connectionArgs' => array(), - 'resolve' => array( __CLASS__, 'resolve_item_connection' ), - ), - 'shippingLines' => array( + 'connectionArgs' => [], + 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + ], + 'shippingLines' => [ 'toType' => 'ShippingLine', - 'connectionArgs' => array(), - 'resolve' => array( __CLASS__, 'resolve_item_connection' ), - ), - 'couponLines' => array( + 'connectionArgs' => [], + 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + ], + 'couponLines' => [ 'toType' => 'CouponLine', - 'connectionArgs' => array(), - 'resolve' => array( __CLASS__, 'resolve_item_connection' ), - ), - 'lineItems' => array( + 'connectionArgs' => [], + 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + ], + 'lineItems' => [ 'toType' => 'LineItem', - 'connectionArgs' => array(), - 'resolve' => array( __CLASS__, 'resolve_item_connection' ), - ), - 'downloadableItems' => array( + 'connectionArgs' => [], + 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + ], + 'downloadableItems' => [ 'toType' => 'DownloadableItem', - 'connectionArgs' => array( - 'active' => array( + 'connectionArgs' => [ + 'active' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that can be downloaded now.', 'wp-graphql-woocommerce' ), - ), - 'expired' => array( + ], + 'expired' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that are expired.', 'wp-graphql-woocommerce' ), - ), - 'hasDownloadsRemaining' => array( + ], + 'hasDownloadsRemaining' => [ 'type' => 'Boolean', 'description' => __( 'Limit results to downloadable items that have downloads remaining.', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => 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 9d0464ded..24a046f54 100644 --- a/includes/type/object/class-payment-gateway-type.php +++ b/includes/type/object/class-payment-gateway-type.php @@ -21,39 +21,39 @@ class Payment_Gateway_Type { public static function register() { register_graphql_object_type( 'PaymentGateway', - array( + [ 'description' => __( 'A payment gateway object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'String' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->id ) ? $source->id : null; }, - ), - 'title' => array( + ], + 'title' => [ 'type' => 'String', 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->title ) ? $source->title : null; }, - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'gateway\'s description', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->description ) ? $source->description : null; }, - ), - 'icon' => array( + ], + 'icon' => [ 'type' => 'String', 'description' => __( 'gateway\'s icon', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source->icon ) ? $source->icon : null; }, - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-product-attribute-types.php b/includes/type/object/class-product-attribute-types.php index 01d6e93b5..1ba4bd882 100644 --- a/includes/type/object/class-product-attribute-types.php +++ b/includes/type/object/class-product-attribute-types.php @@ -20,84 +20,84 @@ public static function register() { // Local. register_graphql_object_type( 'LocalProductAttribute', - array( + [ 'description' => __( 'A product attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'ProductAttribute' ), - 'fields' => array( - 'scope' => array( - 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), + 'interfaces' => [ 'ProductAttribute' ], + 'fields' => [ + 'scope' => [ + 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => function () { return 'local'; }, - ), - ), - ) + ], + ], + ] ); // Global. register_graphql_object_type( 'GlobalProductAttribute', - array( + [ 'description' => __( 'A product attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'ProductAttribute' ), - 'fields' => array( - 'scope' => array( - 'type' => array( 'non_null' => 'ProductAttributeTypesEnum' ), + 'interfaces' => [ 'ProductAttribute' ], + 'fields' => [ + 'scope' => [ + 'type' => [ 'non_null' => 'ProductAttributeTypesEnum' ], 'description' => __( 'Product attribute scope.', 'wp-graphql-woocommerce' ), 'resolve' => function () { return 'global'; }, - ), - 'label' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'label' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { $taxonomy = get_taxonomy( $attribute->get_name() ); return $taxonomy ? ucwords( $taxonomy->labels->singular_name ) : null; }, - ), - 'name' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'name' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Product attribute name', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { $taxonomy = get_taxonomy( $attribute->get_name() ); return $taxonomy->labels->singular_name; }, - ), - 'slug' => array( - 'type' => array( 'non_null' => 'String' ), + ], + 'slug' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Product attribute slug', 'wp-graphql-woocommerce' ), 'resolve' => function ( $attribute ) { return ! empty( $attribute->get_name() ) ? $attribute->get_name() : null; }, - ), - ), - ) + ], + ], + ] ); // ProductAttributeOutput for CartItemError and CartItem edges. register_graphql_object_type( 'ProductAttributeOutput', - array( + [ 'description' => __( 'A simple product attribute object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'attributeName' => array( + 'fields' => [ + 'attributeName' => [ 'type' => 'String', 'description' => __( 'Attribute name.', 'wp-graphql-woocommerce' ), 'resolve' => function ( array $attribute ) { return ! empty( $attribute['attributeName'] ) ? $attribute['attributeName'] : null; }, - ), - 'attributeValue' => array( + ], + 'attributeValue' => [ 'type' => 'String', 'description' => __( 'Attribute value.', 'wp-graphql-woocommerce' ), 'resolve' => 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 dae509032..d539b8536 100644 --- a/includes/type/object/class-product-category-type.php +++ b/includes/type/object/class-product-category-type.php @@ -24,8 +24,8 @@ class Product_Category_Type { public static function register_fields() { register_graphql_fields( 'ProductCategory', - array( - 'image' => array( + [ + 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product category image', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { @@ -34,24 +34,24 @@ public static function register_fields() { ? DataSource::resolve_post_object( $thumbnail_id, $context ) : null; }, - ), - 'display' => array( + ], + 'display' => [ 'type' => 'ProductCategoryDisplay', 'description' => __( 'Product category display type', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { $display = get_term_meta( $source->term_id, 'display_type', true ); return ! empty( $display ) ? $display : 'default'; }, - ), - 'menuOrder' => array( + ], + 'menuOrder' => [ 'type' => 'Integer', 'description' => __( 'Product category menu order', 'wp-graphql-woocommerce' ), 'resolve' => 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 84344b0c3..8c89ee1bc 100644 --- a/includes/type/object/class-product-download-type.php +++ b/includes/type/object/class-product-download-type.php @@ -21,67 +21,67 @@ class Product_Download_Type { public static function register() { register_graphql_object_type( 'ProductDownload', - array( + [ 'description' => __( 'A product object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'downloadId' => array( - 'type' => array( 'non_null' => 'String' ), + 'fields' => [ + 'downloadId' => [ + 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Product download ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->get_id() : null; }, - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Product download name', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->get_name() : null; }, - ), - 'filePathType' => array( + ], + 'filePathType' => [ 'type' => 'String', 'description' => __( 'Type of file path set', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->get_type_of_file_path() : null; }, - ), - 'fileType' => array( + ], + 'fileType' => [ 'type' => 'String', 'description' => __( 'File type', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->get_file_type() : null; }, - ), - 'fileExt' => array( + ], + 'fileExt' => [ 'type' => 'String', 'description' => __( 'File extension', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->get_file_extension() : null; }, - ), - 'allowedFileType' => array( + ], + 'allowedFileType' => [ 'type' => 'Boolean', 'description' => __( 'Is file allowed', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->is_allowed_filetype() : null; }, - ), - 'fileExists' => array( + ], + 'fileExists' => [ 'type' => 'Boolean', 'description' => __( 'Validate file exists', 'wp-graphql-woocommerce' ), 'resolve' => function ( $download ) { return ! empty( $download ) ? $download->file_exists() : null; }, - ), - 'file' => array( + ], + 'file' => [ 'type' => 'String', 'description' => __( 'Download file', 'wp-graphql-woocommerce' ), 'resolve' => 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 85da4091c..de20867f0 100644 --- a/includes/type/object/class-product-types.php +++ b/includes/type/object/class-product-types.php @@ -38,7 +38,7 @@ public static function register() { * @return array */ public static function get_product_interfaces() { - return array( + return [ 'Node', 'Product', 'NodeWithComments', @@ -46,7 +46,7 @@ public static function get_product_interfaces() { 'NodeWithFeaturedImage', 'ContentNode', 'UniformResourceIdentifiable', - ); + ]; } /** @@ -56,34 +56,34 @@ public static function get_product_interfaces() { * * @return array */ - public static function get_inventory_fields( $fields = array() ) { + public static function get_inventory_fields( $fields = [] ) { return array_merge( - array( - 'manageStock' => array( + [ + 'manageStock' => [ 'type' => 'Boolean', 'description' => __( 'If product manage stock', 'wp-graphql-woocommerce' ), - ), - 'stockQuantity' => array( + ], + 'stockQuantity' => [ 'type' => 'Int', 'description' => __( 'Number of items available for sale', 'wp-graphql-woocommerce' ), - ), - 'backorders' => array( + ], + 'backorders' => [ 'type' => 'BackordersEnum', 'description' => __( 'Product backorders status', 'wp-graphql-woocommerce' ), - ), - 'soldIndividually' => array( + ], + 'soldIndividually' => [ 'type' => 'Boolean', 'description' => __( 'If should be sold individually', 'wp-graphql-woocommerce' ), - ), - 'backordersAllowed' => array( + ], + 'backordersAllowed' => [ 'type' => 'Boolean', 'description' => __( 'Can product be backordered?', 'wp-graphql-woocommerce' ), - ), - 'stockStatus' => array( + ], + 'stockStatus' => [ 'type' => 'StockStatusEnum', 'description' => __( 'Product stock status', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], $fields ); } @@ -95,38 +95,38 @@ public static function get_inventory_fields( $fields = array() ) { * * @return array */ - public static function get_shipping_fields( $fields = array() ) { + public static function get_shipping_fields( $fields = [] ) { return array_merge( - array( - 'weight' => array( + [ + 'weight' => [ 'type' => 'String', 'description' => __( 'Product\'s weight', 'wp-graphql-woocommerce' ), - ), - 'length' => array( + ], + 'length' => [ 'type' => 'String', 'description' => __( 'Product\'s length', 'wp-graphql-woocommerce' ), - ), - 'width' => array( + ], + 'width' => [ 'type' => 'String', 'description' => __( 'Product\'s width', 'wp-graphql-woocommerce' ), - ), - 'height' => array( + ], + 'height' => [ 'type' => 'String', 'description' => __( 'Product\'s height', 'wp-graphql-woocommerce' ), - ), - 'shippingClassId' => array( + ], + 'shippingClassId' => [ 'type' => 'Int', 'description' => __( 'shipping class ID', 'wp-graphql-woocommerce' ), - ), - 'shippingRequired' => array( + ], + 'shippingRequired' => [ 'type' => 'Boolean', 'description' => __( 'Does product need to be shipped?', 'wp-graphql-woocommerce' ), - ), - 'shippingTaxable' => array( + ], + 'shippingTaxable' => [ 'type' => 'Boolean', 'description' => __( 'Is product shipping taxable?', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], $fields ); } @@ -138,18 +138,18 @@ public static function get_shipping_fields( $fields = array() ) { * * @return array */ - public static function get_pricing_and_tax_fields( $fields = array() ) { + public static function get_pricing_and_tax_fields( $fields = [] ) { return array_merge( - array( - 'price' => array( + [ + 'price' => [ 'type' => 'String', 'description' => __( 'Product\'s active price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -158,16 +158,16 @@ public static function get_pricing_and_tax_fields( $fields = array() ) { return $source->price; } }, - ), - 'regularPrice' => array( + ], + 'regularPrice' => [ 'type' => 'String', 'description' => __( 'Product\'s regular price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -177,16 +177,16 @@ public static function get_pricing_and_tax_fields( $fields = array() ) { return $source->regularPrice; } }, - ), - 'salePrice' => array( + ], + 'salePrice' => [ 'type' => 'String', 'description' => __( 'Product\'s sale price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -196,16 +196,16 @@ public static function get_pricing_and_tax_fields( $fields = array() ) { return $source->salePrice; } }, - ), - 'taxStatus' => array( + ], + 'taxStatus' => [ 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Tax class', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], $fields ); } @@ -217,30 +217,30 @@ public static function get_pricing_and_tax_fields( $fields = array() ) { * * @return array */ - public static function get_virtual_data_fields( $fields = array() ) { + public static function get_virtual_data_fields( $fields = [] ) { return array_merge( - array( - 'virtual' => array( + [ + 'virtual' => [ 'type' => 'Boolean', 'description' => __( 'Is product virtual?', 'wp-graphql-woocommerce' ), - ), - 'downloadExpiry' => array( + ], + 'downloadExpiry' => [ 'type' => 'Int', 'description' => __( 'Download expiry', 'wp-graphql-woocommerce' ), - ), - 'downloadable' => array( + ], + 'downloadable' => [ 'type' => 'Boolean', 'description' => __( 'Is downloadable?', 'wp-graphql-woocommerce' ), - ), - 'downloadLimit' => array( + ], + 'downloadLimit' => [ 'type' => 'Int', 'description' => __( 'Download limit', 'wp-graphql-woocommerce' ), - ), - 'downloads' => array( - 'type' => array( 'list_of' => 'ProductDownload' ), + ], + 'downloads' => [ + 'type' => [ 'list_of' => 'ProductDownload' ], 'description' => __( 'Product downloads', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], $fields ); } @@ -251,7 +251,7 @@ public static function get_virtual_data_fields( $fields = array() ) { private static function register_simple_product_type() { register_graphql_object_type( 'SimpleProduct', - array( + [ 'description' => __( 'A product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces(), 'fields' => array_merge( @@ -261,7 +261,7 @@ private static function register_simple_product_type() { self::get_shipping_fields(), self::get_virtual_data_fields() ), - ) + ] ); } @@ -271,7 +271,7 @@ private static function register_simple_product_type() { private static function register_variable_product_type() { register_graphql_object_type( 'VariableProduct', - array( + [ 'description' => __( 'A variable product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces(), 'fields' => array_merge( @@ -280,7 +280,7 @@ private static function register_variable_product_type() { self::get_inventory_fields(), self::get_shipping_fields() ), - ) + ] ); } @@ -290,24 +290,24 @@ private static function register_variable_product_type() { private static function register_external_product_type() { register_graphql_object_type( 'ExternalProduct', - array( + [ 'description' => __( 'A external product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces(), 'fields' => array_merge( Product::get_fields(), self::get_pricing_and_tax_fields(), - array( - 'externalUrl' => array( + [ + 'externalUrl' => [ 'type' => 'String', 'description' => __( 'External product url', 'wp-graphql-woocommerce' ), - ), - 'buttonText' => array( + ], + 'buttonText' => [ 'type' => 'String', 'description' => __( 'External product Buy button text', 'wp-graphql-woocommerce' ), - ), - ) + ], + ] ), - ) + ] ); } @@ -317,26 +317,26 @@ private static function register_external_product_type() { private static function register_group_product_type() { register_graphql_object_type( 'GroupProduct', - array( + [ 'description' => __( 'A group product object', 'wp-graphql-woocommerce' ), 'interfaces' => self::get_product_interfaces(), 'fields' => array_merge( Product::get_fields(), - array( - 'addToCartText' => array( + [ + 'addToCartText' => [ 'type' => 'String', 'description' => __( 'Product\'s add to cart button text description', 'wp-graphql-woocommerce' ), - ), - 'addToCartDescription' => array( + ], + 'addToCartDescription' => [ 'type' => 'String', 'description' => __( 'Product\'s add to cart button text description', 'wp-graphql-woocommerce' ), - ), - 'price' => array( + ], + 'price' => [ 'type' => 'String', 'description' => __( 'Products\' price range', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); - $child_prices = array(); + $child_prices = []; $children = array_filter( array_map( 'wc_get_product', $source->grouped_ids ), 'wc_products_array_filter_visible_grouped' ); foreach ( $children as $child ) { @@ -363,10 +363,10 @@ private static function register_group_product_type() { return \wc_graphql_price( $min_price ); }, - ), - ) + ], + ] ), - ) + ] ); } } diff --git a/includes/type/object/class-product-variation-type.php b/includes/type/object/class-product-variation-type.php index e964893f1..d53fc199f 100644 --- a/includes/type/object/class-product-variation-type.php +++ b/includes/type/object/class-product-variation-type.php @@ -27,52 +27,52 @@ class Product_Variation_Type { public static function register() { register_graphql_object_type( 'ProductVariation', - array( + [ 'description' => __( 'A product variation object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( + 'interfaces' => [ 'Node', 'NodeWithFeaturedImage', 'ContentNode', 'UniformResourceIdentifiable', - ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the product variation', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( - 'type' => array( 'non_null' => 'Int' ), + ], + 'databaseId' => [ + 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'The ID of the refund in the database', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Product name', 'wp-graphql-woocommerce' ), - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'Date variation created', 'wp-graphql-woocommerce' ), - ), - 'modified' => array( + ], + 'modified' => [ 'type' => 'String', 'description' => __( 'Date variation last updated', 'wp-graphql-woocommerce' ), - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Product description', 'wp-graphql-woocommerce' ), - ), - 'sku' => array( + ], + 'sku' => [ 'type' => 'String', 'description' => __( 'Product variation SKU (Stock-keeping unit)', 'wp-graphql-woocommerce' ), - ), - 'price' => array( + ], + 'price' => [ 'type' => 'String', 'description' => __( 'Product variation\'s active price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -81,16 +81,16 @@ public static function register() { return $source->price; } }, - ), - 'regularPrice' => array( + ], + 'regularPrice' => [ 'type' => 'String', 'description' => __( 'Product variation\'s regular price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -100,16 +100,16 @@ public static function register() { return $source->regularPrice; } }, - ), - 'salePrice' => array( + ], + 'salePrice' => [ 'type' => 'String', 'description' => __( 'Product variation\'s sale price', 'wp-graphql-woocommerce' ), - 'args' => array( - 'format' => array( + 'args' => [ + 'format' => [ 'type' => 'PricingFieldFormatEnum', 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. @@ -119,126 +119,126 @@ public static function register() { return $source->salePrice; } }, - ), - 'dateOnSaleFrom' => array( + ], + 'dateOnSaleFrom' => [ 'type' => 'String', 'description' => __( 'Date on sale from', 'wp-graphql-woocommerce' ), - ), - 'dateOnSaleTo' => array( + ], + 'dateOnSaleTo' => [ 'type' => 'String', 'description' => __( 'Date on sale to', 'wp-graphql-woocommerce' ), - ), - 'onSale' => array( + ], + 'onSale' => [ 'type' => 'Boolean', 'description' => __( 'Is variation on sale?', 'wp-graphql-woocommerce' ), - ), - 'status' => array( + ], + 'status' => [ 'type' => 'String', 'description' => __( 'Variation status', 'wp-graphql-woocommerce' ), - ), - 'purchasable' => array( + ], + 'purchasable' => [ 'type' => 'Boolean', 'description' => __( 'If product variation can be bought', 'wp-graphql-woocommerce' ), - ), - 'virtual' => array( + ], + 'virtual' => [ 'type' => 'Boolean', 'description' => __( 'Is product virtual?', 'wp-graphql-woocommerce' ), - ), - 'downloadable' => array( + ], + 'downloadable' => [ 'type' => 'Boolean', 'description' => __( 'Is downloadable?', 'wp-graphql-woocommerce' ), - ), - 'downloads' => array( - 'type' => array( 'list_of' => 'ProductDownload' ), + ], + 'downloads' => [ + 'type' => [ 'list_of' => 'ProductDownload' ], 'description' => __( 'Product downloads', 'wp-graphql-woocommerce' ), - ), - 'downloadLimit' => array( + ], + 'downloadLimit' => [ 'type' => 'Int', 'description' => __( 'Download limit', 'wp-graphql-woocommerce' ), - ), - 'downloadExpiry' => array( + ], + 'downloadExpiry' => [ 'type' => 'Int', 'description' => __( 'Download expiry', 'wp-graphql-woocommerce' ), - ), - 'taxStatus' => array( + ], + 'taxStatus' => [ 'type' => 'TaxStatusEnum', 'description' => __( 'Tax status', 'wp-graphql-woocommerce' ), - ), - 'taxClass' => array( + ], + 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Product variation tax class', 'wp-graphql-woocommerce' ), - ), - 'manageStock' => array( + ], + 'manageStock' => [ 'type' => 'ManageStockEnum', 'description' => __( 'if/how product variation stock is managed', 'wp-graphql-woocommerce' ), - ), - 'stockQuantity' => array( + ], + 'stockQuantity' => [ 'type' => 'Int', 'description' => __( 'Product variation stock quantity', 'wp-graphql-woocommerce' ), - ), - 'stockStatus' => array( + ], + 'stockStatus' => [ 'type' => 'StockStatusEnum', 'description' => __( 'Product stock status', 'wp-graphql-woocommerce' ), - ), - 'backorders' => array( + ], + 'backorders' => [ 'type' => 'BackordersEnum', 'description' => __( 'Product variation backorders', 'wp-graphql-woocommerce' ), - ), - 'backordersAllowed' => array( + ], + 'backordersAllowed' => [ 'type' => 'Boolean', 'description' => __( 'Can product be backordered?', 'wp-graphql-woocommerce' ), - ), - 'weight' => array( + ], + 'weight' => [ 'type' => 'String', 'description' => __( 'Product variation weight', 'wp-graphql-woocommerce' ), - ), - 'length' => array( + ], + 'length' => [ 'type' => 'String', 'description' => __( 'Product variation length', 'wp-graphql-woocommerce' ), - ), - 'width' => array( + ], + 'width' => [ 'type' => 'String', 'description' => __( 'Product variation width', 'wp-graphql-woocommerce' ), - ), - 'height' => array( + ], + 'height' => [ 'type' => 'String', 'description' => __( 'Product variation height', 'wp-graphql-woocommerce' ), - ), - 'menuOrder' => array( + ], + 'menuOrder' => [ 'type' => 'Int', 'description' => __( 'Menu order', 'wp-graphql-woocommerce' ), - ), - 'purchaseNote' => array( + ], + 'purchaseNote' => [ 'type' => 'String', 'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ), - ), - 'shippingClass' => array( + ], + 'shippingClass' => [ 'type' => 'String', 'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ), - ), - 'catalogVisibility' => array( + ], + 'catalogVisibility' => [ 'type' => 'CatalogVisibilityEnum', 'description' => __( 'Product variation catalog visibility', 'wp-graphql-woocommerce' ), - ), - 'hasAttributes' => array( + ], + 'hasAttributes' => [ 'type' => 'Boolean', 'description' => __( 'Does product variation have any visible attributes', 'wp-graphql-woocommerce' ), - ), - 'type' => array( + ], + 'type' => [ 'type' => 'ProductTypesEnum', 'description' => __( 'Product type', 'wp-graphql-woocommerce' ), - ), - 'image' => array( + ], + 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return ! empty( $source->image_id ) ? DataSource::resolve_post_object( $source->image_id, $context ) : null; }, - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), - ) + ], + ] ); } } diff --git a/includes/type/object/class-refund-type.php b/includes/type/object/class-refund-type.php index 1071c5528..eda808e5e 100644 --- a/includes/type/object/class-refund-type.php +++ b/includes/type/object/class-refund-type.php @@ -27,45 +27,45 @@ class Refund_Type { public static function register() { register_graphql_object_type( 'Refund', - array( + [ 'description' => __( 'A refund object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Node' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Node' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the refund', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( + ], + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the refund in the database', 'wp-graphql-woocommerce' ), - ), - 'title' => array( + ], + 'title' => [ 'type' => 'String', 'description' => __( 'A title for the new post type', 'wp-graphql-woocommerce' ), - ), - 'amount' => array( + ], + 'amount' => [ 'type' => 'Float', 'description' => __( 'Refunded amount', 'wp-graphql-woocommerce' ), - ), - 'reason' => array( + ], + 'reason' => [ 'type' => 'String', 'description' => __( 'Reason for refund', 'wp-graphql-woocommerce' ), - ), - 'refundedBy' => array( + ], + 'refundedBy' => [ 'type' => 'User', 'description' => __( 'User who completed the refund', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { return DataSource::resolve_user( $source->refunded_by_id, $context ); }, - ), - 'date' => array( + ], + 'date' => [ 'type' => 'String', 'description' => __( 'The date of the refund', 'wp-graphql-woocommerce' ), - ), + ], 'metaData' => Meta_Data_Type::get_metadata_field_definition(), - ), - ) + ], + ] ); } } diff --git a/includes/type/object/class-root-query.php b/includes/type/object/class-root-query.php index 1deb03a06..5d827da40 100644 --- a/includes/type/object/class-root-query.php +++ b/includes/type/object/class-root-query.php @@ -13,6 +13,7 @@ use GraphQLRelay\Relay; use WPGraphQL\AppContext; use WPGraphQL\WooCommerce\Data\Factory; +use WPGraphQL\WooCommerce\WP_GraphQL_WooCommerce; /** * Class - Root_Query @@ -24,15 +25,15 @@ class Root_Query { public static function register_fields() { register_graphql_fields( 'RootQuery', - array( - 'cart' => array( + [ + 'cart' => [ 'type' => 'Cart', - 'args' => array( - 'recalculateTotals' => array( + 'args' => [ + 'recalculateTotals' => [ 'type' => 'Boolean', 'description' => __( 'Should cart totals be recalculated.', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => function( $_, $args ) { $token_invalid = apply_filters( 'graphql_woocommerce_session_token_errors', null ); @@ -47,14 +48,14 @@ public static function register_fields() { return $cart; }, - ), - 'cartItem' => array( + ], + 'cartItem' => [ 'type' => 'CartItem', - 'args' => array( - 'key' => array( - 'type' => array( 'non_null' => 'ID' ), - ), - ), + 'args' => [ + 'key' => [ + 'type' => [ 'non_null' => 'ID' ], + ], + ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args, AppContext $context ) { $item = Factory::resolve_cart_item( $args['key'], $context ); @@ -64,14 +65,14 @@ public static function register_fields() { return $item; }, - ), - 'cartFee' => array( + ], + 'cartFee' => [ 'type' => 'CartFee', - 'args' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), - ), - ), + 'args' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], + ], + ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), 'resolve' => function( $source, array $args ) { $fee = Factory::resolve_cart_fee( $args['id'] ); @@ -81,17 +82,17 @@ public static function register_fields() { return $fee; }, - ), - 'coupon' => array( + ], + 'coupon' => [ 'type' => 'Coupon', 'description' => __( 'A coupon object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( 'type' => array( 'non_null' => 'ID' ) ), - 'idType' => array( + 'args' => [ + 'id' => [ 'type' => [ 'non_null' => 'ID' ] ], + 'idType' => [ 'type' => 'CouponIdTypeEnum', 'description' => __( 'Type of ID being used identify coupon', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -124,20 +125,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $coupon_id, $context ); }, - ), - 'customer' => array( + ], + 'customer' => [ 'type' => 'Customer', 'description' => __( 'A customer object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'Get the customer by their global ID', 'wp-graphql-woocommerce' ), - ), - 'customerId' => array( + ], + 'customerId' => [ 'type' => 'Int', 'description' => __( 'Get the customer by their database ID', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $customer_id = 0; if ( ! empty( $args['id'] ) ) { @@ -164,20 +165,20 @@ public static function register_fields() { return Factory::resolve_session_customer(); }, - ), - 'order' => array( + ], + 'order' => [ 'type' => 'Order', 'description' => __( 'A order object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'The ID for identifying the order', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'OrderIdTypeEnum', 'description' => __( 'Type of ID being used identify order', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -209,17 +210,17 @@ public static function register_fields() { } // Check if user authorized to view order. - $post_type = get_post_type_object( 'shop_order' ); + $post_type = get_post_type_object( 'shop_order' ); $is_authorized = current_user_can( $post_type->cap->edit_others_posts ); if ( get_current_user_id() ) { $orders = wc_get_orders( - array( + [ 'type' => 'shop_order', - 'post__in' => array( $order_id ), + 'post__in' => [ $order_id ], 'customer_id' => get_current_user_id(), 'no_rows_found' => true, 'return' => 'ids', - ) + ] ); if ( in_array( $order_id, $orders, true ) ) { @@ -231,20 +232,20 @@ public static function register_fields() { return $order; }, - ), - 'productVariation' => array( + ], + 'productVariation' => [ 'type' => 'ProductVariation', 'description' => __( 'A product variation object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'The ID for identifying the product variation', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'ProductVariationIdTypeEnum', 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -274,20 +275,20 @@ public static function register_fields() { return Factory::resolve_crud_object( $variation_id, $context ); }, - ), - 'refund' => array( + ], + 'refund' => [ 'type' => 'Refund', 'description' => __( 'A refund object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'args' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The ID for identifying the refund', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'RefundIdTypeEnum', 'description' => __( 'Type of ID being used identify refund', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -316,19 +317,19 @@ public static function register_fields() { } // Check if user authorized to view order. - $post_type = get_post_type_object( 'shop_order_refund' ); + $post_type = get_post_type_object( 'shop_order_refund' ); $is_authorized = current_user_can( $post_type->cap->edit_others_posts ); if ( get_current_user_id() ) { $refund = \wc_get_order( $refund_id ); $order_id = $refund->get_parent_id(); $orders = wc_get_orders( - array( + [ 'type' => 'shop_order', - 'post__in' => array( $order_id ), + 'post__in' => [ $order_id ], 'customer_id' => get_current_user_id(), 'no_rows_found' => true, 'return' => 'ids', - ) + ] ); if ( in_array( $order_id, $orders, true ) ) { @@ -340,20 +341,20 @@ public static function register_fields() { return $refund; }, - ), - 'shippingMethod' => array( + ], + 'shippingMethod' => [ 'type' => 'ShippingMethod', 'description' => __( 'A shipping method object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'The ID for identifying the shipping method', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'ShippingMethodIdTypeEnum', 'description' => __( 'Type of ID being used identify product variation', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -375,20 +376,20 @@ public static function register_fields() { return Factory::resolve_shipping_method( $method_id ); }, - ), - 'taxRate' => array( + ], + 'taxRate' => [ 'type' => 'TaxRate', 'description' => __( 'A tax rate object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => __( 'The ID for identifying the tax rate', 'wp-graphql-woocommerce' ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'TaxRateIdTypeEnum', 'description' => __( 'Type of ID being used identify tax rate', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context ) { $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; @@ -410,17 +411,17 @@ public static function register_fields() { return Factory::resolve_tax_rate( $rate_id, $context ); }, - ), - ) + ], + ] ); // Product queries. $product_type_keys = apply_filters( 'woographql_register_product_queries', - array_keys( \WP_GraphQL_WooCommerce::get_enabled_product_types() ) + array_keys( WP_GraphQL_WooCommerce::get_enabled_product_types() ) ); - $product_types = \WP_GraphQL_WooCommerce::get_enabled_product_types(); + $product_types = WP_GraphQL_WooCommerce::get_enabled_product_types(); foreach ( $product_type_keys as $type_key ) { $field_name = "{$type_key}Product"; @@ -433,25 +434,25 @@ public static function register_fields() { register_graphql_field( 'RootQuery', $field_name, - array( + [ 'type' => $type_name, 'description' => __( 'A simple product object', 'wp-graphql-woocommerce' ), - 'args' => array( - 'id' => array( + 'args' => [ + 'id' => [ 'type' => 'ID', 'description' => sprintf( /* translators: %s: product type */ __( 'The ID for identifying the %s product', 'wp-graphql-woocommerce' ), $type_name ), - ), - 'idType' => array( + ], + 'idType' => [ 'type' => 'ProductIdTypeEnum', 'description' => __( 'Type of ID being used identify product', 'wp-graphql-woocommerce' ), - ), - ), + ], + ], 'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $type_key ) { - $id = isset( $args['id'] ) ? $args['id'] : null; + $id = isset( $args['id'] ) ? $args['id'] : null; $id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id'; $product_id = null; @@ -460,7 +461,7 @@ public static function register_fields() { $product_id = \wc_get_product_id_by_sku( $id ); break; case 'slug': - $post = get_page_by_path( $id, OBJECT, 'product' ); + $post = get_page_by_path( $id, OBJECT, 'product' ); $product_id = ! empty( $post ) ? absint( $post->ID ) : 0; break; case 'database_id': @@ -491,7 +492,7 @@ public static function register_fields() { return $product; }, - ) + ] ); }//end foreach } diff --git a/includes/type/object/class-shipping-method-type.php b/includes/type/object/class-shipping-method-type.php index 58d10ee95..afe03a323 100644 --- a/includes/type/object/class-shipping-method-type.php +++ b/includes/type/object/class-shipping-method-type.php @@ -25,28 +25,28 @@ class Shipping_Method_Type { public static function register() { register_graphql_object_type( 'ShippingMethod', - array( + [ 'description' => __( 'A shipping method object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Node' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Node' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( - 'type' => array( 'non_null' => 'ID' ), + ], + 'databaseId' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The ID of the shipping method in the database', 'wp-graphql-woocommerce' ), - ), - 'title' => array( + ], + 'title' => [ 'type' => 'String', 'description' => __( 'Shipping method title.', 'wp-graphql-woocommerce' ), - ), - 'description' => array( + ], + 'description' => [ 'type' => 'String', 'description' => __( 'Shipping method description.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-shipping-package-type.php b/includes/type/object/class-shipping-package-type.php index fb528dbe8..d91cee52e 100644 --- a/includes/type/object/class-shipping-package-type.php +++ b/includes/type/object/class-shipping-package-type.php @@ -21,14 +21,14 @@ class Shipping_Package_Type { public static function register() { register_graphql_object_type( 'ShippingPackage', - array( + [ 'description' => __( 'Shipping package object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'packageDetails' => array( + 'fields' => [ + 'packageDetails' => [ 'type' => 'String', 'description' => __( 'Shipping package details', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $product_names = array(); + $product_names = []; foreach ( $source['contents'] as $item_id => $values ) { $product_names[ $item_id ] = html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); } @@ -38,24 +38,24 @@ public static function register() { return implode( ', ', $product_names ); }, - ), - 'rates' => array( - 'type' => array( 'list_of' => 'ShippingRate' ), + ], + 'rates' => [ + 'type' => [ 'list_of' => 'ShippingRate' ], 'description' => __( 'Shipping package rates', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { return ! empty( $source['rates'] ) ? $source['rates'] : null; }, - ), - 'supportsShippingCalculator' => array( + ], + 'supportsShippingCalculator' => [ 'type' => 'Boolean', 'description' => __( 'This shipping package supports the shipping calculator.', 'wp-graphql-woocommerce' ), 'resolve' => 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 63f6540ec..bfcd25217 100644 --- a/includes/type/object/class-shipping-rate-type.php +++ b/includes/type/object/class-shipping-rate-type.php @@ -21,46 +21,46 @@ class Shipping_Rate_Type { public static function register() { register_graphql_object_type( 'ShippingRate', - array( + [ 'description' => __( 'Shipping rate object', 'wp-graphql-woocommerce' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Shipping rate ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, - ), - 'methodId' => array( - 'type' => array( 'non_null' => 'ID' ), + ], + 'methodId' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Shipping method ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->get_method_id() ) ? $source->get_method_id() : null; }, - ), - 'instanceId' => array( + ], + 'instanceId' => [ 'type' => 'Int', 'description' => __( 'Shipping instance ID', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->get_instance_id() ) ? $source->get_instance_id() : null; }, - ), - 'label' => array( + ], + 'label' => [ 'type' => 'String', 'description' => __( 'Shipping rate label', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->get_label() ) ? $source->get_label() : null; }, - ), - 'cost' => array( + ], + 'cost' => [ 'type' => 'String', 'description' => __( 'Shipping rate cost', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return ! empty( $source->get_cost() ) ? $source->get_cost() : null; }, - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-simple-attribute-type.php b/includes/type/object/class-simple-attribute-type.php index 1d76ed9e4..06815c922 100644 --- a/includes/type/object/class-simple-attribute-type.php +++ b/includes/type/object/class-simple-attribute-type.php @@ -21,11 +21,11 @@ class Simple_Attribute_Type { public static function register() { register_graphql_object_type( 'SimpleAttribute', - array( + [ 'description' => __( 'A simple attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Attribute' ), - 'fields' => array(), - ) + 'interfaces' => [ 'Attribute' ], + 'fields' => [], + ] ); } } diff --git a/includes/type/object/class-tax-rate-type.php b/includes/type/object/class-tax-rate-type.php index 58a14c61a..9dc58b369 100644 --- a/includes/type/object/class-tax-rate-type.php +++ b/includes/type/object/class-tax-rate-type.php @@ -26,64 +26,64 @@ class Tax_Rate_Type { public static function register() { register_graphql_object_type( 'TaxRate', - array( + [ 'description' => __( 'A Tax rate object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Node' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Node' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The globally unique identifier for the tax rate.', 'wp-graphql-woocommerce' ), - ), - 'databaseId' => array( + ], + 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - ), - 'country' => array( + ], + 'country' => [ 'type' => 'String', 'description' => __( 'Country ISO 3166 code.', 'wp-graphql-woocommerce' ), - ), - 'state' => array( + ], + 'state' => [ 'type' => 'String', 'description' => __( 'State code.', 'wp-graphql-woocommerce' ), - ), - 'postcode' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'postcode' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Postcode/ZIP.', 'wp-graphql-woocommerce' ), - ), - 'city' => array( - 'type' => array( 'list_of' => 'String' ), + ], + 'city' => [ + 'type' => [ 'list_of' => 'String' ], 'description' => __( 'City name.', 'wp-graphql-woocommerce' ), - ), - 'rate' => array( + ], + 'rate' => [ 'type' => 'String', 'description' => __( 'Tax rate.', 'wp-graphql-woocommerce' ), - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Tax rate name.', 'wp-graphql-woocommerce' ), - ), - 'priority' => array( + ], + 'priority' => [ 'type' => 'Int', 'description' => __( 'Tax priority.', 'wp-graphql-woocommerce' ), - ), - 'compound' => array( + ], + 'compound' => [ 'type' => 'Boolean', 'description' => __( 'Whether or not this is a compound rate.', 'wp-graphql-woocommerce' ), - ), - 'shipping' => array( + ], + 'shipping' => [ 'type' => 'Boolean', 'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'wp-graphql-woocommerce' ), - ), - 'order' => array( + ], + 'order' => [ 'type' => 'Int', 'description' => __( 'Indicates the order that will appear in queries.', 'wp-graphql-woocommerce' ), - ), - 'class' => array( + ], + 'class' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Tax class. Default is standard.', 'wp-graphql-woocommerce' ), - ), - ), - ) + ], + ], + ] ); } } diff --git a/includes/type/object/class-variation-attribute-type.php b/includes/type/object/class-variation-attribute-type.php index 6de129eb3..2b3cb23d4 100644 --- a/includes/type/object/class-variation-attribute-type.php +++ b/includes/type/object/class-variation-attribute-type.php @@ -21,25 +21,25 @@ class Variation_Attribute_Type { public static function register() { register_graphql_object_type( 'VariationAttribute', - array( + [ 'description' => __( 'A product variation attribute object', 'wp-graphql-woocommerce' ), - 'interfaces' => array( 'Attribute' ), - 'fields' => array( - 'id' => array( - 'type' => array( 'non_null' => 'ID' ), + 'interfaces' => [ 'Attribute' ], + 'fields' => [ + 'id' => [ + 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'The Global ID of the attribute.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return isset( $source['id'] ) ? $source['id'] : null; }, - ), - 'attributeId' => array( + ], + 'attributeId' => [ 'type' => 'Int', 'description' => __( 'The Database ID of the attribute.', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return isset( $source['attributeId'] ) ? $source['attributeId'] : null; }, - ), - 'label' => array( + ], + 'label' => [ 'type' => 'String', 'description' => __( 'Label of attribute', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { @@ -50,23 +50,23 @@ public static function register() { $slug = \wc_attribute_taxonomy_slug( $source['name'] ); return ucwords( str_replace( '_', ' ', $slug ) ); }, - ), - 'name' => array( + ], + 'name' => [ 'type' => 'String', 'description' => __( 'Name of attribute', 'wp-graphql-woocommerce' ), 'resolve' => function ( $source ) { return isset( $source['name'] ) ? $source['name'] : null; }, - ), - 'value' => array( + ], + 'value' => [ 'type' => 'String', 'description' => __( 'Selected value of attribute', 'wp-graphql-woocommerce' ), 'resolve' => 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 7e7150293..3bdf4e424 100644 --- a/includes/utils/class-ql-session-handler.php +++ b/includes/utils/class-ql-session-handler.php @@ -97,13 +97,13 @@ public function init() { $this->init_session_token(); $this->transaction_manager = Session_Transaction_Manager::get( $this ); - add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_token' ), 10 ); - add_action( 'graphql_after_resolve_field', array( $this, 'save_if_dirty' ), 10, 4 ); - add_action( 'shutdown', array( $this, 'save_data' ) ); - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); + add_action( 'woocommerce_set_cart_cookies', [ $this, 'set_customer_session_token' ], 10 ); + add_action( 'graphql_after_resolve_field', [ $this, 'save_if_dirty' ], 10, 4 ); + add_action( 'shutdown', [ $this, 'save_data' ] ); + add_action( 'wp_logout', [ $this, 'destroy_session' ] ); if ( ! is_user_logged_in() ) { - add_filter( 'nonce_user_logged_out', array( $this, 'maybe_update_nonce_user_logged_out' ), 10, 2 ); + add_filter( 'nonce_user_logged_out', [ $this, 'maybe_update_nonce_user_logged_out' ], 10, 2 ); } } @@ -262,15 +262,15 @@ public function build_token() { ); // Configure the token array, which will be encoded. - $token = array( + $token = [ 'iss' => get_bloginfo( 'url' ), 'iat' => $this->_session_issued, 'nbf' => $not_before, 'exp' => $this->_session_expiration, - 'data' => array( + 'data' => [ 'customer_id' => $this->_customer_id, - ), - ); + ], + ]; /** * Filter the token, allowing for individual systems to configure the token as needed @@ -371,7 +371,7 @@ public function forget_session() { unset( $this->_token_to_be_sent ); } wc_empty_cart(); - $this->_data = array(); + $this->_data = []; $this->_dirty = false; // Start new session. diff --git a/includes/utils/class-session-transaction-manager.php b/includes/utils/class-session-transaction-manager.php index 8fd56ab71..30705a619 100644 --- a/includes/utils/class-session-transaction-manager.php +++ b/includes/utils/class-session-transaction-manager.php @@ -64,8 +64,8 @@ public static function get( &$session_handler ) { public function __construct( &$session_handler ) { $this->session_handler = $session_handler; - add_action( 'graphql_before_resolve_field', array( $this, 'update_transaction_queue' ), 10, 4 ); - add_action( 'graphql_process_http_request_response', array( $this, 'pop_transaction_id' ), 20 ); + add_action( 'graphql_before_resolve_field', [ $this, 'update_transaction_queue' ], 10, 4 ); + add_action( 'graphql_process_http_request_response', [ $this, 'pop_transaction_id' ], 20 ); } /** @@ -91,7 +91,7 @@ public static function get_session_mutations() { */ return \apply_filters( 'woographql_session_mutations', - array( + [ 'addToCart', 'updateItemQuantities', 'addFee', @@ -103,7 +103,7 @@ public static function get_session_mutations() { 'updateItemQuantities', 'updateShippingMethod', 'updateCustomer', - ) + ] ); } @@ -184,7 +184,7 @@ public function get_transaction_queue() { // Get transaction queue. $transaction_queue = get_transient( "woo_session_transactions_queue_{$this->session_handler->get_customer_id()}" ); if ( ! $transaction_queue ) { - $transaction_queue = array(); + $transaction_queue = []; } // If transaction ID not in queue, add it, and start transaction. @@ -232,7 +232,7 @@ public function pop_transaction_id() { * * @param array $queue Transaction queue. */ - public function save_transaction_queue( $queue = array() ) { + public function save_transaction_queue( $queue = [] ) { // If queue empty delete transient and bail. if ( empty( $queue ) ) { delete_transient( "woo_session_transactions_queue_{$this->session_handler->get_customer_id()}" ); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4c548f9bb..0646b43bb 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -42,6 +42,12 @@ + + + + + + /tests/ diff --git a/tests/_support/Factory/CartFactory.php b/tests/_support/Factory/CartFactory.php index 351f54ed0..5e568e93e 100644 --- a/tests/_support/Factory/CartFactory.php +++ b/tests/_support/Factory/CartFactory.php @@ -22,7 +22,7 @@ class CartFactory { * @return array */ public function add( ...$products ) { - $keys = array(); + $keys = []; foreach ( $products as $product ) { if ( gettype( $product ) === 'array' ) { @@ -36,8 +36,8 @@ public function add( ...$products ) { $product['product_id'], ! empty( $product['quantity'] ) ? $product['quantity'] : 1, ! empty( $product['variation_id'] ) ? $product['variation_id'] : 0, - ! empty( $product['variation'] ) ? $product['variation'] : array(), - ! empty( $product['cart_item_data'] ) ? $product['cart_item_data'] : array() + ! empty( $product['variation'] ) ? $product['variation'] : [], + ! empty( $product['cart_item_data'] ) ? $product['cart_item_data'] : [] ); } else { WC()->cart->add_to_cart( $product, 1 ); diff --git a/tests/_support/Factory/CouponFactory.php b/tests/_support/Factory/CouponFactory.php index 469703684..4d0d0341d 100644 --- a/tests/_support/Factory/CouponFactory.php +++ b/tests/_support/Factory/CouponFactory.php @@ -17,9 +17,9 @@ class CouponFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'coupon_class' => '\WC_Coupon', - ); + ]; } public function create_object( $args ) { @@ -34,13 +34,13 @@ public function create_object( $args ) { $amount = Dummy::instance()->number( 0, 75 ); $coupon->set_props( array_merge( - array( + [ 'code' => $amount . 'off', 'amount' => floatval( $amount ), 'date_expires' => null, 'discount_type' => 'percent', 'description' => 'Test coupon', - ), + ], $args ) ); @@ -59,7 +59,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); diff --git a/tests/_support/Factory/CustomerFactory.php b/tests/_support/Factory/CustomerFactory.php index cac47a704..3acb6af2f 100644 --- a/tests/_support/Factory/CustomerFactory.php +++ b/tests/_support/Factory/CustomerFactory.php @@ -17,7 +17,7 @@ class CustomerFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array(); + $this->default_generation_definitions = []; $this->dummy = Dummy::instance(); } @@ -41,10 +41,10 @@ public function create_object( $args ) { $phone = $this->dummy->telephone(); $args = array_merge( - array( - 'billing' => array(), - 'shipping' => array(), - ), + [ + 'billing' => [], + 'shipping' => [], + ], $args ); @@ -70,7 +70,7 @@ public function create_object( $args ) { // Set data. $customer->set_props( array_merge( - array( + [ 'email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, @@ -78,7 +78,7 @@ public function create_object( $args ) { 'role' => 'customer', 'username' => $username, 'is_paying_customer' => false, - ), + ], $args ) ); @@ -97,7 +97,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); diff --git a/tests/_support/Factory/OrderFactory.php b/tests/_support/Factory/OrderFactory.php index f555778ab..319833b8a 100644 --- a/tests/_support/Factory/OrderFactory.php +++ b/tests/_support/Factory/OrderFactory.php @@ -17,7 +17,7 @@ class OrderFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'status' => '', 'customer_id' => 0, 'customer_note' => '', @@ -25,7 +25,7 @@ public function __construct( $factory = null ) { 'created_via' => '', 'cart_hash' => '', 'order_id' => 0, - ); + ]; } public function create_object( $args ) { @@ -50,7 +50,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); @@ -66,7 +66,7 @@ public function get_object_by_id( $id ) { return \wc_get_order( $id ); } - public function createNew( $args = array(), $items = array() ) { + public function createNew( $args = [], $items = [] ) { if ( ! isset( $args['customer_id'] ) ) { $customer = new \WC_Customer( $this->factory->customer->create() ); $args['customer_id'] = $customer->get_id(); @@ -88,10 +88,10 @@ public function createNew( $args = array(), $items = array() ) { for ( $i = 0; $i < $random_amount; $i++ ) { $order = $this->add_line_item( $order, - array( + [ 'product' => $this->factory->product->createSimple(), 'qty' => rand( 1, 6 ), - ), + ], false ); } @@ -107,12 +107,12 @@ public function createNew( $args = array(), $items = array() ) { $rate = new \WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' ); $item = new \WC_Order_Item_Shipping(); $item->set_props( - array( + [ 'method_title' => $rate->label, 'method_id' => $rate->id, 'total' => \wc_format_decimal( $rate->cost ), 'taxes' => $rate->taxes, - ) + ] ); foreach ( $rate->get_meta_data() as $key => $value ) { $item->add_meta_data( $key, $value, true ); @@ -140,7 +140,7 @@ public function createNew( $args = array(), $items = array() ) { } } - public function add_line_item( $order, $args = array(), $save = true ) { + public function add_line_item( $order, $args = [], $save = true ) { $order = $save ? \wc_get_order( $order ) : $order; if ( empty( $args['product'] ) ) { @@ -157,12 +157,12 @@ public function add_line_item( $order, $args = array(), $save = true ) { $item = new \WC_Order_Item_Product(); $item->set_props( - array( + [ 'product' => $product, 'quantity' => $qty, - 'subtotal' => \wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ), - 'total' => \wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ), - ) + 'subtotal' => \wc_get_price_excluding_tax( $product, [ 'qty' => $qty ] ), + 'total' => \wc_get_price_excluding_tax( $product, [ 'qty' => $qty ] ), + ] ); // Set meta data. @@ -179,22 +179,22 @@ public function add_line_item( $order, $args = array(), $save = true ) { $order->save(); } - public function add_shipping_line( $order, $args = array(), $save = true ) { + public function add_shipping_line( $order, $args = [], $save = true ) { $order = $save ? \wc_get_order( $order ) : $order; $this->factory->shipping_zone->createLegacyFlatRate(); $item = new WC_Order_Item_Shipping(); $item->set_props( array_merge( - array( + [ 'method_title' => 'Flat Rate', 'method_id' => 'flat_rate', 'total' => '', 'total_tax' => '', - 'taxes' => array( - 'total' => array(), - ), - ), + 'taxes' => [ + 'total' => [], + ], + ], $args ) ); @@ -223,7 +223,7 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { // Create new coupon if $coupon_id not passed. if ( empty( $coupon_id ) ) { // Get order product IDs - $product_ids = array(); + $product_ids = []; foreach ( $order->get_items() as $item ) { if ( ! in_array( $item->get_product_id(), $product_ids, true ) ) { $product_ids[] = $item->get_product_id(); @@ -231,7 +231,7 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { } $coupon = new \WC_Coupon( - $this->factory->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->factory->coupon->create( [ 'product_ids' => $product_ids ] ) ); } else { $coupon = new \WC_Coupon( $coupon_id ); @@ -249,19 +249,19 @@ public function add_coupon_line( $order, $coupon_id = 0, $save = true ) { $order->save(); } - public function add_fee( $order, $args = array(), $save = true ) { + public function add_fee( $order, $args = [], $save = true ) { $order = \wc_get_order( $order ); // Get thre customer country code. $country_code = $order->get_shipping_country(); // Set the array for tax calculations. - $calculate_tax_for = array( + $calculate_tax_for = [ 'country' => $country_code, 'state' => '', 'postcode' => '', 'city' => '', - ); + ]; $imported_total_fee = 8.4342; @@ -297,7 +297,7 @@ public function add_fee( $order, $args = array(), $save = true ) { $order->save(); } - public function add_tax( $order, $args = array(), $save = true ) { + public function add_tax( $order, $args = [], $save = true ) { $order = \wc_get_order( $order ); if ( empty( $args['rate_id'] ) ) { @@ -309,14 +309,14 @@ public function add_tax( $order, $args = array(), $save = true ) { $item = new \WC_Order_Item_Tax(); $item->set_props( array_merge( - array( + [ 'rate_id' => $rate_id, 'tax_total' => 100.66, 'shipping_tax_total' => 150.45, 'rate_code' => \WC_Tax::get_rate_code( $rate_id ), 'label' => \WC_Tax::get_rate_label( $rate_id ), 'compound' => \WC_Tax::is_compound( $rate_id ), - ), + ], $args ) ); diff --git a/tests/_support/Factory/ProductFactory.php b/tests/_support/Factory/ProductFactory.php index 2499d73b8..cf83e865e 100644 --- a/tests/_support/Factory/ProductFactory.php +++ b/tests/_support/Factory/ProductFactory.php @@ -17,9 +17,9 @@ class ProductFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'product_class' => '\WC_Product_Simple', - ); + ]; } public function create_object( $args ) { @@ -32,7 +32,7 @@ public function create_object( $args ) { $product = new $product_class(); foreach ( $args as $key => $value ) { - if ( is_callable( array( $product, "set_{$key}" ) ) ) { + if ( is_callable( [ $product, "set_{$key}" ] ) ) { $product->{"set_{$key}"}( $value ); } } @@ -50,7 +50,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s product field.', $field, $object->get_type() ) ); @@ -66,12 +66,12 @@ public function get_object_by_id( $product_id ) { return \wc_get_product( absint( $product_id ) ); } - public function createSimple( $args = array() ) { + public function createSimple( $args = [] ) { $name = Dummy::instance()->product(); $price = Dummy::instance()->price( 15, 200 ); $regular_price = $price; - $generation_definitions = array( + $generation_definitions = [ 'name' => $name, 'slug' => $this->slugify( $name ), 'regular_price' => $regular_price, @@ -86,16 +86,16 @@ public function createSimple( $args = array() ) { 'description' => '[shortcode_test]', 'short_description' => Dummy::instance()->sentence(), 'product_class' => '\WC_Product_Simple', - ); + ]; return $this->create( $args, $generation_definitions ); } - public function createExternal( $args = array() ) { + public function createExternal( $args = [] ) { $name = Dummy::instance()->product(); $price = Dummy::instance()->price( 15, 200 ); - $generation_definitions = array( + $generation_definitions = [ 'name' => $name, 'slug' => $this->slugify( $name ), 'regular_price' => $price, @@ -103,53 +103,53 @@ public function createExternal( $args = array() ) { 'product_url' => 'http://woocommerce.com', 'button_text' => 'Buy external product', 'product_class' => '\WC_Product_External', - ); + ]; return $this->create( $args, $generation_definitions ); } - public function createGrouped( $args = array() ) { + public function createGrouped( $args = [] ) { $name = Dummy::instance()->product() . 'Group'; - $generation_definitions = array( + $generation_definitions = [ 'name' => $name, 'slug' => $this->slugify( $name ), 'sku' => uniqid(), 'product_class' => '\WC_Product_Grouped', - ); + ]; $args = array_merge( - array( 'children' => array( $this->createSimple() ) ), + [ 'children' => [ $this->createSimple() ] ], $args ); return $this->create( $args, $generation_definitions ); } - public function createVariable( $args = array() ) { + public function createVariable( $args = [] ) { $name = Dummy::instance()->product(); - $generation_definitions = array( + $generation_definitions = [ 'name' => $name, 'slug' => $this->slugify( $name ), 'sku' => uniqid(), 'product_class' => '\WC_Product_Variable', - ); + ]; $args = array_merge( - array( - 'attribute_data' => array( - $this->createAttribute( 'size', array( 'small', 'medium', 'large' ) ), // Create Size attribute. - $this->createAttribute( 'color', array( 'red', 'blue', 'green' ) ), // Create Color attribute. - ), - ), + [ + 'attribute_data' => [ + $this->createAttribute( 'size', [ 'small', 'medium', 'large' ] ), // Create Size attribute. + $this->createAttribute( 'color', [ 'red', 'blue', 'green' ] ), // Create Color attribute. + ], + ], $args ); return $this->create( $args, $generation_definitions ); } - public function createAttribute( $raw_name = 'size', $terms = array( 'small' ) ) { + public function createAttribute( $raw_name = 'size', $terms = [ 'small' ] ) { global $wpdb, $wc_product_attributes; // Make sure caches are clean. @@ -170,35 +170,35 @@ public function createAttribute( $raw_name = 'size', $terms = array( 'small' ) ) $taxonomy_name = wc_attribute_taxonomy_name( $attribute_name ); $attribute_id = wc_create_attribute( - array( + [ 'name' => $raw_name, 'slug' => $attribute_name, 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => 0, - ) + ] ); // Register as taxonomy. register_taxonomy( $taxonomy_name, - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, array( 'product' ) ), + apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, [ 'product' ] ), apply_filters( 'woocommerce_taxonomy_args_' . $taxonomy_name, - array( - 'labels' => array( + [ + 'labels' => [ 'name' => $raw_name, - ), + ], 'hierarchical' => false, 'show_ui' => false, 'query_var' => true, 'rewrite' => false, - ) + ] ) ); // Set product attributes global. - $wc_product_attributes = array(); + $wc_product_attributes = []; foreach ( wc_get_attribute_taxonomies() as $taxonomy ) { $wc_product_attributes[ wc_attribute_taxonomy_name( $taxonomy->attribute_name ) ] = $taxonomy; @@ -206,12 +206,12 @@ public function createAttribute( $raw_name = 'size', $terms = array( 'small' ) ) } $attribute = wc_get_attribute( $attribute_id ); - $return = array( + $return = [ 'attribute_name' => $attribute->name, 'attribute_taxonomy' => $attribute->slug, 'attribute_id' => $attribute_id, - 'term_ids' => array(), - ); + 'term_ids' => [], + ]; foreach ( $terms as $term ) { $result = term_exists( $term, $attribute->slug ); @@ -227,8 +227,8 @@ public function createAttribute( $raw_name = 'size', $terms = array( 'small' ) ) return $return; } - private function setVariationAttributes( \WC_Product_Variable $product, array $attribute_data = array() ) { - $attributes = array(); + private function setVariationAttributes( \WC_Product_Variable $product, array $attribute_data = [] ) { + $attributes = []; foreach ( $attribute_data as $index => $data ) { $attribute = new \WC_Product_Attribute(); $attribute->set_id( $data['attribute_id'] ); @@ -243,30 +243,30 @@ private function setVariationAttributes( \WC_Product_Variable $product, array $a $product->set_attributes( $attributes ); } - public function createRelated( $args = array() ) { - $cross_sell_ids = array( + public function createRelated( $args = [] ) { + $cross_sell_ids = [ $this->createSimple(), $this->createSimple(), - ); - $upsell_ids = array( + ]; + $upsell_ids = [ $this->createSimple(), $this->createSimple(), - ); - $tag_ids = array( $this->createProductTag( 'related' ) ); - $related_product_id = $this->createSimple( array( 'tag_ids' => $tag_ids ) ); + ]; + $tag_ids = [ $this->createProductTag( 'related' ) ]; + $related_product_id = $this->createSimple( [ 'tag_ids' => $tag_ids ] ); - return array( + return [ 'product' => $this->createSimple( - array( + [ 'tag_ids' => $tag_ids, 'cross_sell_ids' => $cross_sell_ids, 'upsell_ids' => $upsell_ids, - ) + ] ), - 'related' => array( $related_product_id ), + 'related' => [ $related_product_id ], 'cross_sell' => $cross_sell_ids, 'upsell' => $upsell_ids, - ); + ]; } public function createProductTag( $term ) { @@ -280,11 +280,11 @@ public function createProductTag( $term ) { } public function getStockStatusEnum( $status ) { - $statuses = array( + $statuses = [ 'instock' => 'IN_STOCK', 'outofstock' => 'OUT_OF_STOCK', 'onbackorder' => 'ON_BACKORDER', - ); + ]; if ( in_array( $status, array_keys( $statuses ), true ) ) { return $statuses[ $status ]; @@ -297,7 +297,7 @@ public function createProductCategory( $term, $parent_id = 0 ) { if ( term_exists( $term, 'product_cat' ) ) { $term = get_term( $term, 'product_cat', ARRAY_A ); } else { - $args = array(); + $args = []; if ( $parent_id ) { $args['parent'] = $parent_id; } @@ -315,17 +315,17 @@ public function createDownload( $id = 0 ) { if ( $id ) { $product = \wc_get_product( $id ); - $product->set_downloads( array( $download ) ); + $product->set_downloads( [ $download ] ); $product->save(); } return $download; } - public function createReview( $product_id, $args = array() ) { + public function createReview( $product_id, $args = [] ) { $firstName = Dummy::instance()->firstname(); $data = array_merge( - array( + [ 'comment_post_ID' => $product_id, 'comment_author' => $firstName, 'comment_author_email' => "{$firstName}@example.com", @@ -333,7 +333,7 @@ public function createReview( $product_id, $args = array() ) { 'comment_content' => Dummy::instance()->text(), 'comment_approved' => 1, 'comment_type' => 'review', - ), + ], $args ); diff --git a/tests/_support/Factory/ProductVariationFactory.php b/tests/_support/Factory/ProductVariationFactory.php index e3ccbb9e8..b5660ee79 100644 --- a/tests/_support/Factory/ProductVariationFactory.php +++ b/tests/_support/Factory/ProductVariationFactory.php @@ -17,9 +17,9 @@ class ProductVariationFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'variation_class' => '\WC_Product_Variation', - ); + ]; } public function create_object( $args ) { @@ -49,7 +49,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s product field.', $field, $object->get_type() ) ); @@ -65,49 +65,49 @@ public function get_object_by_id( $product_id ) { return \wc_get_product( absint( $product_id ) ); } - public function createSome( $product = null, $args = array() ) { + public function createSome( $product = null, $args = [] ) { if ( ! $product ) { $product = $this->factory->product->createVariable(); } // Create variation stub data. - $variation_data = array( - array( - 'attributes' => array( 'pa_size' => 'small' ), + $variation_data = [ + [ + 'attributes' => [ 'pa_size' => 'small' ], 'image_id' => null, - 'downloads' => array( $this->factory->product->createDownload() ), + 'downloads' => [ $this->factory->product->createDownload() ], 'regular_price' => 10, - ), - array( - 'attributes' => array( 'pa_size' => 'medium' ), + ], + [ + 'attributes' => [ 'pa_size' => 'medium' ], 'image_id' => $this->factory->post->create( - array( + [ 'post_status' => 'publish', 'post_type' => 'attachment', 'post_content' => 'product image', - ) + ] ), - 'downloads' => array(), + 'downloads' => [], 'regular_price' => 15, - ), - array( - 'attributes' => array( 'pa_size' => 'large' ), + ], + [ + 'attributes' => [ 'pa_size' => 'large' ], 'image_id' => null, - 'downloads' => array(), + 'downloads' => [], 'regular_price' => 20, - ), - ); + ], + ]; - $variations = array(); + $variations = []; foreach ( $variation_data as $data ) { $args = array_merge( $data, $args ); $variation = $this->create_and_get( $args, - array( + [ 'parent_id' => $product, 'sku' => uniqid(), 'variation_class' => '\WC_Product_Variation', - ) + ] ); $variations[] = $variation->get_id(); diff --git a/tests/_support/Factory/RefundFactory.php b/tests/_support/Factory/RefundFactory.php index d831310bc..607b8f49e 100644 --- a/tests/_support/Factory/RefundFactory.php +++ b/tests/_support/Factory/RefundFactory.php @@ -17,13 +17,13 @@ class RefundFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'amount' => 0, 'order_id' => 0, 'reason' => 'defective', 'refund_payment' => false, 'restock_items' => false, - ); + ]; } public function create_object( $args ) { @@ -43,7 +43,7 @@ public function update_object( $object, $fields ) { } foreach ( $fields as $field => $field_value ) { - if ( ! is_callable( array( $object, "set_{$field}" ) ) ) { + if ( ! is_callable( [ $object, "set_{$field}" ] ) ) { throw new \Exception( sprintf( '"%1$s" is not a valid %2$s coupon field.', $field, $object->get_type() ) ); @@ -59,7 +59,7 @@ public function get_object_by_id( $id ) { return \wc_get_order( $id ); } - public function createNew( $order, $args = array() ) { + public function createNew( $order, $args = [] ) { $order = \wc_get_order( $order ); if ( empty( $order ) ) { @@ -68,13 +68,13 @@ public function createNew( $order, $args = array() ) { return $this->create( array_merge( - array( + [ 'amount' => floatval( $order->get_total() ), 'order_id' => $order->get_id(), 'reason' => 'defective', 'refund_payment' => false, 'restock_items' => false, - ), + ], $args ) ); diff --git a/tests/_support/Factory/ShippingZoneFactory.php b/tests/_support/Factory/ShippingZoneFactory.php index 7521b5804..7df6e1e3e 100644 --- a/tests/_support/Factory/ShippingZoneFactory.php +++ b/tests/_support/Factory/ShippingZoneFactory.php @@ -17,9 +17,9 @@ class ShippingZoneFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'zone_name' => '', - ); + ]; $this->dummy = Dummy::instance(); } @@ -31,7 +31,7 @@ public function create_object( $args ) { $object = new \WC_Shipping_Zone(); foreach ( $args as $key => $value ) { - if ( is_callable( array( $object, "set_{$key}" ) ) ) { + if ( is_callable( [ $object, "set_{$key}" ] ) ) { $object->{"set_{$key}"}( $value ); } } @@ -63,38 +63,38 @@ public function getAllZones() { return false; } - public function createLegacyFlatRate( $args = array() ) { + public function createLegacyFlatRate( $args = [] ) { $flat_rate_settings = array_merge( - array( + [ 'enabled' => 'yes', 'title' => 'Flat rate', 'availability' => 'all', 'countries' => '', 'tax_status' => 'taxable', 'cost' => '10', - ), + ], $args ); update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings ); - update_option( 'woocommerce_flat_rate', array() ); + update_option( 'woocommerce_flat_rate', [] ); \WC_Cache_Helper::get_transient_version( 'shipping', true ); \WC()->shipping()->load_shipping_methods(); return 'legacy_flat_rate'; } - public function createLegacyFreeShipping( $args = array() ) { + public function createLegacyFreeShipping( $args = [] ) { $free_shipping_settings = array_merge( - array( + [ 'enabled' => 'yes', 'title' => 'Free shipping', 'availability' => 'all', 'countries' => '', - ), + ], $args ); update_option( 'woocommerce_free_shipping_settings', $free_shipping_settings ); - update_option( 'woocommerce_free_shipping', array() ); + update_option( 'woocommerce_free_shipping', [] ); \WC_Cache_Helper::get_transient_version( 'shipping', true ); WC()->shipping()->load_shipping_methods(); diff --git a/tests/_support/Factory/TaxRateFactory.php b/tests/_support/Factory/TaxRateFactory.php index 9a9500b77..3b2e3794d 100644 --- a/tests/_support/Factory/TaxRateFactory.php +++ b/tests/_support/Factory/TaxRateFactory.php @@ -17,9 +17,9 @@ class TaxRateFactory extends \WP_UnitTest_Factory_For_Thing { public function __construct( $factory = null ) { parent::__construct( $factory ); - $this->default_generation_definitions = array( + $this->default_generation_definitions = [ 'zone_name' => '', - ); + ]; $this->dummy = Dummy::instance(); } @@ -28,8 +28,8 @@ public function create_object( $args ) { codecept_debug( $args ); } - $rate_args = array(); - $fields = array( + $rate_args = []; + $fields = [ 'country' => 'tax_rate_country', 'state' => 'tax_rate_state', 'rate' => 'tax_rate', @@ -39,7 +39,7 @@ public function create_object( $args ) { 'shipping' => 'tax_rate_shipping', 'order' => 'tax_rate_order', 'class' => 'tax_rate_class', - ); + ]; foreach ( $args as $key => $value ) { if ( in_array( $key, array_keys( $fields ), true ) ) { @@ -48,7 +48,7 @@ public function create_object( $args ) { } $rate_args = array_merge( - array( + [ 'tax_rate_country' => 'US', 'tax_rate_state' => '*', 'tax_rate' => 20.0000, @@ -57,7 +57,7 @@ public function create_object( $args ) { 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, 'tax_rate_order' => 0, - ), + ], $rate_args ); @@ -80,6 +80,7 @@ public function get_object_by_id( $id ) { } // Get locales from a tax rate. + // phpcs:ignore WordPress.DB.DirectDatabaseQuery $locales = $wpdb->get_results( $wpdb->prepare( "SELECT location_code, location_type @@ -91,7 +92,7 @@ public function get_object_by_id( $id ) { foreach ( $locales as $locale ) { if ( empty( $rate->{'tax_rate_' . $locale->location_type} ) ) { - $rate->{'tax_rate_' . $locale->location_type} = array(); + $rate->{'tax_rate_' . $locale->location_type} = []; } $rate->{'tax_rate_' . $locale->location_type}[] = $locale->location_code; } diff --git a/tests/_support/Helper/GraphQLE2E.php b/tests/_support/Helper/GraphQLE2E.php index dd1d91c25..da589030f 100644 --- a/tests/_support/Helper/GraphQLE2E.php +++ b/tests/_support/Helper/GraphQLE2E.php @@ -19,7 +19,7 @@ public function wantHTTPResponseHeaders( $headers ) { return $rest->grabHttpHeader( $headers ); } - $response_headers = array(); + $response_headers = []; foreach ( $headers as $header ) { $rest->seeHttpHeaderOnce( $header ); $response_headers[] = $rest->grabHttpHeader( $header ); @@ -33,7 +33,7 @@ public function wantHTTPResponseHeaders( $headers ) { * @param string $session_header * @return array */ - public function login( $input, $request_headers = array() ) { + public function login( $input, $request_headers = [] ) { $mutation = ' mutation ( $input: LoginInput! ) { login( input: $input ) { @@ -64,7 +64,7 @@ public function login( $input, $request_headers = array() ) { * * @return array */ - public function addToCart( $input, $request_headers = array() ) { + public function addToCart( $input, $request_headers = [] ) { // Add to cart mutation $mutation = ' mutation ( $input: AddToCartInput! ) { @@ -107,7 +107,7 @@ public function addToCart( $input, $request_headers = array() ) { * * @return array */ - public function updateItemQuantities( $input, $request_headers = array() ) { + public function updateItemQuantities( $input, $request_headers = [] ) { // Update cart items mutation $mutation = ' mutation updateItemQuantities( $input: UpdateItemQuantitiesInput! ) { @@ -143,7 +143,7 @@ public function updateItemQuantities( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function removeItemsFromCart( $input, $request_headers = array() ) { + public function removeItemsFromCart( $input, $request_headers = [] ) { // Remove item from cart mutation $mutation = ' mutation ( $input: RemoveItemsFromCartInput! ) { @@ -185,7 +185,7 @@ public function removeItemsFromCart( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function restoreCartItems( $input, $request_headers = array() ) { + public function restoreCartItems( $input, $request_headers = [] ) { $mutation = ' mutation restoreCartItems( $input: RestoreCartItemsInput! ) { restoreCartItems( input: $input ) { @@ -226,7 +226,7 @@ public function restoreCartItems( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function emptyCart( $input, $request_headers = array() ) { + public function emptyCart( $input, $request_headers = [] ) { $mutation = ' mutation emptyCart( $input: EmptyCartInput! ) { emptyCart( input: $input ) { @@ -271,7 +271,7 @@ public function emptyCart( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function addFee( $input, $request_headers = array() ) { + public function addFee( $input, $request_headers = [] ) { $mutation = ' mutation addFee( $input: AddFeeInput! ) { addFee( input: $input ) { @@ -302,7 +302,7 @@ public function addFee( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function applyCoupon( $input, $request_headers = array() ) { + public function applyCoupon( $input, $request_headers = [] ) { $mutation = ' mutation applyCoupon( $input: ApplyCouponInput! ) { applyCoupon( input: $input ) { @@ -345,7 +345,7 @@ public function applyCoupon( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function removeCoupons( $input, $request_headers = array() ) { + public function removeCoupons( $input, $request_headers = [] ) { $mutation = ' mutation removeCoupons( $input: RemoveCouponsInput! ) { removeCoupons( input: $input ) { @@ -386,7 +386,7 @@ public function removeCoupons( $input, $request_headers = array() ) { * @param string $session_header * @return array */ - public function updateShippingMethod( $input, $request_headers = array() ) { + public function updateShippingMethod( $input, $request_headers = [] ) { // updateShippingMethod mutation. $mutation = ' mutation ($input: UpdateShippingMethodInput!){ @@ -427,7 +427,7 @@ public function updateShippingMethod( $input, $request_headers = array() ) { * * @return array */ - public function checkout( $input, $request_headers = array() ) { + public function checkout( $input, $request_headers = [] ) { // Checkout mutation. $mutation = ' mutation checkout( $input: CheckoutInput! ) { @@ -611,7 +611,7 @@ public function checkout( $input, $request_headers = array() ) { * * @return array */ - public function sendGraphQLRequest( $query, $input, $request_headers = array() ) { + public function sendGraphQLRequest( $query, $input, $request_headers = [] ) { $rest = $this->getModule( 'REST' ); // Add item to cart. @@ -626,10 +626,10 @@ public function sendGraphQLRequest( $query, $input, $request_headers = array() ) $rest->sendPost( '/graphql', json_encode( - array( + [ 'query' => $query, - 'variables' => array( 'input' => $input ), - ) + 'variables' => [ 'input' => $input ], + ] ) ); @@ -662,44 +662,44 @@ public function sendGraphQLRequest( $query, $input, $request_headers = array() ) public function getCatalog() { $this->_setupStore(); - $product_catalog = array(); - $products = array( - array( + $product_catalog = []; + $products = [ + [ 'post_title' => 't-shirt', - 'meta_input' => array( + 'meta_input' => [ '_price' => 45, '_regular_price' => 45, - ), - ), - array( + ], + ], + [ 'post_title' => 'jeans', - 'meta_input' => array( + 'meta_input' => [ '_price' => 60, '_regular_price' => 60, - ), - ), - array( + ], + ], + [ 'post_title' => 'belt', - 'meta_input' => array( + 'meta_input' => [ '_price' => 45, '_regular_price' => 45, - ), - ), - array( + ], + ], + [ 'post_title' => 'shoes', - 'meta_input' => array( + 'meta_input' => [ '_price' => 115, '_regular_price' => 115, - ), - ), - array( + ], + ], + [ 'post_title' => 'socks', - 'meta_input' => array( + 'meta_input' => [ '_price' => 20, '_regular_price' => 20, - ), - ), - ); + ], + ], + ]; foreach ( $products as $product ) { $this->haveAProductInTheDatabase( $product, $product_id ); $product_catalog[ $product['post_title'] ] = $product_id; @@ -724,13 +724,13 @@ public function _setupStore() { // Enable payment gateway. update_option( 'woocommerce_bacs_settings', - array( + [ 'enabled' => 'yes', 'title' => 'Direct bank transfer', 'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'instructions' => 'Instructions that will be added to the thank you page and emails.', 'account' => '', - ) + ] ); // Additional cart fees. @@ -793,10 +793,10 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple' // Create Product $product_id = $wpdb->havePostInDatabase( array_replace_recursive( - array( + [ 'post_type' => 'product', 'post_title' => 't-shirt', - 'meta_input' => array( + 'meta_input' => [ '_visibility' => 'visible', '_sku' => '', '_price' => '100', @@ -817,38 +817,38 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple' '_length' => '', '_width' => '', '_height' => '', - '_upsell_ids' => array(), - '_cross_sell_ids' => array(), + '_upsell_ids' => [], + '_cross_sell_ids' => [], '_purchase_note' => '', - '_default_attributes' => array(), - '_product_attributes' => array(), + '_default_attributes' => [], + '_product_attributes' => [], '_virtual' => false, '_downloadable' => false, '_download_limit' => -1, '_download_expiry' => -1, '_featured' => false, - '_wc_rating_counts' => array(), + '_wc_rating_counts' => [], '_wc_average_rating' => 0, '_wc_review_count' => 0, - ), - ), + ], + ], $args ) ); if ( ! $term_id ) { $term_id = $wpdb->grabTermIdFromDatabase( - array( + [ 'name' => $term, 'slug' => $term, - ) + ] ); } $term_taxonomy_id = $wpdb->grabTermTaxonomyIdFromDatabase( - array( + [ 'term_id' => $term_id, 'taxonomy' => 'product_type', - ) + ] ); $wpdb->haveTermRelationshipInDatabase( $product_id, $term_id ); } @@ -861,10 +861,10 @@ public function setupStoreAndUsers() { $userId = $wpdb->haveUserInDatabase( 'jimbo1234', 'customer', - array( + [ 'user_pass' => 'password', 'user_email' => 'jimbo1234@example.com', - ) + ] ); } } diff --git a/tests/_support/Helper/Wpunit.php b/tests/_support/Helper/Wpunit.php index 97017bddb..7a7ab2768 100644 --- a/tests/_support/Helper/Wpunit.php +++ b/tests/_support/Helper/Wpunit.php @@ -29,10 +29,10 @@ public function _initialize() { */ public function _beforeSuite( $settings = null ) { $helper = $this->product(); - $helper->create_attribute( 'size', array( 'small', 'medium', 'large' ) ); - $helper->create_attribute( 'color', array( 'red', 'blue', 'green' ) ); + $helper->create_attribute( 'size', [ 'small', 'medium', 'large' ] ); + $helper->create_attribute( 'color', [ 'red', 'blue', 'green' ] ); codecept_debug( 'ATTRIBUTES_LOADED' ); - add_action( 'init_graphql_request', array( __CLASS__, 'shortcode_test_init' ) ); + add_action( 'init_graphql_request', [ __CLASS__, 'shortcode_test_init' ] ); codecept_debug( 'SHORTCODE_INITIALIZED' ); \Stripe\Stripe::setApiKey( defined( 'STRIPE_API_SECRET_KEY' ) ? STRIPE_API_SECRET_KEY : getenv( 'STRIPE_API_SECRET_KEY' ) @@ -80,12 +80,12 @@ public function tax_rate() { } public function get_nodes( $ids, $crud ) { - $nodes = array(); + $nodes = []; foreach ( $ids as $id ) { $nodes[] = $crud->get_query_data( $id ); } - return array( 'nodes' => $nodes ); + return [ 'nodes' => $nodes ]; } public function clear_loader_cache( $loader_name ) { @@ -94,7 +94,7 @@ public function clear_loader_cache( $loader_name ) { } public static function shortcode_test_init() { - add_shortcode( 'shortcode_test', array( __CLASS__, 'shortcode_test_handler' ) ); + add_shortcode( 'shortcode_test', [ __CLASS__, 'shortcode_test_handler' ] ); } public static function shortcode_test_handler( $atts ) { diff --git a/tests/_support/TestCase/WooGraphQLTestCase.php b/tests/_support/TestCase/WooGraphQLTestCase.php index 5b9ed924a..bd64e6722 100644 --- a/tests/_support/TestCase/WooGraphQLTestCase.php +++ b/tests/_support/TestCase/WooGraphQLTestCase.php @@ -35,7 +35,7 @@ public function setUp(): void { parent::setUp(); // Load factories. - $factories = array( + $factories = [ 'Product', 'ProductVariation', 'Cart', @@ -45,7 +45,7 @@ public function setUp(): void { 'TaxRate', 'Order', 'Refund', - ); + ]; foreach ( $factories as $factory ) { $factory_name = strtolower( preg_replace( '/\B([A-Z])/', '_$1', $factory ) ); @@ -56,7 +56,7 @@ public function setUp(): void { $this->factory->shipping_zone->createLegacyFlatRate(); // Create test users. - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); $this->customer = $this->factory->customer->create(); // For these tests, we are not concerned with Approved Download Directory functionality. diff --git a/tests/_support/Utils/Dummy.php b/tests/_support/Utils/Dummy.php index 7de0173d2..e8e841d35 100644 --- a/tests/_support/Utils/Dummy.php +++ b/tests/_support/Utils/Dummy.php @@ -39,7 +39,7 @@ public function all() { $fn = $this->firstname(); $ln = $this->lastname(); - $dump = array( + $dump = [ 'primaryText' => $this->words( 6 ), 'secondaryText' => $this->sentence(), 'userid' => $this->number(), @@ -66,13 +66,13 @@ public function all() { 'state' => $this->state(), 'zipcode' => $this->zipcode(), 'telephone' => $this->telephone(), - ); + ]; return( $dump ); } public function dump( $qty = 5 ) { - $a = array(); + $a = []; for ( $b = 0;$b < $qty;$b++ ) { $a[] = $this->all(); @@ -122,10 +122,10 @@ public function text( $min = 30, $max = 120, $nospaces = false ) { } public function words( $max = 5, $cmin = 2, $cmax = 6 ) { - $t = array(); + $t = []; for ( $a = 0; $a <= ( $max - 1 ); $a++ ) { - $t[] = str_replace( array( ',', '.' ), array( '', '' ), $this->text( $cmin, ( $cmax + 2 ), true ) ); + $t[] = str_replace( [ ',', '.' ], [ '', '' ], $this->text( $cmin, ( $cmax + 2 ), true ) ); } return( implode( ' ', $t ) ); @@ -143,7 +143,7 @@ public function number( $min = 10, $max = 1000 ) { } public function image( $w = 300, $h = 300 ) { - $c = array( 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ); + $c = [ 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ]; shuffle( $c ); $u = 'http://lorempixel.com/' . $w . '/' . $h . '/' . current( $c ); @@ -155,7 +155,7 @@ public function placeholder( $w = 300, $h = 300 ) { } public function price( $min = 2, $max = 500 ) { - $c = array( '00', '99', '49', '00', '50', '29' ); + $c = [ '00', '99', '49', '00', '50', '29' ]; shuffle( $c ); $p = rand( $min, $max ) . '.' . current( $c ); return( $p ); @@ -220,7 +220,7 @@ public function username() { public function email( $u = false ) { if ( ! $u ) { $u = $this->username(); } - $m = array( '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ); + $m = [ '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ]; shuffle( $m ); $m = current( $m ); @@ -241,7 +241,7 @@ public function city() { } public function state( $full = false ) { - $list = array( + $list = [ 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', @@ -293,7 +293,7 @@ public function state( $full = false ) { 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', - ); + ]; $abbv = array_rand( $list, 1 ); if ( $full ) { diff --git a/tests/acceptance/NewCustomerCheckingOutCept.php b/tests/acceptance/NewCustomerCheckingOutCept.php index 4c4cd962b..1ac45c8ac 100644 --- a/tests/acceptance/NewCustomerCheckingOutCept.php +++ b/tests/acceptance/NewCustomerCheckingOutCept.php @@ -5,9 +5,9 @@ // Make quick helper for managing the session token. $request_headers = function () use ( $I, &$last_request_headers ) { - $last_request_headers = array( + $last_request_headers = [ 'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ), - ); + ]; return $last_request_headers; }; @@ -18,11 +18,11 @@ /** * Add "T-Shirt" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['t-shirt'], 'quantity' => 3, -); +]; $success = $I->addToCart( $add_to_cart_input ); @@ -36,11 +36,11 @@ /** * Add "Belt" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['belt'], 'quantity' => 2, -); +]; $success = $I->addToCart( $add_to_cart_input, @@ -57,11 +57,11 @@ /** * Add "Jeans" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['jeans'], 'quantity' => 4, -); +]; $success = $I->addToCart( $add_to_cart_input, @@ -78,11 +78,11 @@ /** * Add "Socks" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['socks'], 'quantity' => 1, -); +]; $success = $I->addToCart( $add_to_cart_input, @@ -101,10 +101,10 @@ /** * Remove "Socks" from cart and confirm response data. */ -$remove_from_cart_input = array( +$remove_from_cart_input = [ 'clientMutationId' => 'someId', 'keys' => $socks_key, -); +]; $success = $I->removeItemsFromCart( $remove_from_cart_input, @@ -124,19 +124,19 @@ * - Change "Jeans" quantity to "1" * - Confirm response data. */ -$update_quantity_input = array( +$update_quantity_input = [ 'clientMutationId' => 'someId', - 'items' => array( - array( + 'items' => [ + [ 'key' => $belt_key, 'quantity' => 0, - ), - array( + ], + [ 'key' => $jeans_key, 'quantity' => 1, - ), - ), -); + ], + ], +]; $success = $I->updateItemQuantities( $update_quantity_input, @@ -162,11 +162,11 @@ /** * Place order for items in the cart using the "Checkout" mutation and confirm response data. */ -$checkout_input = array( +$checkout_input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => array( 'flat rate' ), - 'billing' => array( + 'shippingMethod' => [ 'flat rate' ], + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -176,8 +176,8 @@ 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -185,8 +185,8 @@ 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), -); + ], +]; $success = $I->checkout( $checkout_input, diff --git a/tests/acceptance/ReturningCustomerSessionCept.php b/tests/acceptance/ReturningCustomerSessionCept.php index 651346604..db168c842 100644 --- a/tests/acceptance/ReturningCustomerSessionCept.php +++ b/tests/acceptance/ReturningCustomerSessionCept.php @@ -7,11 +7,11 @@ // Begin Tests. $I->wantTo( 'login' ); -$login_input = array( +$login_input = [ 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -); +]; $success = $I->login( $login_input ); @@ -48,20 +48,20 @@ $response = $I->sendGraphQLRequest( $query, null, - array( + [ 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$initial_session_token}", - ) + ] ); -$expected_results = array( - 'data' => array( - 'customer' => array( +$expected_results = [ + 'data' => [ + 'customer' => [ 'databaseId' => $customer_id, 'username' => 'jimbo1234', - ), - ), -); + ], + ], +]; $I->assertEquals( $expected_results, $response ); @@ -70,18 +70,18 @@ /** * Add "T-Shirt" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['t-shirt'], 'quantity' => 3, -); +]; $success = $I->addToCart( $add_to_cart_input, - array( + [ 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$initial_session_token}", - ) + ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -113,29 +113,29 @@ $response = $I->sendGraphQLRequest( $cart_query, null, - array( + [ 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$initial_session_token}", - ) + ] ); -$expected_results = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( +$expected_results = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $shirt_key, - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'databaseId' => $product_catalog['t-shirt'], - ), - ), - ), - ), - ), - ), - ), -); + ], + ], + ], + ], + ], + ], + ], +]; $I->assertEquals( $expected_results, $response ); @@ -147,11 +147,11 @@ $I->wantTo( 'Login and continue previous session.' ); -$login_input = array( +$login_input = [ 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -); +]; $success = $I->login( $login_input ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -184,25 +184,25 @@ } '; -$response = $I->sendGraphQLRequest( $cart_query, null, array( 'Authorization' => "Bearer {$authToken}" ) ); -$expected_results = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( +$response = $I->sendGraphQLRequest( $cart_query, null, [ 'Authorization' => "Bearer {$authToken}" ] ); +$expected_results = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $shirt_key, - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'databaseId' => $product_catalog['t-shirt'], - ), - ), - ), - ), - ), - ), - ), -); + ], + ], + ], + ], + ], + ], + ], +]; $I->assertEquals( $expected_results, $response ); @@ -211,13 +211,13 @@ /** * Add "Belt" to cart and confirm response data. */ -$add_to_cart_input = array( +$add_to_cart_input = [ 'clientMutationId' => 'someId', 'productId' => $product_catalog['belt'], 'quantity' => 2, -); +]; -$success = $I->addToCart( $add_to_cart_input, array( 'Authorization' => "Bearer {$authToken}" ) ); +$success = $I->addToCart( $add_to_cart_input, [ 'Authorization' => "Bearer {$authToken}" ] ); $I->assertArrayNotHasKey( 'errors', $success ); $I->assertArrayHasKey( 'data', $success ); @@ -254,37 +254,37 @@ $response = $I->sendGraphQLRequest( $cart_query, null, - array( + [ 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$refreshed_session_token}", - ) + ] ); -$expected_results = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( +$expected_results = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $shirt_key, - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'databaseId' => $product_catalog['t-shirt'], - ), - ), - ), - array( + ], + ], + ], + [ 'key' => $belt_key, - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'databaseId' => $product_catalog['belt'], - ), - ), - ), - ), - ), - ), - ), -); + ], + ], + ], + ], + ], + ], + ], +]; $I->assertEquals( $expected_results, $response ); @@ -296,11 +296,11 @@ $I->wantTo( 'Login and start a new session.' ); -$login_input = array( +$login_input = [ 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', -); +]; $success = $I->login( $login_input ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -341,19 +341,19 @@ $response = $I->sendGraphQLRequest( $cart_query, null, - array( + [ 'Authorization' => "Bearer {$authToken}", 'woocommerce-session' => "Session {$new_session_token}", - ) -); -$expected_results = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array(), - ), - ), - ), + ] ); +$expected_results = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [], + ], + ], + ], +]; $I->assertEquals( $expected_results, $response ); diff --git a/tests/functional/CartTransactionQueueCest.php b/tests/functional/CartTransactionQueueCest.php index 977e24ad2..ffb03a6c9 100644 --- a/tests/functional/CartTransactionQueueCest.php +++ b/tests/functional/CartTransactionQueueCest.php @@ -8,16 +8,16 @@ public function _before( FunctionalTester $I ) { $this->product_catalog = $I->getCatalog(); } - public function _addTshirtToCart( FunctionalTester $I, $headers = array() ) { + public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) { /** * Add t-shirt to the cart */ $success = $I->addToCart( - array( + [ 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 5, - ), + ], $headers ); @@ -42,11 +42,11 @@ public function _startAuthenticatedSession( $I ) { // Begin Tests. $I->wantTo( 'login' ); - $login_input = array( + $login_input = [ 'clientMutationId' => 'someId', 'username' => 'jimbo1234', 'password' => 'password', - ); + ]; $success = $I->login( $login_input ); @@ -67,10 +67,10 @@ public function _startAuthenticatedSession( $I ) { // You can also retrieve the token from the "woocommerce-session" HTTP response header. $initial_session_token = $success['data']['login']['sessionToken']; - $headers = array( + $headers = [ 'Authorization' => "Bearer {$auth_token}", 'woocommerce-session' => "Session {$initial_session_token}", - ); + ]; extract( $this->_addTshirtToCart( $I, $headers ) ); @@ -145,124 +145,124 @@ public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester } '; - $requests = array( - array( + $requests = [ + [ 'query' => $update_item_quantities_mutation, - 'variables' => array( - 'input' => array( + 'variables' => [ + 'input' => [ 'clientMutationId' => 'some_id', - 'items' => array( - array( + 'items' => [ + [ 'key' => $key, 'quantity' => 3, - ), - ), - ), - ), - ), - array( + ], + ], + ], + ], + ], + [ 'query' => $update_item_quantities_mutation, - 'variables' => array( - 'input' => array( + 'variables' => [ + 'input' => [ 'clientMutationId' => 'some_id', - 'items' => array( - array( + 'items' => [ + [ 'key' => $key, 'quantity' => 4, - ), - ), - ), - ), - ), - array( + ], + ], + ], + ], + ], + [ 'query' => $remove_item_mutation, - 'variables' => array( - 'input' => array( + 'variables' => [ + 'input' => [ 'clientMutationId' => 'some_id', - 'keys' => array( $key ), - ), - ), - ), - array( + 'keys' => [ $key ], + ], + ], + ], + [ 'query' => $restore_item_mutation, - 'variables' => array( - 'input' => array( + 'variables' => [ + 'input' => [ 'clientMutationId' => 'some_id', - 'keys' => array( $key ), - ), - ), - ), - ); - $expected_responses = array( - array( - 'updateItemQuantities' => array( + 'keys' => [ $key ], + ], + ], + ], + ]; + $expected_responses = [ + [ + 'updateItemQuantities' => [ 'clientMutationId' => 'some_id', - 'updated' => array( - array( + 'updated' => [ + [ 'key' => $key, 'quantity' => 3, - ), - ), - 'removed' => array(), - 'items' => array( - array( + ], + ], + 'removed' => [], + 'items' => [ + [ 'key' => $key, 'quantity' => 3, - ), - ), - ), - ), - array( - 'updateItemQuantities' => array( + ], + ], + ], + ], + [ + 'updateItemQuantities' => [ 'clientMutationId' => 'some_id', - 'updated' => array( - array( + 'updated' => [ + [ 'key' => $key, 'quantity' => 4, - ), - ), - 'removed' => array(), - 'items' => array( - array( + ], + ], + 'removed' => [], + 'items' => [ + [ 'key' => $key, 'quantity' => 4, - ), - ), - ), - ), - array( - 'removeItemsFromCart' => array( + ], + ], + ], + ], + [ + 'removeItemsFromCart' => [ 'clientMutationId' => 'some_id', - 'cart' => array( - 'contents' => array( - 'nodes' => array(), - ), - ), - ), - ), - array( - 'restoreCartItems' => array( + 'cart' => [ + 'contents' => [ + 'nodes' => [], + ], + ], + ], + ], + [ + 'restoreCartItems' => [ 'clientMutationId' => 'some_id', - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $key, 'quantity' => 4, - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ]; $base_uri = getenv( 'WORDPRESS_URL' ) ? getenv( 'WORDPRESS_URL' ) : 'http://localhost'; - $headers = array( + $headers = [ 'Content-Type' => 'application/json', 'Authorization' => "Bearer ${auth_token}", 'woocommerce-session' => "Session {$session_token}", - ); + ]; $timeout = 300; $client = new \GuzzleHttp\Client( compact( 'base_uri', 'headers', 'timeout' ) ); @@ -287,7 +287,7 @@ public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester $pool = new \GuzzleHttp\Pool( $client, $iterator( $requests ), - array( + [ 'concurrency' => 5, 'fulfilled' => function ( $response, $index ) use ( $I, $expected_responses ) { \codecept_debug( "Finished session mutation request $index @ " . ( new \Carbon\Carbon() )->format( 'Y-m-d H:i:s' ) ); @@ -298,7 +298,7 @@ public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester \codecept_debug( $body ); $I->assertEquals( $expected, $body['data'] ); }, - ) + ] ); $promise = $pool->promise(); diff --git a/tests/functional/QLSessionHandlerCest.php b/tests/functional/QLSessionHandlerCest.php index e018e2785..493a0e7ec 100644 --- a/tests/functional/QLSessionHandlerCest.php +++ b/tests/functional/QLSessionHandlerCest.php @@ -20,11 +20,11 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I * Add item to the cart */ $success = $I->addToCart( - array( + [ 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 5, - ) + ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -73,20 +73,20 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $cart_item_key, - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $I->assertEquals( $expected, $actual ); @@ -94,11 +94,11 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I * Remove item from the cart */ $success = $I->removeItemsFromCart( - array( + [ 'clientMutationId' => 'someId', 'keys' => $cart_item_key, - ), - array( 'woocommerce-session' => "Session {$session_token}" ) + ], + [ 'woocommerce-session' => "Session {$session_token}" ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -123,16 +123,16 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array(), - ), - ), - ), - ); + $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [], + ], + ], + ], + ]; $I->assertEquals( $expected, $actual ); @@ -140,11 +140,11 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I * Restore item to the cart */ $success = $I->restoreCartItems( - array( + [ 'clientMutationId' => 'someId', - 'keys' => array( $cart_item_key ), - ), - array( 'woocommerce-session' => "Session {$session_token}" ) + 'keys' => [ $cart_item_key ], + ], + [ 'woocommerce-session' => "Session {$session_token}" ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -169,20 +169,20 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I } '; - $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $cart_item_key, - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $I->assertEquals( $expected, $actual ); } @@ -192,11 +192,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * Add item to cart and retrieve session token to corrupt. */ $success = $I->addToCart( - array( + [ 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 1, - ) + ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -226,12 +226,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ); $failed = $I->addToCart( - array( + [ 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['t-shirt'], 'quantity' => 1, - ), - array( 'woocommerce-session' => "Session {$invalid_token}" ) + ], + [ 'woocommerce-session' => "Session {$invalid_token}" ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -245,11 +245,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ); $failed = $I->removeItemsFromCart( - array( + [ 'clientMutationId' => 'someId', 'keys' => $cart_item_key, - ), - array( 'woocommerce-session' => "Session {$invalid_token}" ) + ], + [ 'woocommerce-session' => "Session {$invalid_token}" ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -259,16 +259,16 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->updateItemQuantities( - array( + [ 'clientMutationId' => 'someId', - 'items' => array( - array( + 'items' => [ + [ 'key' => $cart_item_key, 'quantity' => 0, - ), - ), - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + ], + ], + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -278,8 +278,8 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->emptyCart( - array( 'clientMutationId' => 'someId' ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + [ 'clientMutationId' => 'someId' ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -289,12 +289,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * GraphQL should throw an error and mutation will fail. */ $failed = $I->addFee( - array( + [ 'clientMutationId' => 'someId', 'name' => 'extra_fee', 'amount' => 49.99, - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -306,11 +306,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * @Note: No coupons exist in the database, but mutation should fail before that becomes a factor. */ $failed = $I->applyCoupon( - array( + [ 'clientMutationId' => 'someId', 'code' => 'some_coupon', - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -322,11 +322,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * @Note: No coupons exist on the cart, but mutation should failed before that becomes a factor. */ $failed = $I->removeCoupons( - array( + [ 'clientMutationId' => 'someId', - 'codes' => array( 'some_coupon' ), - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + 'codes' => [ 'some_coupon' ], + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -339,11 +339,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * but mutation should failed before that becomes a factor. */ $failed = $I->restoreCartItems( - array( + [ 'clientMutationId' => 'someId', - 'keys' => array( $cart_item_key ), - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + 'keys' => [ $cart_item_key ], + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -356,11 +356,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ * but mutation should failed before that becomes a factor. */ $failed = $I->updateShippingMethod( - array( + [ 'clientMutationId' => 'someId', - 'shippingMethods' => array( 'legacy_flat_rate' ), - ), - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + 'shippingMethods' => [ 'legacy_flat_rate' ], + ], + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -384,7 +384,7 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $ $failed = $I->sendGraphQLRequest( $query, null, - array( 'woocommerce-session' => 'Session invalid-jwt-token-string' ) + [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ] ); $I->assertArrayHasKey( 'errors', $failed ); @@ -395,11 +395,11 @@ public function testCartSessionDataMutations( FunctionalTester $I ) { * Add item to the cart */ $success = $I->addToCart( - array( + [ 'clientMutationId' => 'someId', 'productId' => $this->product_catalog['socks'], 'quantity' => 2, - ) + ] ); $I->assertArrayNotHasKey( 'errors', $success ); @@ -435,14 +435,14 @@ public function testCartSessionDataMutations( FunctionalTester $I ) { /** * Set shipping address, so shipping rates can be calculated */ - $input = array( + $input = [ 'clientMutationId' => 'someId', - 'shipping' => array( + 'shipping' => [ 'state' => 'New York', 'country' => 'US', 'postcode' => '12345', - ), - ); + ], + ]; $mutation = ' mutation ( $input: UpdateCustomerInput! ){ @@ -458,20 +458,20 @@ public function testCartSessionDataMutations( FunctionalTester $I ) { } '; - $actual = $I->sendGraphQLRequest( $mutation, $input, array( 'woocommerce-session' => "Session {$session_token}" ) ); - $expected = array( - 'data' => array( - 'updateCustomer' => array( - 'customer' => array( - 'shipping' => array( + $actual = $I->sendGraphQLRequest( $mutation, $input, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $expected = [ + 'data' => [ + 'updateCustomer' => [ + 'customer' => [ + 'shipping' => [ 'state' => 'New York', 'country' => 'US', 'postcode' => '12345', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; $I->assertEquals( $expected, $actual ); @@ -500,38 +500,38 @@ public function testCartSessionDataMutations( FunctionalTester $I ) { } '; - $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $cart_item_key, - ), - ), - ), - 'availableShippingMethods' => array( - array( + ], + ], + ], + 'availableShippingMethods' => [ + [ 'packageDetails' => \html_entity_decode( 'socks ×2' ), 'supportsShippingCalculator' => true, - 'rates' => array( - array( + 'rates' => [ + [ 'id' => 'flat_rate:7', 'cost' => '0.00', 'label' => 'Flat rate', - ), - array( + ], + [ 'id' => 'free_shipping:8', 'cost' => '0.00', 'label' => 'Free shipping', - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ]; $I->assertEquals( $expected, $actual ); @@ -564,11 +564,11 @@ public function testCartSessionDataMutations( FunctionalTester $I ) { $success = $I->sendGraphQLRequest( $mutation, - array( + [ 'clientMutationId' => 'someId', - 'shippingMethods' => array( 'flat_rate:7' ), - ), - array( 'woocommerce-session' => "Session {$session_token}" ) + 'shippingMethods' => [ 'flat_rate:7' ], + ], + [ 'woocommerce-session' => "Session {$session_token}" ] ); $I->assertArrayNotHasKey( 'errors', $success ); diff --git a/tests/wpunit/CartMutationsTest.php b/tests/wpunit/CartMutationsTest.php index 54f777b13..1de985588 100644 --- a/tests/wpunit/CartMutationsTest.php +++ b/tests/wpunit/CartMutationsTest.php @@ -31,13 +31,13 @@ public function testAddToCartMutationWithProduct() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'productId' => $product_id, 'quantity' => 2, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -55,7 +55,7 @@ public function testAddToCartMutationWithProduct() { $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'addToCart.clientMutationId', 'someId' ), $this->expectedField( 'addToCart.cartItem.key', $cart_item_key ), $this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'product', $product_id ) ), @@ -64,7 +64,7 @@ public function testAddToCartMutationWithProduct() { $this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ), $this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ), $this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ), - ) + ] ); } @@ -97,20 +97,20 @@ public function testAddToCartMutationWithProductVariation() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'productId' => $ids['product'], 'quantity' => 3, 'variationId' => $ids['variations'][0], - 'variation' => array( - array( + 'variation' => [ + [ 'attributeName' => 'color', 'attributeValue' => 'red', - ), - ), - ), - ); + ], + ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -128,7 +128,7 @@ public function testAddToCartMutationWithProductVariation() { $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'addToCart.clientMutationId', 'someId' ), $this->expectedField( 'addToCart.cartItem.key', $cart_item_key ), $this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'product', $ids['product'] ) ), @@ -138,26 +138,26 @@ public function testAddToCartMutationWithProductVariation() { $this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ), $this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ), $this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ), - ) + ] ); } public function testUpdateCartItemQuantitiesMutation() { // Create/add some products to the cart. - $cart_item_data = array( - array( + $cart_item_data = [ + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - ); + ], + ]; // Store cart item keys for use in mutation. $keys = $this->factory->cart->add( ...$cart_item_data ); @@ -184,95 +184,95 @@ public function testUpdateCartItemQuantitiesMutation() { '; // Define variables - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', - 'items' => array( - array( + 'items' => [ + [ 'key' => $keys[0], 'quantity' => 4, - ), - array( + ], + [ 'key' => $keys[1], 'quantity' => 2, - ), - array( + ], + [ 'key' => $keys[2], 'quantity' => 0, - ), - ), - ), - ); + ], + ], + ], + ]; // Execute mutation. $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'updateItemQuantities.clientMutationId', 'someId' ), $this->expectedNode( 'updateItemQuantities.updated', - array( + [ 'key' => $keys[0], 'quantity' => 4, - ) + ] ), $this->expectedNode( 'updateItemQuantities.updated', - array( + [ 'key' => $keys[1], 'quantity' => 2, - ) + ] ), $this->expectedNode( 'updateItemQuantities.removed', - array( + [ 'key' => $keys[2], 'quantity' => 1, - ) + ] ), $this->expectedNode( 'updateItemQuantities.items', - array( + [ 'key' => $keys[0], 'quantity' => 4, - ) + ] ), $this->expectedNode( 'updateItemQuantities.items', - array( + [ 'key' => $keys[1], 'quantity' => 2, - ) + ] ), $this->expectedNode( 'updateItemQuantities.items', - array( + [ 'key' => $keys[2], 'quantity' => 1, - ) + ] ), - ) + ] ); } public function testRemoveItemsFromCartMutation() { // Create/add some products to the cart. - $cart_item_data = array( - array( + $cart_item_data = [ + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - ); + ], + ]; // Store cart item keys for use in mutation. $keys = $this->factory->cart->add( ...$cart_item_data ); @@ -289,17 +289,17 @@ public function testRemoveItemsFromCartMutation() { '; // Define expected response data. - $expected = array( $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) ); + $expected = [ $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) ]; foreach ( $keys as $key ) { $expected[] = $this->expectedNode( 'removeItemsFromCart.cartItems', compact( 'key' ) ); } - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'keys' => $keys, - ), - ); + ], + ]; // Execute mutation w/ "keys" array. $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -317,12 +317,12 @@ public function testRemoveItemsFromCartMutation() { // Add more items and execute mutation with "all" flag. $keys = $this->factory->cart->add( ...$cart_item_data ); - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'all' => true, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); @@ -339,20 +339,20 @@ public function testRemoveItemsFromCartMutation() { public function testRestoreCartItemsMutation() { // Create/add some products to the cart. - $cart_item_data = array( - array( + $cart_item_data = [ + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 5, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - ); + ], + ]; $keys = $this->factory->cart->add( ...$cart_item_data ); $this->factory->cart->remove( ...$keys ); @@ -367,16 +367,16 @@ public function testRestoreCartItemsMutation() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'keys' => $keys, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) ); + $expected = [ $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) ]; foreach ( $keys as $key ) { $expected[] = $this->expectedNode( 'restoreCartItems.cartItems', compact( 'key' ) ); } @@ -429,33 +429,33 @@ public function testEmptyCartMutation() { } '; - $variables = array( - 'input' => array( 'clientMutationId' => 'someId' ), - ); + $variables = [ + 'input' => [ 'clientMutationId' => 'someId' ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'emptyCart.clientMutationId', 'someId' ), $this->expectedNode( 'emptyCart.deletedCart.contents.nodes', - array( + [ 'key' => $cart_item['key'], - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'id' => $this->toRelayId( 'product', $cart_item['product_id'] ), - ), - ), + ], + ], 'variation' => null, 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ) + ] ), - ) + ] ); $this->assertTrue( \WC()->cart->is_empty() ); @@ -464,17 +464,17 @@ public function testEmptyCartMutation() { public function testApplyCouponMutation() { // Create products. $product_id = $this->factory->product->createSimple( - array( 'regular_price' => 100 ) + [ 'regular_price' => 100 ] ); // Create coupon. $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( + [ 'amount' => 0.5, - 'product_ids' => array( $product_id ), + 'product_ids' => [ $product_id ], 'description' => 'lorem ipsum dolor', - ) + ] ) ); @@ -513,12 +513,12 @@ public function testApplyCouponMutation() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'code' => $coupon_code, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // Get updated cart item. @@ -526,42 +526,42 @@ public function testApplyCouponMutation() { $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'applyCoupon.clientMutationId', 'someId' ), $this->expectedNode( 'applyCoupon.cart.appliedCoupons', - array( + [ 'code' => $coupon_code, 'description' => 'lorem ipsum dolor', - ) + ] ), $this->expectedNode( 'applyCoupon.cart.contents.nodes', - array( + [ 'key' => $cart_item['key'], - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'id' => $this->toRelayId( 'product', $cart_item['product_id'] ), - ), - ), + ], + ], 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ) + ] ), - ) + ] ); $new_total = \WC()->cart->get_cart_contents_total(); // Use --debug to view. codecept_debug( - array( + [ 'old' => $old_total, 'new' => $new_total, - ) + ] ); $this->assertTrue( $old_total > $new_total ); @@ -575,19 +575,19 @@ public function testApplyCouponMutationWithInvalidCoupons() { // Create invalid coupon codes. $coupon_id = $this->factory->coupon->create( - array( 'product_ids' => array( $product_id ) ) + [ 'product_ids' => [ $product_id ] ] ); $expired_coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( - 'product_ids' => array( $product_id ), + [ + 'product_ids' => [ $product_id ], 'date_expires' => time() - 20, - ) + ] ) ); $applied_coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( 'product_ids' => array( $product_id ) ) + [ 'product_ids' => [ $product_id ] ] ) ); @@ -610,12 +610,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass coupon ID as coupon 'code'. Mutation should fail. */ - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'code' => '$coupon_id', - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -626,12 +626,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass expired coupon code. Mutation should fail. */ - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'code' => $expired_coupon_code, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -642,12 +642,12 @@ public function testApplyCouponMutationWithInvalidCoupons() { * * Can't pass coupon already applied to the cart. Mutation should fail. */ - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'code' => $applied_coupon_code, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertNotEmpty( $response['errors'] ); @@ -661,7 +661,7 @@ public function testRemoveCouponMutation() { $product_id = $this->factory->product->createSimple(); $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( 'product_ids' => array( $product_id ) ) + [ 'product_ids' => [ $product_id ] ] ) ); @@ -698,12 +698,12 @@ public function testRemoveCouponMutation() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', - 'codes' => array( $coupon_code ), - ), - ); + 'codes' => [ $coupon_code ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // Get updated cart item. @@ -711,26 +711,26 @@ public function testRemoveCouponMutation() { $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'removeCoupons.clientMutationId', 'someId' ), $this->expectedField( 'removeCoupons.cart.appliedCoupons', self::IS_NULL ), $this->expectedNode( 'removeCoupons.cart.contents.nodes', - array( + [ 'key' => $cart_item['key'], - 'product' => array( - 'node' => array( + 'product' => [ + 'node' => [ 'id' => $this->toRelayId( 'product', $cart_item['product_id'] ), - ), - ), + ], + ], 'quantity' => $cart_item['quantity'], 'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ), 'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ), 'total' => wc_graphql_price( $cart_item['line_total'] ), 'tax' => wc_graphql_price( $cart_item['line_tax'] ), - ) + ] ), - ) + ] ); } @@ -739,7 +739,7 @@ public function testAddFeeMutation() { $product_id = $this->factory->product->createSimple(); $coupon_code = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( 'product_ids' => array( $product_id ) ) + [ 'product_ids' => [ $product_id ] ] ) ); @@ -764,13 +764,13 @@ public function testAddFeeMutation() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'name' => 'extra_fee', 'amount' => 49.99, - ), - ); + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $response ); @@ -782,30 +782,30 @@ public function testAddFeeMutation() { $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'addFee.clientMutationId', 'someId' ), $this->expectedField( 'addFee.cartFee', - array( + [ 'id' => $fee->id, 'name' => $fee->name, 'taxClass' => ! empty( $fee->tax_class ) ? $fee->tax_class : null, 'taxable' => $fee->taxable, 'amount' => (float) $fee->amount, 'total' => (float) $fee->total, - ) + ] ), - ) + ] ); } public function testAddToCartMutationErrors() { // Create products. $product_id = $this->factory->product->createSimple( - array( + [ 'manage_stock' => true, 'stock_quantity' => 1, - ) + ] ); $variation_ids = $this->factory->product_variation->createSome(); @@ -813,7 +813,7 @@ public function testAddToCartMutationErrors() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( array( 'yes', 'no' ) ); + $attribute->set_options( [ 'yes', 'no' ] ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -849,25 +849,25 @@ public function testAddToCartMutationErrors() { '; \WC()->session->set( 'wc_notices', null ); - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'productId' => $variation_ids['product'], 'quantity' => 5, 'variationId' => $variation_ids['variations'][0], - ), - ); + ], + ]; $missing_attributes = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $missing_attributes ); \WC()->session->set( 'wc_notices', null ); - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'productId' => $product_id, 'quantity' => 5, - ), - ); + ], + ]; $not_enough_stock = $this->graphql( compact( 'query', 'variables' ) ); $this->assertArrayHasKey( 'errors', $not_enough_stock ); } @@ -879,7 +879,7 @@ public function testAddToCartMutationItemEdgeData() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( array( 'yes', 'no' ) ); + $attribute->set_options( [ 'yes', 'no' ] ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -906,48 +906,48 @@ public function testAddToCartMutationItemEdgeData() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', 'productId' => $variation_ids['product'], 'quantity' => 3, 'variationId' => $variation_ids['variations'][1], - 'variation' => array( - array( + 'variation' => [ + [ 'attributeName' => 'test', 'attributeValue' => 'yes', - ), - array( + ], + [ 'attributeName' => 'color', 'attributeValue' => 'green', - ), - ), - ), - ); + ], + ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedObject( 'addToCart.cartItem.product', - array( + [ $this->expectedField( 'node.databaseId', $variation_ids['product'] ), $this->expectedObject( 'simpleVariations.#', - array( + [ $this->expectedField( 'name', 'attribute_test' ), $this->expectedField( 'value', 'yes' ), - ) + ] ), $this->expectedObject( 'simpleVariations.#', - array( + [ $this->expectedField( 'name', 'attribute_pa_color' ), $this->expectedField( 'value', 'green' ), - ) + ] ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -959,7 +959,7 @@ public function testAddCartItemsMutationAndErrors() { $attribute = new WC_Product_Attribute(); $attribute->set_id( 0 ); $attribute->set_name( 'test' ); - $attribute->set_options( array( 'yes', 'no' ) ); + $attribute->set_options( [ 'yes', 'no' ] ); $attribute->set_position( 3 ); $attribute->set_visible( true ); $attribute->set_variation( true ); @@ -1000,118 +1000,118 @@ public function testAddCartItemsMutationAndErrors() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', - 'items' => array( - array( + 'items' => [ + [ 'productId' => $product_one, 'quantity' => 2, - ), - array( + ], + [ 'productId' => $variation_ids['product'], 'quantity' => 5, 'variationId' => $variation_ids['variations'][0], - ), - array( + ], + [ 'productId' => $invalid_product, 'quantity' => 4, - ), - array( + ], + [ 'productId' => $variation_ids['product'], 'quantity' => 3, 'variationId' => $variation_ids['variations'][1], - 'variation' => array( - array( + 'variation' => [ + [ 'attributeName' => 'test', 'attributeValue' => 'yes', - ), - array( + ], + [ 'attributeName' => 'color', 'attributeValue' => 'green', - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'addCartItems.clientMutationId', 'someId' ), $this->expectedNode( 'addCartItems.added', - array( - 'product' => array( - 'node' => array( 'databaseId' => $product_one ), - ), + [ + 'product' => [ + 'node' => [ 'databaseId' => $product_one ], + ], 'variation' => null, 'quantity' => 2, - ) + ] ), $this->expectedNode( 'addCartItems.added', - array( - 'product' => array( - 'node' => array( 'databaseId' => $variation_ids['product'] ), - ), - 'variation' => array( - 'node' => array( 'databaseId' => $variation_ids['variations'][1] ), - ), + [ + 'product' => [ + 'node' => [ 'databaseId' => $variation_ids['product'] ], + ], + 'variation' => [ + 'node' => [ 'databaseId' => $variation_ids['variations'][1] ], + ], 'quantity' => 3, - ) + ] ), $this->expectedNode( 'addCartItems.cartErrors', - array( + [ 'type' => 'INVALID_CART_ITEM', - 'reasons' => array( 'color and test are required fields' ), + 'reasons' => [ 'color and test are required fields' ], 'productId' => $variation_ids['product'], 'quantity' => 5, 'variationId' => $variation_ids['variations'][0], 'variation' => null, 'extraData' => null, - ) + ] ), $this->expectedNode( 'addCartItems.cartErrors', - array( + [ 'type' => 'INVALID_CART_ITEM', - 'reasons' => array( 'No product found matching the ID provided' ), + 'reasons' => [ 'No product found matching the ID provided' ], 'productId' => $invalid_product, 'quantity' => 4, 'variationId' => null, 'variation' => null, 'extraData' => null, - ) + ] ), - ) + ] ); } public function testFillCartMutationAndErrors() { // Create products. - $product_one = $this->factory->product->createSimple( array( 'regular_price' => 100 ) ); - $product_two = $this->factory->product->createSimple( array( 'regular_price' => 40 ) ); + $product_one = $this->factory->product->createSimple( [ 'regular_price' => 100 ] ); + $product_two = $this->factory->product->createSimple( [ 'regular_price' => 40 ] ); // Create coupons. $coupon_code_one = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( + [ 'amount' => 0.5, - 'product_ids' => array( $product_one ), - ) + 'product_ids' => [ $product_one ], + ] ) ); $coupon_code_two = wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( + [ 'amount' => 0.2, - 'product_ids' => array( $product_two ), - ) + 'product_ids' => [ $product_two ], + ] ) ); @@ -1164,62 +1164,62 @@ public function testFillCartMutationAndErrors() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'someId', - 'items' => array( - array( + 'items' => [ + [ 'productId' => $product_one, 'quantity' => 3, - ), - array( + ], + [ 'productId' => $product_two, 'quantity' => 2, - ), - array( + ], + [ 'productId' => $invalid_product, 'quantity' => 4, - ), - ), - 'coupons' => array( $coupon_code_one, $coupon_code_two, $invalid_coupon ), - 'shippingMethods' => array( 'legacy_flat_rate', $invalid_shipping_method ), - ), - ); + ], + ], + 'coupons' => [ $coupon_code_one, $coupon_code_two, $invalid_coupon ], + 'shippingMethods' => [ 'legacy_flat_rate', $invalid_shipping_method ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedObject( 'fillCart', - array( + [ $this->expectedField( 'clientMutationId', 'someId' ), $this->expectedObject( 'cart', - array( + [ $this->expectedField( 'chosenShippingMethods.0', 'legacy_flat_rate' ), $this->expectedObject( 'contents', - array( + [ $this->expectedNode( 'nodes', - array( + [ $this->expectedField( 'product.node.databaseId', $product_one ), $this->expectedField( 'quantity', 3 ), $this->expectedField( 'variation', self::IS_NULL ), - ) + ] ), $this->expectedNode( 'nodes', - array( + [ $this->expectedField( 'product.node.databaseId', $product_two ), $this->expectedField( 'quantity', 2 ), $this->expectedField( 'variation', self::IS_NULL ), - ) + ] ), - ) + ] ), $this->expectedNode( 'appliedCoupons', - array( + [ $this->expectedField( 'code', $coupon_code_one ), $this->expectedField( 'discountAmount', @@ -1229,11 +1229,11 @@ public function testFillCartMutationAndErrors() { 'discountTax', \wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_one ) ) ), - ) + ] ), $this->expectedNode( 'appliedCoupons', - array( + [ $this->expectedField( 'code', $coupon_code_two ), $this->expectedField( 'discountAmount', @@ -1243,38 +1243,38 @@ public function testFillCartMutationAndErrors() { 'discountTax', \wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_two ) ) ), - ) + ] ), - ) + ] ), $this->expectedNode( 'cartErrors', - array( + [ $this->expectedField( 'type', 'INVALID_CART_ITEM' ), - $this->expectedField( 'reasons', array( 'No product found matching the ID provided' ) ), + $this->expectedField( 'reasons', [ 'No product found matching the ID provided' ] ), $this->expectedField( 'productId', $invalid_product ), $this->expectedField( 'quantity', 4 ), - ) + ] ), $this->expectedNode( 'cartErrors', - array( + [ $this->expectedField( 'type', 'INVALID_COUPON' ), - $this->expectedField( 'reasons', array( "Coupon \"{$invalid_coupon}\" does not exist!" ) ), + $this->expectedField( 'reasons', [ "Coupon \"{$invalid_coupon}\" does not exist!" ] ), $this->expectedField( 'code', $invalid_coupon ), - ) + ] ), $this->expectedNode( 'cartErrors', - array( + [ $this->expectedField( 'type', 'INVALID_SHIPPING_METHOD' ), $this->expectedField( 'chosenMethod', $invalid_shipping_method ), $this->expectedField( 'package', 1 ), - ) + ] ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CartQueriesTest.php b/tests/wpunit/CartQueriesTest.php index 102da4e45..8b4c7a17b 100644 --- a/tests/wpunit/CartQueriesTest.php +++ b/tests/wpunit/CartQueriesTest.php @@ -8,7 +8,7 @@ private function key_to_cursor( $key ) { public function getExpectedCartData() { $cart = WC()->cart; - return array( + return [ $this->expectedField( 'cart.subtotal', \wc_graphql_price( $cart->get_subtotal() ) ), $this->expectedField( 'cart.subtotalTax', \wc_graphql_price( $cart->get_subtotal_tax() ) ), $this->expectedField( 'cart.discountTotal', \wc_graphql_price( $cart->get_discount_total() ) ), @@ -24,16 +24,16 @@ public function getExpectedCartData() { $this->expectedField( 'cart.isEmpty', $cart->is_empty() ), $this->expectedField( 'cart.displayPricesIncludeTax', $cart->display_prices_including_tax() ), $this->expectedField( 'cart.needsShippingAddress', $cart->needs_shipping_address() ), - ); + ]; } public function getExpectedCartItemData( $path, $cart_item_key ) { $cart = WC()->cart; $item = $cart->get_cart_item( $cart_item_key ); - return array( + return [ $this->expectedObject( $path, - array( + [ $this->expectedField( 'key', $item['key'] ), $this->expectedField( 'product.node.id', $this->toRelayId( 'product', $item['product_id'] ) ), $this->expectedField( 'product.node.databaseId', $item['product_id'] ), @@ -52,23 +52,23 @@ public function getExpectedCartItemData( $path, $cart_item_key ) { $this->expectedField( 'subtotalTax', \wc_graphql_price( $item['line_subtotal_tax'] ) ), $this->expectedField( 'total', \wc_graphql_price( $item['line_total'] ) ), $this->expectedField( 'tax', \wc_graphql_price( $item['line_tax'] ) ), - ) + ] ), - ); + ]; } // tests public function testCartQuery() { $cart = WC()->cart; $this->factory->cart->add( - array( + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ) + ] ); $query = ' @@ -115,7 +115,7 @@ public function testCartItemQuery() { $variations['product'], 3, $variations['variations'][0], - array( 'attribute_pa_color' => 'red' ) + [ 'attribute_pa_color' => 'red' ] ); $query = ' @@ -153,7 +153,7 @@ public function testCartItemQuery() { /** * Assertion One */ - $variables = array( 'key' => $key ); + $variables = [ 'key' => $key ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $this->getExpectedCartItemData( 'cartItem', $key ) ); @@ -161,28 +161,28 @@ public function testCartItemQuery() { public function testCartItemConnection() { $keys = $this->factory->cart->add( - array( + [ 'product_id' => $this->factory->product->createSimple( - array( 'virtual' => true ) + [ 'virtual' => true ] ), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 10, - ) + ] ); $code = \wc_get_coupon_code_by_id( $this->factory->coupon->create( - array( + [ 'amount' => 45.50, 'discount_type' => 'fixed_cart', - ) + ] ) ); $cart = \WC()->cart; @@ -206,9 +206,9 @@ public function testCartItemConnection() { $response = $this->graphql( compact( 'query' ) ); - $expected = array(); + $expected = []; foreach ( $keys as $key ) { - $expected[] = $this->expectedNode( 'cart.contents.nodes', array( 'key' => $key ) ); + $expected[] = $this->expectedNode( 'cart.contents.nodes', [ 'key' => $key ] ); } $this->assertQuerySuccessful( $response, $expected ); @@ -218,15 +218,15 @@ public function testCartItemConnection() { * * Tests "needsShipping" parameter. */ - $variables = array( 'needsShipping' => true ); + $variables = [ 'needsShipping' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( - $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[1] ) ), - $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[2] ) ), - ) + [ + $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[1] ] ), + $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[2] ] ), + ] ); /** @@ -234,14 +234,14 @@ public function testCartItemConnection() { * * Tests "needsShipping" parameter reversed. */ - $variables = array( 'needsShipping' => false ); + $variables = [ 'needsShipping' => false ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( - $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[0] ) ), - ) + [ + $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[0] ] ), + ] ); } @@ -267,21 +267,21 @@ public function testCartFeeQuery() { /** * Assertion One */ - $variables = array( 'id' => $fee_ids[0] ); + $variables = [ 'id' => $fee_ids[0] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $fee = ( \WC()->cart->get_fees() )[ $fee_ids[0] ]; $this->assertQuerySuccessful( $response, - array( + [ $this->expectedField( 'cartFee.id', $fee->id ), $this->expectedField( 'cartFee.name', $fee->name ), $this->expectedField( 'cartFee.taxClass', $this->maybe( $fee->tax_class ) ), $this->expectedField( 'cartFee.taxable', $fee->taxable ), $this->expectedField( 'cartFee.amount', (float) $fee->amount ), $this->expectedField( 'cartFee.total', (float) $fee->total ), - ) + ] ); } @@ -305,9 +305,9 @@ public function testCartToCartFeeQuery() { */ $response = $this->graphql( compact( 'query' ) ); - $expected = array(); + $expected = []; foreach ( \WC()->cart->get_fees() as $fee_id => $value ) { - $expected[] = $this->expectedNode( 'cart.fees', array( 'id' => $fee_id ) ); + $expected[] = $this->expectedNode( 'cart.fees', [ 'id' => $fee_id ] ); } $this->assertQuerySuccessful( $response, $expected ); @@ -315,26 +315,26 @@ public function testCartToCartFeeQuery() { public function testCartItemPagination() { $cart_items = $this->factory->cart->add( - array( + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 2, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ), - array( + ], + [ 'product_id' => $this->factory->product->createSimple(), 'quantity' => 1, - ) + ] ); $query = ' @@ -363,29 +363,29 @@ public function testCartItemPagination() { * * Tests "first" parameter. */ - $variables = array( + $variables = [ 'first' => 2, 'after' => '', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'cart.contents.itemCount', 6 ), $this->expectedField( 'cart.contents.productCount', 5 ), $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ), - $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ), - $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[1] ) ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[0] ) ), + [ $this->expectedField( 'key', $cart_items[0] ) ], 0 ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[1] ) ), + [ $this->expectedField( 'key', $cart_items[1] ) ], 1 ), - ); + $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ), + $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[1] ) ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -394,27 +394,27 @@ public function testCartItemPagination() { * * Tests "after" parameter. */ - $variables = array( + $variables = [ 'first' => 2, 'after' => $this->key_to_cursor( $cart_items[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[2] ) ), $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[3] ) ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[2] ) ), + [ $this->expectedField( 'key', $cart_items[2] ) ], 0 ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[3] ) ), + [ $this->expectedField( 'key', $cart_items[3] ) ], 1 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -423,24 +423,24 @@ public function testCartItemPagination() { * * Tests "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'cart.contents.pageInfo.hasNextPage', false ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ), - $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[3] ) ), - $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[4] ) ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[3] ) ), + [ $this->expectedField( 'key', $cart_items[3] ) ], 0 ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[4] ) ), + [ $this->expectedField( 'key', $cart_items[4] ) ], 1 ), - ); + $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[3] ) ), + $this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[4] ) ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -449,12 +449,12 @@ public function testCartItemPagination() { * * Tests "before" parameter. */ - $variables = array( + $variables = [ 'last' => 4, 'before' => $this->key_to_cursor( $cart_items[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ), $this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ), $this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ), @@ -462,20 +462,20 @@ public function testCartItemPagination() { $this->expectedField( 'cart.contents.edges.2.cursor', $this->key_to_cursor( $cart_items[2] ) ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[0] ) ), + [ $this->expectedField( 'key', $cart_items[0] ) ], 0 ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[1] ) ), + [ $this->expectedField( 'key', $cart_items[1] ) ], 1 ), $this->expectedEdge( 'cart.contents.edges', - array( $this->expectedField( 'key', $cart_items[2] ) ), + [ $this->expectedField( 'key', $cart_items[2] ) ], 2 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CheckoutMutationTest.php b/tests/wpunit/CheckoutMutationTest.php index 78f19a449..77f738e95 100644 --- a/tests/wpunit/CheckoutMutationTest.php +++ b/tests/wpunit/CheckoutMutationTest.php @@ -8,8 +8,8 @@ public function setUp(): void { parent::setUp(); // Create users. - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->simple_customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->simple_customer = $this->factory->user->create( [ 'role' => 'customer' ] ); // Get helper instances $this->order = $this->getModule( '\Helper\Wpunit' )->order(); @@ -29,18 +29,18 @@ public function setUp(): void { // Enable payment gateways. update_option( 'woocommerce_bacs_settings', - array( + [ 'enabled' => 'yes', 'title' => 'Direct bank transfer', 'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'instructions' => 'Instructions that will be added to the thank you page and emails.', 'account' => '', - ) + ] ); update_option( 'woocommerce_stripe_settings', - array( + [ 'enabled' => 'yes', 'title' => 'Credit Card (Stripe)', 'description' => 'Pay with your credit card via Stripe', @@ -65,7 +65,7 @@ public function setUp(): void { 'payment_request_button_height' => '44', 'saved_cards' => 'yes', 'logging' => 'no', - ) + ] ); // Additional cart fees. @@ -80,7 +80,7 @@ function() { // Create a tax rate. $this->tax->create( - array( + [ 'country' => '', 'state' => '', 'rate' => 20.000, @@ -89,7 +89,7 @@ function() { 'compound' => '0', 'shipping' => '1', 'class' => '', - ) + ] ); // Create sample order to be used as a parent order. $this->order_id = $this->order->create(); @@ -279,11 +279,11 @@ private function checkout( $input, $mutation = null ) { } $actual = graphql( - array( + [ 'query' => $mutation, 'operation_name' => 'checkout', - 'variables' => array( 'input' => $input ), - ) + 'variables' => [ 'input' => $input ], + ] ); return $actual; @@ -295,13 +295,13 @@ public function testCheckoutMutation() { WC()->customer->set_billing_company( 'Harris Teeter' ); $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); WC()->cart->add_to_cart( $product_ids[0], 3 ); @@ -310,16 +310,16 @@ public function testCheckoutMutation() { $product_ids[2], 2, $variable['variations'][0], - array( 'attribute_pa_color' => 'red' ) + [ 'attribute_pa_color' => 'red' ] ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => array( 'flat rate' ), + 'shippingMethod' => [ 'flat rate' ], 'customerNote' => 'Test customer note', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -330,8 +330,8 @@ public function testCheckoutMutation() { 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', 'overwrite' => true, - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -339,14 +339,14 @@ public function testCheckoutMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - 'metaData' => array( - array( + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'test value', - ), - ), - ); + ], + ], + ]; /** * Assertion One @@ -367,49 +367,49 @@ public function testCheckoutMutation() { // Get Available payment gateways. $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); - $expected = array( - 'data' => array( - 'checkout' => array( + $expected = [ + 'data' => [ + 'checkout' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'metaData' => array( - array( + [ + 'metaData' => [ + [ 'key' => 'is_vat_exempt', 'value' => 'no', - ), - array( + ], + [ 'key' => 'test_key', 'value' => 'test value', - ), + ], // array( // 'key' => '_new_order_email_sent', // 'value' => 'true' // ) - ), - 'couponLines' => array( + ], + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, 'coupon' => null, - ); + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -420,17 +420,17 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( + ], + 'shippingLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -443,34 +443,34 @@ function( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'shipping' ) ) ), - ), - 'taxLines' => array( + ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -484,43 +484,43 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), - 'customer' => array( + 'customer' => [ 'id' => $this->customer->to_relay_id( $order->get_customer_id() ), - ), + ], 'result' => 'success', 'redirect' => $available_gateways['bacs']->process_payment( $order->get_id() )['redirect'], - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } public function testCheckoutMutationWithNewAccount() { $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); WC()->cart->add_to_cart( $product_ids[0], 3 ); WC()->cart->add_to_cart( $product_ids[1], 6 ); @@ -528,15 +528,15 @@ public function testCheckoutMutationWithNewAccount() { $product_ids[2], 2, $variable['variations'][0], - array( 'attribute_pa_color' => 'red' ) + [ 'attribute_pa_color' => 'red' ] ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => array( 'flat rate' ), - 'billing' => array( + 'shippingMethod' => [ 'flat rate' ], + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'company' => 'Harris Teeter', @@ -547,12 +547,12 @@ public function testCheckoutMutationWithNewAccount() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'account' => array( + ], + 'account' => [ 'username' => 'test_user_1', 'password' => 'test_pass', - ), - ); + ], + ]; /** * Assertion One @@ -573,41 +573,41 @@ public function testCheckoutMutationWithNewAccount() { // Get Available payment gateways. $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); - $expected = array( - 'data' => array( - 'checkout' => array( + $expected = [ + 'data' => [ + 'checkout' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'metaData' => array( - array( + [ + 'metaData' => [ + [ 'key' => 'is_vat_exempt', 'value' => 'no', - ), - ), - 'couponLines' => array( + ], + ], + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, 'coupon' => null, - ); + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -618,17 +618,17 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( + ], + 'shippingLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -641,34 +641,34 @@ function( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'shipping' ) ) ), - ), - 'taxLines' => array( + ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -682,30 +682,30 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), - 'customer' => array( + 'customer' => [ 'id' => $this->customer->to_relay_id( $order->get_customer_id() ), - ), + ], 'result' => 'success', 'redirect' => $available_gateways['bacs']->process_payment( $order->get_id() )['redirect'], - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -713,13 +713,13 @@ function( $item ) { public function testCheckoutMutationWithNoAccount() { update_option( 'woocommerce_enable_guest_checkout', 'yes' ); $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); WC()->cart->add_to_cart( $product_ids[0], 3 ); WC()->cart->add_to_cart( $product_ids[1], 6 ); @@ -727,15 +727,15 @@ public function testCheckoutMutationWithNoAccount() { $product_ids[2], 2, $variable['variations'][0], - array( 'attribute_pa_color' => 'red' ) + [ 'attribute_pa_color' => 'red' ] ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => array( 'flat rate' ), - 'billing' => array( + 'shippingMethod' => [ 'flat rate' ], + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -745,8 +745,8 @@ public function testCheckoutMutationWithNoAccount() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -754,8 +754,8 @@ public function testCheckoutMutationWithNoAccount() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - ); + ], + ]; /** * Assertion One @@ -776,41 +776,41 @@ public function testCheckoutMutationWithNoAccount() { // Get Available payment gateways. $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); - $expected = array( - 'data' => array( - 'checkout' => array( + $expected = [ + 'data' => [ + 'checkout' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'metaData' => array( - array( + [ + 'metaData' => [ + [ 'key' => 'is_vat_exempt', 'value' => 'no', - ), - ), - 'couponLines' => array( + ], + ], + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, 'coupon' => null, - ); + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -821,17 +821,17 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( + ], + 'shippingLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -844,34 +844,34 @@ function( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'shipping' ) ) ), - ), - 'taxLines' => array( + ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -885,62 +885,62 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), 'customer' => null, 'result' => 'success', 'redirect' => $available_gateways['bacs']->process_payment( $order->get_id() )['redirect'], - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } public function testCheckoutMutationWithPrepaidOrder() { update_option( 'woocommerce_enable_guest_checkout', 'yes' ); - $product_ids = array( + $product_ids = [ $this->product->create_simple( - array( + [ 'virtual' => true, 'downloadable' => true, - ) + ] ), $this->product->create_simple( - array( + [ 'virtual' => true, 'downloadable' => true, - ) + ] ), - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); WC()->cart->add_to_cart( $product_ids[0], 3 ); WC()->cart->add_to_cart( $product_ids[1], 6 ); WC()->cart->apply_coupon( $coupon->get_code() ); - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', 'isPaid' => true, 'transactionId' => 'transaction_id', - 'shippingMethod' => array( 'flat rate' ), - 'billing' => array( + 'shippingMethod' => [ 'flat rate' ], + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -950,8 +950,8 @@ public function testCheckoutMutationWithPrepaidOrder() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -959,8 +959,8 @@ public function testCheckoutMutationWithPrepaidOrder() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - ); + ], + ]; /** * Assertion One @@ -982,41 +982,41 @@ public function testCheckoutMutationWithPrepaidOrder() { // Get Available payment gateways. $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); - $expected = array( - 'data' => array( - 'checkout' => array( + $expected = [ + 'data' => [ + 'checkout' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'metaData' => array( - array( + [ + 'metaData' => [ + [ 'key' => 'is_vat_exempt', 'value' => 'no', - ), - ), - 'couponLines' => array( + ], + ], + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, 'coupon' => null, - ); + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -1027,35 +1027,35 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( 'nodes' => array() ), - 'taxLines' => array( + ], + 'shippingLines' => [ 'nodes' => [] ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -1069,28 +1069,28 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), 'customer' => null, 'result' => 'success', 'redirect' => $available_gateways['bacs']->process_payment( $order->get_id() )['redirect'], - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -1103,7 +1103,7 @@ function( $item ) { * @return array */ private function create_stripe_customer( $email ) { - $customer = \Stripe\Customer::create( array( 'email' => $email ) ); + $customer = \Stripe\Customer::create( [ 'email' => $email ] ); // use --debug flag to view. codecept_debug( $customer ); @@ -1121,7 +1121,7 @@ private function create_stripe_customer( $email ) { private function create_stripe_source( $customer ) { $source = \Stripe\Customer::createSource( $customer['id'], - array( 'source' => 'tok_visa' ) + [ 'source' => 'tok_visa' ] ); // use --debug flag to view. @@ -1143,13 +1143,13 @@ private function create_stripe_source( $customer ) { */ private function create_stripe_payment_intent( $amount, $customer ) { $payment_intent = \Stripe\PaymentIntent::create( - array( + [ 'amount' => $amount, 'currency' => 'gbp', - 'payment_method_types' => array( 'card' ), + 'payment_method_types' => [ 'card' ], 'customer' => $customer['id'], 'payment_method' => $customer['invoice_settings']['default_payment_method'], - ) + ] ); // use --debug flag to view. @@ -1161,10 +1161,10 @@ private function create_stripe_payment_intent( $amount, $customer ) { public function testCheckoutMutationWithStripe() { update_option( 'woocommerce_enable_guest_checkout', 'yes' ); // Add items to the cart. - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), - ); + ]; WC()->cart->add_to_cart( $product_ids[0], 3 ); WC()->cart->add_to_cart( $product_ids[1], 6 ); @@ -1178,11 +1178,11 @@ public function testCheckoutMutationWithStripe() { $this->markTestSkipped( $e->getMessage() ); } - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'stripe', 'shippingMethod' => 'flat rate', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -1192,22 +1192,22 @@ public function testCheckoutMutationWithStripe() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'metaData' => array( - array( + ], + 'metaData' => [ + [ 'key' => '_stripe_source_id', 'value' => $stripe_source['id'], - ), - array( + ], + [ 'key' => '_stripe_customer_id', 'value' => $stripe_customer['id'], - ), - array( + ], + [ 'key' => '_stripe_intent_id', 'value' => $payment_intent['id'], - ), - ), - ); + ], + ], + ]; // Remove "metaData" value field and "redirect" link from the mutation output. $modified_mutation = ' @@ -1268,27 +1268,27 @@ public function testCheckoutMutationWithStripe() { // Get Available payment gateways. $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); - $expected = array( - 'data' => array( - 'checkout' => array( + $expected = [ + 'data' => [ + 'checkout' => [ 'clientMutationId' => 'someId', - 'order' => array( + 'order' => [ 'databaseId' => $order->get_id(), - 'metaData' => array( - array( 'key' => 'is_vat_exempt' ), - array( 'key' => '_stripe_source_id' ), - array( 'key' => '_stripe_customer_id' ), - array( 'key' => '_stripe_intent_id' ), - array( 'key' => '_stripe_charge_captured' ), - array( 'key' => '_stripe_fee' ), - array( 'key' => '_stripe_net' ), - array( 'key' => '_stripe_currency' ), - ), - 'lineItems' => array( + 'metaData' => [ + [ 'key' => 'is_vat_exempt' ], + [ 'key' => '_stripe_source_id' ], + [ 'key' => '_stripe_customer_id' ], + [ 'key' => '_stripe_intent_id' ], + [ 'key' => '_stripe_charge_captured' ], + [ 'key' => '_stripe_fee' ], + [ 'key' => '_stripe_net' ], + [ 'key' => '_stripe_currency' ], + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -1302,25 +1302,25 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ), + ], + ], 'result' => 'success', - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -1329,10 +1329,10 @@ public function testCheckoutMutationCartItemValidation() { add_filter( 'woocommerce_hold_stock_for_checkout', '__return_false' ); $product_id = $this->product->create_simple( - array( + [ 'manage_stock' => true, 'stock_quantity' => 3, - ) + ] ); $key = WC()->cart->add_to_cart( $product_id, 3 ); @@ -1343,11 +1343,11 @@ public function testCheckoutMutationCartItemValidation() { * * Ensure that checkout failed when stock is too low. */ - $input = array( + $input = [ 'clientMutationId' => 'someId', 'paymentMethod' => 'bacs', - 'shippingMethod' => array( 'flat rate' ), - 'billing' => array( + 'shippingMethod' => [ 'flat rate' ], + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'company' => 'Harris Teeter', @@ -1358,12 +1358,12 @@ public function testCheckoutMutationCartItemValidation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'account' => array( + ], + 'account' => [ 'username' => 'test_user_1', 'password' => 'test_pass', - ), - ); + ], + ]; $failed = $this->checkout( $input ); // use --debug flag to view. diff --git a/tests/wpunit/ConnectionPaginationTest.php b/tests/wpunit/ConnectionPaginationTest.php index bcff63a5f..4b36d7b65 100644 --- a/tests/wpunit/ConnectionPaginationTest.php +++ b/tests/wpunit/ConnectionPaginationTest.php @@ -14,13 +14,13 @@ public function toCursor( $id ) { // tests public function testCouponsPagination() { - $coupons = array( + $coupons = [ $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), $this->factory->coupon->create(), - ); + ]; usort( $coupons, @@ -52,16 +52,16 @@ function( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'coupons.pageInfo.hasPreviousPage', false ), $this->expectedField( 'coupons.pageInfo.hasNextPage', true ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[0] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[1] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[0] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[1] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -70,12 +70,12 @@ function( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $coupons[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', false ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[2] ) ), @@ -83,7 +83,7 @@ function( $key_a, $key_b ) { $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[2] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[3] ), $this->expectedField( 'coupons.nodes.2.databaseId', $coupons[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -93,18 +93,18 @@ function( $key_a, $key_b ) { * Test "last" parameter. */ \WPGraphQL::set_is_graphql_request( true ); - $variables = array( + $variables = [ 'last' => 2, - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', false ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[3] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[4] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[3] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[4] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); @@ -113,31 +113,31 @@ function( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 2, 'before' => $this->toCursor( $coupons[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ), $this->expectedField( 'coupons.pageInfo.hasNextPage', true ), $this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[1] ) ), $this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[2] ) ), $this->expectedField( 'coupons.nodes.0.databaseId', $coupons[1] ), $this->expectedField( 'coupons.nodes.1.databaseId', $coupons[2] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); } public function testProductsPagination() { - $products = array( + $products = [ $this->factory->product->createSimple(), $this->factory->product->createSimple(), $this->factory->product->createSimple(), $this->factory->product->createSimple(), $this->factory->product->createSimple(), - ); + ]; usort( $products, @@ -167,16 +167,16 @@ function( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.pageInfo.hasPreviousPage', false ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), $this->expectedField( 'products.pageInfo.startCursor', $this->toCursor( $products[0] ) ), $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[0] ), $this->expectedField( 'products.nodes.1.databaseId', $products[1] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -185,12 +185,12 @@ function( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $products[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), $this->expectedField( 'products.pageInfo.startCursor', $this->toCursor( $products[2] ) ), @@ -198,7 +198,7 @@ function( $key_a, $key_b ) { $this->expectedField( 'products.nodes.0.databaseId', $products[2] ), $this->expectedField( 'products.nodes.1.databaseId', $products[3] ), $this->expectedField( 'products.nodes.2.databaseId', $products[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -207,16 +207,16 @@ function( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', false ), $this->expectedField( 'products.pageInfo.startCursor', $this->toCursor( $products[3] ) ), $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[4] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[3] ), $this->expectedField( 'products.nodes.1.databaseId', $products[4] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); @@ -225,19 +225,19 @@ function( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 2, 'before' => $this->toCursor( $products[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.pageInfo.hasPreviousPage', true ), $this->expectedField( 'products.pageInfo.hasNextPage', true ), $this->expectedField( 'products.pageInfo.startCursor', $this->toCursor( $products[1] ) ), $this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ), $this->expectedField( 'products.nodes.0.databaseId', $products[1] ), $this->expectedField( 'products.nodes.1.databaseId', $products[2] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); } @@ -253,13 +253,13 @@ public function testOrdersPagination() { unset( $old_orders ); unset( $query ); - $orders = array( + $orders = [ $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), $this->factory->order->createNew(), - ); + ]; usort( $orders, @@ -289,16 +289,16 @@ function( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'orders.pageInfo.hasPreviousPage', false ), $this->expectedField( 'orders.pageInfo.hasNextPage', true ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[0] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[1] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[0] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[1] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -307,12 +307,12 @@ function( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $orders[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', false ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[2] ) ), @@ -320,7 +320,7 @@ function( $key_a, $key_b ) { $this->expectedField( 'orders.nodes.0.databaseId', $orders[2] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[3] ), $this->expectedField( 'orders.nodes.2.databaseId', $orders[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -329,16 +329,16 @@ function( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', false ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[3] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[4] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[3] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[4] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); @@ -347,32 +347,32 @@ function( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 2, 'before' => $this->toCursor( $orders[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'orders.pageInfo.hasPreviousPage', true ), $this->expectedField( 'orders.pageInfo.hasNextPage', true ), $this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[1] ) ), $this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[2] ) ), $this->expectedField( 'orders.nodes.0.databaseId', $orders[1] ), $this->expectedField( 'orders.nodes.1.databaseId', $orders[2] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); } public function testRefundsPagination() { $order = $this->factory->order->createNew(); - $refunds = array( - $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), - $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), - $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), - $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), - $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ), - ); + $refunds = [ + $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), + $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), + $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), + $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), + $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ), + ]; usort( $refunds, @@ -404,16 +404,16 @@ function( $key_a, $key_b ) { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'refunds.pageInfo.hasPreviousPage', false ), $this->expectedField( 'refunds.pageInfo.hasNextPage', true ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[0] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[1] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[0] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[1] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -422,12 +422,12 @@ function( $key_a, $key_b ) { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $refunds[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', false ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[2] ) ), @@ -435,7 +435,7 @@ function( $key_a, $key_b ) { $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[2] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[3] ), $this->expectedField( 'refunds.nodes.2.databaseId', $refunds[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -444,16 +444,16 @@ function( $key_a, $key_b ) { * * Test "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', false ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[3] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[4] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[3] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[4] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); @@ -462,39 +462,39 @@ function( $key_a, $key_b ) { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 2, 'before' => $this->toCursor( $refunds[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ), $this->expectedField( 'refunds.pageInfo.hasNextPage', true ), $this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[1] ) ), $this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[2] ) ), $this->expectedField( 'refunds.nodes.0.databaseId', $refunds[1] ), $this->expectedField( 'refunds.nodes.1.databaseId', $refunds[2] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); } public function testCustomersPagination() { - $some_customers = array( + $some_customers = [ $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), - ); + ]; $customers = get_users( - array( + [ 'fields' => 'id', 'role' => 'customer', 'orderby' => 'user_login', 'order' => 'ASC', - ) + ] ); $customers = array_map( 'absint', $customers ); @@ -523,16 +523,16 @@ public function testCustomersPagination() { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customers.pageInfo.hasNextPage', true ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[0] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[1] ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[0] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[1] ) ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -541,19 +541,19 @@ public function testCustomersPagination() { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $customers[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[2] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[2] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[3] ), $this->expectedField( 'customers.nodes.2.databaseId', $customers[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -562,16 +562,16 @@ public function testCustomersPagination() { * * Test "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.hasNextPage', false ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[3] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[3] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[4] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); @@ -580,19 +580,19 @@ public function testCustomersPagination() { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 2, 'before' => $this->toCursor( $customers[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customers.pageInfo.hasNextPage', true ), $this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[1] ) ), $this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[2] ) ), $this->expectedField( 'customers.nodes.0.databaseId', $customers[1] ), $this->expectedField( 'customers.nodes.1.databaseId', $customers[2] ), - ); + ]; // $this->assertQuerySuccessful( $response, $expected ); } @@ -600,42 +600,42 @@ public function testCustomersPagination() { public function testDownloadableItemsPagination() { $customer_id = $this->factory->customer->create(); - $downloads = array( + $downloads = [ $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), $this->factory->product->createDownload(), - ); + ]; $products = array_map( function( $download ) { return $this->factory->product->createSimple( - array( + [ 'downloadable' => true, - 'downloads' => array( $download ), - ) + 'downloads' => [ $download ], + ] ); }, $downloads ); $order_id = $this->factory->order->createNew( - array( + [ 'status' => 'completed', 'customer_id' => $customer_id, - ), - array( + ], + [ 'line_items' => array_map( function( $product_id ) { - return array( + return [ 'product' => $product_id, 'qty' => 1, - ); + ]; }, $products ), - ) + ] ); $order = \wc_get_order( $order_id ); @@ -675,16 +675,16 @@ function( $product_id ) { * * Test "first" parameter. */ - $variables = array( 'first' => 2 ); + $variables = [ 'first' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[1] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -693,12 +693,12 @@ function( $product_id ) { * * Test "after" parameter. */ - $variables = array( + $variables = [ 'first' => 3, 'after' => $this->toCursor( $downloads[1] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[2] ) ), @@ -706,7 +706,7 @@ function( $product_id ) { $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[2] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[3] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -715,16 +715,16 @@ function( $product_id ) { * * Test "last" parameter. */ - $variables = array( 'last' => 2 ); + $variables = [ 'last' => 2 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[3] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[4] ) ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[3] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[4] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -733,12 +733,12 @@ function( $product_id ) { * * Test "before" parameter. */ - $variables = array( + $variables = [ 'last' => 3, 'before' => $this->toCursor( $downloads[3] ), - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ), @@ -746,7 +746,7 @@ function( $product_id ) { $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ), $this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[2] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CoreInterfaceQueriesTest.php b/tests/wpunit/CoreInterfaceQueriesTest.php index 826432dd4..b4e2573ed 100644 --- a/tests/wpunit/CoreInterfaceQueriesTest.php +++ b/tests/wpunit/CoreInterfaceQueriesTest.php @@ -25,14 +25,14 @@ public function testProductAsNodeWithComments() { // Create product and review to be queried. $product_id = $this->products->create_simple(); $comment_id = $this->factory()->comment->create( - array( + [ 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $product_id, 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ) + ] ); update_comment_meta( $comment_id, 'rating', 1 ); @@ -48,21 +48,21 @@ public function testProductAsNodeWithComments() { } } '; - $variables = array( 'id' => $product_id ); + $variables = [ 'id' => $product_id ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product', $product_id ), 'commentCount' => 1, 'commentStatus' => 'open', - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -87,26 +87,26 @@ public function testOrderAsNodeWithComments() { } } '; - $variables = array( 'id' => $order_id ); + $variables = [ 'id' => $order_id ]; /** * Assertion One * * Authenticate as a shop manager and execute query and validate response. */ - wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) ); + wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) ); $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'order' => array( + $expected = [ + 'data' => [ + 'order' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'shop_order', $order_id ), 'commentCount' => 2, 'commentStatus' => 'open', - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -120,15 +120,15 @@ public function testOrderAsNodeWithComments() { $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'order' => array( + $expected = [ + 'data' => [ + 'order' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'shop_order', $order_id ), 'commentCount' => 1, 'commentStatus' => 'closed', - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -140,7 +140,7 @@ public function testProductAsNodeWithContentEditor() { $product = \wc_get_product( $product_id ); // Authenticate to view RAW content. - wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) ); + wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) ); // Define query and variables. $query = ' @@ -153,23 +153,23 @@ public function testProductAsNodeWithContentEditor() { } } '; - $variables = array( + $variables = [ 'id' => $product_id, 'format' => 'RAW', - ); + ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product', $product_id ), 'content' => $product->get_description(), - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -178,12 +178,12 @@ public function testProductAsNodeWithContentEditor() { public function testProductAsNodeWithFeaturedImage() { // Create product to be queried. $attachment_id = $this->factory()->attachment->create( - array( + [ 'post_mime_type' => 'image/gif', 'post_author' => $this->admin, - ) + ] ); - $product_id = $this->products->create_simple( array( 'image_id' => $attachment_id ) ); + $product_id = $this->products->create_simple( [ 'image_id' => $attachment_id ] ); // Define query and variables. $query = ' @@ -197,21 +197,21 @@ public function testProductAsNodeWithFeaturedImage() { } } '; - $variables = array( 'id' => $product_id ); + $variables = [ 'id' => $product_id ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product', $product_id ), 'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $attachment_id ), 'featuredImageDatabaseId' => $attachment_id, - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -250,15 +250,15 @@ public function testProductAsContentNode() { } } '; - $variables = array( 'id' => $product_id ); + $variables = [ 'id' => $product_id ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product', $product_id ), 'databaseId' => $wp_product->ID, 'date' => (string) $wc_product->get_date_created(), @@ -276,9 +276,9 @@ public function testProductAsContentNode() { 'isPreview' => null, 'previewRevisionDatabaseId' => null, 'previewRevisionId' => null, - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -301,20 +301,20 @@ public function testProductAsUniformResourceIdentifiable() { } } '; - $variables = array( 'id' => $product_id ); + $variables = [ 'id' => $product_id ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product', $product_id ), 'uri' => str_ireplace( home_url(), '', get_permalink( $wp_product->ID ) ), - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); @@ -357,15 +357,15 @@ public function testNodeInterfacesOnProductVariation() { } } '; - $variables = array( 'id' => $variation_id ); + $variables = [ 'id' => $variation_id ]; // Execute query and retrieve response. $response = $this->graphql( compact( 'query', 'variables' ) ); // Define expected data object. - $expected = array( - 'data' => array( - 'productVariation' => array( + $expected = [ + 'data' => [ + 'productVariation' => [ 'id' => \GraphQLRelay\Relay::toGlobalId( 'product_variation', $variation_id ), 'databaseId' => $wp_product->ID, 'date' => (string) $wc_product->get_date_created(), @@ -385,9 +385,9 @@ public function testNodeInterfacesOnProductVariation() { 'previewRevisionId' => null, 'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $wc_product->get_image_id() ), 'featuredImageDatabaseId' => $wc_product->get_image_id(), - ), - ), - ); + ], + ], + ]; // Assert query response valid. $this->assertEquals( $expected, $response ); diff --git a/tests/wpunit/CouponMutationsTest.php b/tests/wpunit/CouponMutationsTest.php index 7d3c8c59b..3cf65e12f 100644 --- a/tests/wpunit/CouponMutationsTest.php +++ b/tests/wpunit/CouponMutationsTest.php @@ -18,14 +18,14 @@ public function testCreateCoupon() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', 'code' => 'testcode', 'amount' => 0.25, 'discountType' => 'PERCENT', - ), - ); + ], + ]; /** * Assertion One @@ -33,10 +33,10 @@ public function testCreateCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'createCoupon' ), $this->expectedField( 'createCoupon', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -56,18 +56,18 @@ public function testCreateCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedObject( 'createCoupon.coupon', - array( + [ $this->expectedField( 'id', self::NOT_FALSY ), $this->expectedField( 'databaseId', self::NOT_FALSY ), $this->expectedField( 'code', 'testcode' ), $this->expectedField( 'amount', 0.25 ), $this->expectedField( 'discountType', 'PERCENT' ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -89,15 +89,15 @@ public function testUpdateCoupon() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), 'code' => 'blahblah', 'amount' => 0.25, 'discountType' => 'PERCENT', - ), - ); + ], + ]; /** * Assertion One @@ -105,10 +105,10 @@ public function testUpdateCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'updateCoupon' ), $this->expectedField( 'updateCoupon', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -128,18 +128,18 @@ public function testUpdateCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedObject( 'updateCoupon.coupon', - array( + [ $this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'databaseId', $coupon_id ), $this->expectedField( 'code', 'blahblah' ), $this->expectedField( 'amount', 0.25 ), $this->expectedField( 'discountType', 'PERCENT' ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -158,12 +158,12 @@ public function testDeleteCoupon() { } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ), - ), - ); + ], + ]; /** * Assertion One @@ -171,10 +171,10 @@ public function testDeleteCoupon() { * Expect mutation to failed due to lack of capabilities */ $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'deleteCoupon' ), $this->expectedField( 'deleteCoupon', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -194,15 +194,15 @@ public function testDeleteCoupon() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedObject( 'deleteCoupon.coupon', - array( + [ $this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'databaseId', $coupon_id ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CouponQueriesTest.php b/tests/wpunit/CouponQueriesTest.php index 400309cfd..d9c22ef97 100644 --- a/tests/wpunit/CouponQueriesTest.php +++ b/tests/wpunit/CouponQueriesTest.php @@ -6,7 +6,7 @@ class CouponQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL public function expectedCouponData( $coupon_id ) { $coupon = new \WC_Coupon( $coupon_id ); - $expected = array( + $expected = [ $this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', $coupon_id ) ), $this->expectedField( 'coupon.databaseId', $coupon->get_id() ), $this->expectedField( 'coupon.code', $coupon->get_code() ), @@ -26,26 +26,26 @@ public function expectedCouponData( $coupon_id ) { $this->expectedField( 'coupon.minimumAmount', $this->maybe( $coupon->get_minimum_amount(), self::IS_NULL ) ), $this->expectedField( 'coupon.maximumAmount', $this->maybe( $coupon->get_maximum_amount(), self::IS_NULL ) ), $this->expectedField( 'coupon.emailRestrictions', $this->maybe( $coupon->get_email_restrictions(), self::IS_NULL ) ), - ); + ]; foreach ( $coupon->get_product_ids() as $product_id ) { - $expected[] = $this->expectedNode( 'coupon.products.nodes', array( 'databaseId' => $product_id ) ); + $expected[] = $this->expectedNode( 'coupon.products.nodes', [ 'databaseId' => $product_id ] ); } foreach ( $coupon->get_excluded_product_ids() as $product_id ) { - $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', array( 'databaseId' => $product_id ) ); + $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', [ 'databaseId' => $product_id ] ); } foreach ( $coupon->get_product_categories() as $category_id ) { - $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', array( 'productCategoryId' => $category_id ) ); + $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', [ 'productCategoryId' => $category_id ] ); } foreach ( $coupon->get_excluded_product_categories() as $category_id ) { - $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', array( 'productCategoryId' => $category_id ) ); + $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', [ 'productCategoryId' => $category_id ] ); } foreach ( $coupon->get_used_by() as $customer_id ) { - $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', array( 'databaseId' => $customer_id ) ); + $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', [ 'databaseId' => $customer_id ] ); } return $expected; @@ -54,13 +54,13 @@ public function expectedCouponData( $coupon_id ) { // tests public function testCouponQuery() { $coupon_id = $this->factory->coupon->create( - array( + [ 'code' => '10off', 'amount' => 10, 'discount_type' => 'percent', - 'product_ids' => array( $this->factory->product->createSimple() ), - 'excluded_product_ids' => array( $this->factory->product->createSimple() ), - ) + 'product_ids' => [ $this->factory->product->createSimple() ], + 'excluded_product_ids' => [ $this->factory->product->createSimple() ], + ] ); $query = ' @@ -122,7 +122,7 @@ public function testCouponQuery() { * Assertion One */ $this->loginAsCustomer(); - $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ); + $variables = [ 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedCouponData( $coupon_id ); @@ -148,12 +148,12 @@ public function testCouponQueryAndIds() { * Testing "ID" ID type. */ $this->loginAsCustomer(); - $variables = array( + $variables = [ 'id' => $relay_id, 'idType' => 'ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'coupon.id', $relay_id ) ); + $expected = [ $this->expectedField( 'coupon.id', $relay_id ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -162,10 +162,10 @@ public function testCouponQueryAndIds() { * * Testing "DATABASE_ID" ID type */ - $variables = array( + $variables = [ 'id' => $coupon_id, 'idType' => 'DATABASE_ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -175,33 +175,33 @@ public function testCouponQueryAndIds() { * * Testing "CODE" ID type. */ - $variables = array( + $variables = [ 'id' => $coupon->get_code(), 'idType' => 'CODE', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); } public function testCouponsQueryAndWhereArgs() { - $coupons = array( + $coupons = [ $this->factory->coupon->create(), $this->factory->coupon->create( - array( + [ 'code' => '20off', 'amount' => 20, 'discount_type' => 'percent', - ) + ] ), $this->factory->coupon->create( - array( + [ 'code' => 'testcode', 'amount' => 30, 'discount_type' => 'percent', - ) + ] ), - ); + ]; $query = ' query ($code: String, $include: [Int], $exclude: [Int]) { @@ -220,9 +220,9 @@ public function testCouponsQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( + $expected = [ $this->expectedField( 'coupons.nodes', self::IS_NULL ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -235,11 +235,11 @@ public function testCouponsQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), - ); + $expected = [ + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -250,13 +250,13 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'code' where argument */ - $variables = array( 'code' => 'testcode' ); + $variables = [ 'code' => 'testcode' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), - $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), - $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), - ); + $expected = [ + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), + $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), + $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -267,13 +267,13 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'include' where argument */ - $variables = array( 'include' => $coupons[0] ); + $variables = [ 'include' => $coupons[0] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), - $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), - $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), - ); + $expected = [ + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), + $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), + $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -282,14 +282,14 @@ public function testCouponsQueryAndWhereArgs() { * * Tests 'exclude' where argument */ - $variables = array( 'exclude' => $coupons[0] ); + $variables = [ 'exclude' => $coupons[0] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ), - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ), - $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ), + $expected = [ + $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ), + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ), + $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/CustomerMutationsTest.php b/tests/wpunit/CustomerMutationsTest.php index 7a8631124..e3269f8d8 100644 --- a/tests/wpunit/CustomerMutationsTest.php +++ b/tests/wpunit/CustomerMutationsTest.php @@ -14,7 +14,7 @@ public function setUp(): void { $this->username = 'spidersRLoose67'; $this->pass = 'c@nalSt_@ll_DaY'; $this->email = 'peter.parker@dailybugle.com'; - $this->billing = array( + $this->billing = [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -24,8 +24,8 @@ public function setUp(): void { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ); - $this->shipping = array( + ]; + $this->shipping = [ 'firstName' => 'Peter', 'lastName' => 'Parker', 'address1' => '202 Canal St', @@ -34,13 +34,13 @@ public function setUp(): void { 'state' => 'NY', 'postcode' => '12310', 'country' => 'US', - ); + ]; // Update Info $this->new_first_name = 'Ben'; $this->new_last_name = 'Wallace'; $this->new_email = 'we0utHere32@gmail.com'; - $this->new_billing = array( + $this->new_billing = [ 'firstName' => 'Jim', 'lastName' => 'Bean', 'address1' => '45 Vodka Rd', @@ -50,8 +50,8 @@ public function setUp(): void { 'country' => 'US', 'email' => '4daKnock0ut@yahoo.com', 'phone' => '757-422-0989', - ); - $this->new_shipping = array( + ]; + $this->new_shipping = [ 'firstName' => 'Ben', 'lastName' => 'Wallace', 'address1' => '478 Vodka Rd', @@ -59,7 +59,7 @@ public function setUp(): void { 'state' => 'VA', 'postcode' => '23451', 'country' => 'US', - ); + ]; } public function tearDown(): void { @@ -76,7 +76,7 @@ public function tearDown(): void { } private function empty_shipping() { - return array( + return [ 'firstName' => null, 'lastName' => null, 'company' => null, @@ -86,16 +86,16 @@ private function empty_shipping() { 'state' => null, 'postcode' => null, 'country' => null, - ); + ]; } private function empty_billing() { return array_merge( $this->empty_shipping(), - array( + [ 'email' => null, 'phone' => null, - ) + ] ); } @@ -144,13 +144,13 @@ private function registerCustomer( $input ) { } '; - $variables = array( 'input' => $input ); + $variables = [ 'input' => $input ]; $actual = graphql( - array( + [ 'query' => $mutation, 'operation_name' => 'register', 'variables' => $variables, - ) + ] ); return $actual; @@ -198,13 +198,13 @@ private function updateCustomer( $input ) { } '; - $variables = array( 'input' => $input ); + $variables = [ 'input' => $input ]; $actual = graphql( - array( + [ 'query' => $mutation, 'operation_name' => 'update', 'variables' => $variables, - ) + ] ); return $actual; @@ -217,14 +217,14 @@ public function testRegisterMutationWithoutCustomerInfo() { * Tests mutation without a providing WooCommerce specific customer information. */ $actual = $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, 'email' => $this->email, 'firstName' => $this->first_name, 'lastName' => $this->last_name, - ) + ] ); // use --debug flag to view. @@ -233,13 +233,13 @@ public function testRegisterMutationWithoutCustomerInfo() { $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $this->username, @@ -247,13 +247,13 @@ public function testRegisterMutationWithoutCustomerInfo() { 'lastName' => $this->last_name, 'billing' => $this->empty_billing(), 'shipping' => $this->empty_shipping(), - ), - 'viewer' => array( + ], + 'viewer' => [ 'userId' => $user->ID, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -265,7 +265,7 @@ public function testRegisterMutationWithBillingInfo() { * Tests mutation with customer billing information. */ $actual = $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, @@ -273,7 +273,7 @@ public function testRegisterMutationWithBillingInfo() { 'firstName' => $this->first_name, 'lastName' => $this->last_name, 'billing' => $this->billing, - ) + ] ); // use --debug flag to view. @@ -282,13 +282,13 @@ public function testRegisterMutationWithBillingInfo() { $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $this->username, @@ -296,13 +296,13 @@ public function testRegisterMutationWithBillingInfo() { 'lastName' => $this->last_name, 'billing' => array_merge( $this->empty_billing(), $this->billing ), 'shipping' => $this->empty_shipping(), - ), - 'viewer' => array( + ], + 'viewer' => [ 'userId' => $user->ID, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -314,7 +314,7 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { * Tests mutation using "shippingSameAsBilling" field. */ $actual = $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, @@ -323,7 +323,7 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { 'lastName' => $this->last_name, 'billing' => $this->billing, 'shippingSameAsBilling' => true, - ) + ] ); // use --debug flag to view. @@ -332,13 +332,13 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $this->username, @@ -349,13 +349,13 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() { $this->empty_shipping(), array_intersect_key( $this->billing, $this->empty_shipping() ) ), - ), - 'viewer' => array( + ], + 'viewer' => [ 'userId' => $user->ID, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -367,7 +367,7 @@ public function testRegisterMutationWithBillingAndShippingInfo() { * Tests mutation with customer shipping information. */ $actual = $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, @@ -376,7 +376,7 @@ public function testRegisterMutationWithBillingAndShippingInfo() { 'lastName' => $this->last_name, 'billing' => $this->billing, 'shipping' => $this->shipping, - ) + ] ); // use --debug flag to view. @@ -385,13 +385,13 @@ public function testRegisterMutationWithBillingAndShippingInfo() { $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $this->username, @@ -399,13 +399,13 @@ public function testRegisterMutationWithBillingAndShippingInfo() { 'lastName' => $this->last_name, 'billing' => array_merge( $this->empty_billing(), $this->billing ), 'shipping' => array_merge( $this->empty_shipping(), $this->shipping ), - ), - 'viewer' => array( + ], + 'viewer' => [ 'userId' => $user->ID, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -417,7 +417,7 @@ public function testUpdateMutation() { * Tests mutation without a providing WooCommerce specific customer information. */ $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, @@ -426,34 +426,34 @@ public function testUpdateMutation() { 'lastName' => $this->last_name, 'billing' => $this->billing, 'shipping' => $this->shipping, - ) + ] ); $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); $actual = $this->updateCustomer( - array( + [ 'clientMutationId' => 'someId', 'id' => $this->helper->to_relay_id( $user->ID ), 'email' => $this->new_email, 'firstName' => $this->new_first_name, 'lastName' => $this->new_last_name, - 'billing' => array_merge( $this->new_billing, array( 'overwrite' => true ) ), - 'shipping' => array_merge( $this->new_shipping, array( 'overwrite' => true ) ), - ) + 'billing' => array_merge( $this->new_billing, [ 'overwrite' => true ] ), + 'shipping' => array_merge( $this->new_shipping, [ 'overwrite' => true ] ), + ] ); // use --debug flag to view. codecept_debug( $actual ); - $expected = array( - 'data' => array( - 'updateCustomer' => array( + $expected = [ + 'data' => [ + 'updateCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->new_email, 'username' => $this->username, @@ -461,10 +461,10 @@ public function testUpdateMutation() { 'lastName' => $this->new_last_name, 'billing' => array_merge( $this->empty_billing(), $this->new_billing ), 'shipping' => array_merge( $this->empty_shipping(), $this->new_shipping ), - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -476,7 +476,7 @@ public function testUpdateMutationWithShippingSameAsBilling() { * Tests mutation without a providing WooCommerce specific customer information. */ $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'username' => $this->username, 'password' => $this->pass, @@ -485,30 +485,30 @@ public function testUpdateMutationWithShippingSameAsBilling() { 'lastName' => $this->last_name, 'billing' => $this->billing, 'shipping' => $this->shipping, - ) + ] ); $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); $actual = $this->updateCustomer( - array( + [ 'clientMutationId' => 'someId', 'id' => $this->helper->to_relay_id( $user->ID ), 'shippingSameAsBilling' => true, - ) + ] ); // use --debug flag to view. codecept_debug( $actual ); - $expected = array( - 'data' => array( - 'updateCustomer' => array( + $expected = [ + 'data' => [ + 'updateCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $this->username, @@ -519,10 +519,10 @@ public function testUpdateMutationWithShippingSameAsBilling() { $this->empty_shipping(), array_intersect_key( $this->billing, $this->empty_shipping() ) ), - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -534,12 +534,12 @@ public function testRegisterMutationWithoutAnyInfo() { * Tests mutation without a providing an username and password. */ $actual = $this->registerCustomer( - array( + [ 'clientMutationId' => 'someId', 'email' => $this->email, 'firstName' => $this->first_name, 'lastName' => $this->last_name, - ) + ] ); // use --debug flag to view. @@ -548,13 +548,13 @@ public function testRegisterMutationWithoutAnyInfo() { $user = get_user_by( 'email', 'peter.parker@dailybugle.com' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ 'clientMutationId' => 'someId', 'authToken' => \WPGraphQL\JWT_Authentication\Auth::get_token( $user ), 'refreshToken' => \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ), - 'customer' => array( + 'customer' => [ 'databaseId' => $user->ID, 'email' => $this->email, 'username' => $user->user_login, @@ -562,13 +562,13 @@ public function testRegisterMutationWithoutAnyInfo() { 'lastName' => $this->last_name, 'billing' => $this->empty_billing(), 'shipping' => $this->empty_shipping(), - ), - 'viewer' => array( + ], + 'viewer' => [ 'userId' => $user->ID, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -593,18 +593,18 @@ public function testCustomerMutationsWithMeta() { } } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', 'email' => 'user@woographql.test', - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ), - ), - ), - ); + ], + ], + ], + ]; $actual = graphql( compact( 'query', 'variables' ) ); codecept_debug( $actual ); @@ -612,22 +612,22 @@ public function testCustomerMutationsWithMeta() { $user = get_user_by( 'email', 'user@woographql.test' ); $this->assertTrue( is_a( $user, WP_User::class ) ); - $expected = array( - 'data' => array( - 'registerCustomer' => array( - 'customer' => array( + $expected = [ + 'data' => [ + 'registerCustomer' => [ + 'customer' => [ 'databaseId' => $user->ID, 'email' => 'user@woographql.test', - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); @@ -650,38 +650,38 @@ public function testCustomerMutationsWithMeta() { } } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', 'id' => \GraphQLRelay\Relay::toGlobalId( 'customer', $user->ID ), - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'new_meta_value', - ), - ), - ), - ); + ], + ], + ], + ]; $actual = graphql( compact( 'query', 'variables' ) ); codecept_debug( $actual ); - $expected = array( - 'data' => array( - 'updateCustomer' => array( - 'customer' => array( + $expected = [ + 'data' => [ + 'updateCustomer' => [ + 'customer' => [ 'databaseId' => $user->ID, 'email' => 'user@woographql.test', - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'new_meta_value', - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); @@ -703,36 +703,36 @@ public function testCustomerMutationsWithMeta() { } } '; - $variables = array( - 'input' => array( + $variables = [ + 'input' => [ 'clientMutationId' => 'some_id', - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ), - ), - ), - ); + ], + ], + ], + ]; $actual = graphql( compact( 'query', 'variables' ) ); codecept_debug( $actual ); - $expected = array( - 'data' => array( - 'updateCustomer' => array( - 'customer' => array( + $expected = [ + 'data' => [ + 'updateCustomer' => [ + 'customer' => [ 'id' => 'guest', - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_meta_key', 'value' => 'test_meta_value', - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } diff --git a/tests/wpunit/CustomerQueriesTest.php b/tests/wpunit/CustomerQueriesTest.php index d55a11a44..2fa50c4ae 100644 --- a/tests/wpunit/CustomerQueriesTest.php +++ b/tests/wpunit/CustomerQueriesTest.php @@ -16,10 +16,10 @@ public function expectedCustomerData( $id ) { $billing = $customer->get_billing(); $shipping = $customer->get_shipping(); - return array( + return [ $this->expectedObject( 'customer', - array( + [ $this->expectedField( 'id', $this->toRelayId( 'customer', $id ) ), $this->expectedField( 'databaseId', $id ), $this->expectedField( 'isVatExempt', $customer->get_is_vat_exempt() ), @@ -43,7 +43,7 @@ public function expectedCustomerData( $id ) { ), $this->expectedObject( 'billing', - array( + [ $this->expectedField( 'firstName', $this->maybe( $billing['first_name'] ) ), $this->expectedField( 'lastName', $this->maybe( $billing['last_name'] ) ), $this->expectedField( 'company', $this->maybe( $billing['company'] ) ), @@ -53,11 +53,11 @@ public function expectedCustomerData( $id ) { $this->expectedField( 'postcode', $this->maybe( $billing['postcode'] ) ), $this->expectedField( 'email', $this->maybe( $billing['email'] ) ), $this->expectedField( 'phone', $this->maybe( $billing['phone'] ) ), - ) + ] ), $this->expectedObject( 'shipping', - array( + [ $this->expectedField( 'firstName', $this->maybe( $shipping['first_name'] ) ), $this->expectedField( 'lastName', $this->maybe( $shipping['last_name'] ) ), $this->expectedField( 'company', $this->maybe( $shipping['company'] ) ), @@ -65,7 +65,7 @@ public function expectedCustomerData( $id ) { $this->expectedField( 'address2', $this->maybe( $shipping['address_2'] ) ), $this->expectedField( 'city', $this->maybe( $shipping['city'] ) ), $this->expectedField( 'postcode', $this->maybe( $shipping['postcode'] ) ), - ) + ] ), $this->expectedField( 'isPayingCustomer', $customer->get_is_paying_customer() ), $this->expectedField( @@ -80,9 +80,9 @@ public function expectedCustomerData( $id ) { ? \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $wp_user ) : null ), - ) + ] ), - ); + ]; } // tests @@ -144,12 +144,12 @@ public function testCustomerQueryAndArgs() { * Query should return null value due to lack of permissions. */ $this->loginAsCustomer(); - $variables = array( 'id' => $this->toRelayId( 'customer', $new_customer_id ) ); + $variables = [ 'id' => $this->toRelayId( 'customer', $new_customer_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'customer' ), $this->expectedField( 'customer', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -161,7 +161,7 @@ public function testCustomerQueryAndArgs() { * * Query should return requested data because user queried themselves. */ - $variables = array( 'id' => $this->toRelayId( 'customer', $this->customer ) ); + $variables = [ 'id' => $this->toRelayId( 'customer', $this->customer ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expectedCustomerData( $this->customer ); @@ -177,15 +177,15 @@ public function testCustomerQueryAndArgs() { * but should not have access to JWT fields. */ $this->loginAsShopManager(); - $variables = array( 'id' => $this->toRelayId( 'customer', $new_customer_id ) ); + $variables = [ 'id' => $this->toRelayId( 'customer', $new_customer_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_merge( - array( + [ $this->expectedErrorPath( 'customer.jwtAuthToken' ), $this->expectedField( 'customer.jwtAuthToken', self::IS_NULL ), $this->expectedErrorPath( 'customer.jwtRefreshToken' ), $this->expectedField( 'customer.jwtRefreshToken', self::IS_NULL ), - ), + ], $this->expectedCustomerData( $new_customer_id ) ); @@ -214,7 +214,7 @@ public function testCustomerQueryAndArgs() { * Query should return requested data because user queried themselves. */ $this->loginAs( $new_customer_id ); - $variables = array( 'customerId' => $new_customer_id ); + $variables = [ 'customerId' => $new_customer_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -228,12 +228,12 @@ public function testCustomerQueryAndArgs() { * Query should return null value due to lack of permissions.. */ $this->loginAsCustomer(); - $variables = array( 'customerId' => $new_customer_id ); + $variables = [ 'customerId' => $new_customer_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'customer' ), $this->expectedField( 'customer', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -242,17 +242,17 @@ public function testCustomerQueryAndArgs() { } public function testCustomersQueryAndWhereArgs() { - $users = array( + $users = [ $this->factory->customer->create( - array( + [ 'email' => 'gotcha@example.com', 'username' => 'megaman8080', - ) + ] ), $this->factory->customer->create(), $this->factory->customer->create(), $this->factory->customer->create(), - ); + ]; $query = ' query ( @@ -285,7 +285,7 @@ public function testCustomersQueryAndWhereArgs() { */ $this->loginAs( $users[0] ); $response = $this->graphql( compact( 'query' ) ); - $expected = array( $this->expectedField( 'customers.nodes', array() ) ); + $expected = [ $this->expectedField( 'customers.nodes', [] ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -296,12 +296,12 @@ public function testCustomersQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.nodes.#.databaseId', $users[0] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[2] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[3] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -310,11 +310,11 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "search" where argument. */ - $variables = array( 'search' => 'megaman8080' ); + $variables = [ 'search' => 'megaman8080' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.nodes.0.databaseId', $users[0] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -323,11 +323,11 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "include" where argument. */ - $variables = array( 'include' => array( $users[2] ) ); + $variables = [ 'include' => [ $users[2] ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.nodes.0.databaseId', $users[2] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -336,14 +336,14 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "exclude" where argument. */ - $variables = array( 'exclude' => array( $users[2] ) ); + $variables = [ 'exclude' => [ $users[2] ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.nodes.#.databaseId', $users[0] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->expectedField( 'customers.nodes.#.databaseId', $users[3] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -352,14 +352,14 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "email" where argument. */ - $variables = array( 'email' => 'gotcha@example.com' ); + $variables = [ 'email' => 'gotcha@example.com' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customers.nodes.0.databaseId', $users[0] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[1] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ), $this->not()->expectedField( 'customers.nodes.#.databaseId', $users[3] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -368,21 +368,21 @@ public function testCustomersQueryAndWhereArgs() { * * Tests "orderby" and "order" where arguments. */ - $variables = array( + $variables = [ 'orderby' => 'USERNAME', 'order' => 'ASC', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $all_users = get_users( - array( + [ 'fields' => 'ID', 'role' => 'customer', 'orderby' => 'username', 'order' => 'ASC', - ) + ] ); - $expected = array(); + $expected = []; foreach ( $all_users as $index => $user_id ) { $expected[] = $this->expectedField( "customers.nodes.{$index}.databaseId", @@ -396,10 +396,10 @@ public function testCustomersQueryAndWhereArgs() { public function testCustomerToOrdersConnection() { $new_customer_id = $this->factory->customer->create(); $order_1 = $this->factory->order->createNew( - array( 'customer_id' => $this->customer ) + [ 'customer_id' => $this->customer ] ); $order_2 = $this->factory->order->createNew( - array( 'customer_id' => $new_customer_id ) + [ 'customer_id' => $new_customer_id ] ); $query = ' @@ -421,9 +421,9 @@ public function testCustomerToOrdersConnection() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( + $expected = [ $this->expectedField( 'customer.orders.nodes.#.databaseId', $order_1 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/DownloadableItemQueriesTest.php b/tests/wpunit/DownloadableItemQueriesTest.php index fc2043be9..72e93bde9 100644 --- a/tests/wpunit/DownloadableItemQueriesTest.php +++ b/tests/wpunit/DownloadableItemQueriesTest.php @@ -12,24 +12,24 @@ public function setUp(): void { // tests public function testOrderToDownloadableItemsQuery() { $downloadable_product = $this->factory->product->createSimple( - array( + [ 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $order_id = $this->factory->order->createNew( - array( + [ 'status' => 'completed', 'customer_id' => $this->customer, - ), - array( - 'line_items' => array( - array( + ], + [ + 'line_items' => [ + [ 'product' => $downloadable_product, 'qty' => 1, - ), - ), - ) + ], + ], + ] ); // Force download permission updated. @@ -75,10 +75,10 @@ public function testOrderToDownloadableItemsQuery() { function( $item ) { return $this->expectedNode( 'customer.orders.nodes', - array( + [ $this->expectedNode( 'downloadableItems.nodes', - array( + [ $this->expectedField( 'url', $item['download_url'] ), $this->expectedField( 'accessExpires', $item['access_expires'] ), $this->expectedField( 'downloadId', $item['download_id'] ), @@ -91,9 +91,9 @@ function( $item ) { $this->expectedField( 'name', $item['download_name'] ), $this->expectedField( 'product.databaseId', $item['product_id'] ), $this->expectedField( 'download.downloadId', $item['download_id'] ), - ) + ] ), - ), + ], 0 ); }, @@ -106,48 +106,48 @@ function( $item ) { public function testOrderToDownloadableItemsQueryArgs() { $valid_product = $this->factory->product->createSimple( - array( + [ 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $downloadable_product = $this->factory->product->createSimple( - array( + [ 'download_expiry' => 5, 'download_limit' => 3, 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $downloaded_product = $this->factory->product->createSimple( - array( + [ 'download_limit' => 0, 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $order_id = $this->factory->order->createNew( - array( + [ 'status' => 'completed', 'customer_id' => $this->customer, - ), - array( - 'line_items' => array( - array( + ], + [ + 'line_items' => [ + [ 'product' => $valid_product, 'qty' => 1, - ), - array( + ], + [ 'product' => $downloadable_product, 'qty' => 1, - ), - array( + ], + [ 'product' => $downloaded_product, 'qty' => 1, - ), - ), - ) + ], + ], + ] ); // Force download permission updated. @@ -177,28 +177,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * Tests "active" whereArg */ $this->loginAsCustomer(); - $variables = array( 'active' => true ); + $variables = [ 'active' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'customer.orders.nodes', - array( + [ $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $valid_product ) ) + [ $this->expectedField( 'product.databaseId', $valid_product ) ] ), $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) + [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] ), $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) + [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] ), - ), + ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -207,28 +207,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "active" whereArg reversed */ - $variables = array( 'active' => false ); + $variables = [ 'active' => false ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'customer.orders.nodes', - array( + [ $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) + [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] ), $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $valid_product ) ) + [ $this->expectedField( 'product.databaseId', $valid_product ) ] ), $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) + [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] ), - ), + ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -237,28 +237,28 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "hasDownloadsRemaining" whereArg */ - $variables = array( 'hasDownloadsRemaining' => true ); + $variables = [ 'hasDownloadsRemaining' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'customer.orders.nodes', - array( + [ $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) + [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] ), $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $valid_product ) ) + [ $this->expectedField( 'product.databaseId', $valid_product ) ] ), $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) + [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] ), - ), + ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -267,52 +267,52 @@ public function testOrderToDownloadableItemsQueryArgs() { * * Tests "hasDownloadsRemaining" whereArg reversed */ - $variables = array( 'hasDownloadsRemaining' => false ); + $variables = [ 'hasDownloadsRemaining' => false ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'customer.orders.nodes', - array( + [ $this->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloaded_product ) ) + [ $this->expectedField( 'product.databaseId', $downloaded_product ) ] ), $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $valid_product ) ) + [ $this->expectedField( 'product.databaseId', $valid_product ) ] ), $this->not()->expectedNode( 'downloadableItems.nodes', - array( $this->expectedField( 'product.databaseId', $downloadable_product ) ) + [ $this->expectedField( 'product.databaseId', $downloadable_product ) ] ), - ), + ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testCustomerToDownloadableItemsQuery() { $downloadable_product = $this->factory->product->createSimple( - array( + [ 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $order_id = $this->factory->order->createNew( - array( + [ 'status' => 'completed', 'customer_id' => $this->customer, - ), - array( - 'line_items' => array( - array( + ], + [ + 'line_items' => [ + [ 'product' => $downloadable_product, 'qty' => 1, - ), - ), - ) + ], + ], + ] ); // Force download permission updated. @@ -353,7 +353,7 @@ public function testCustomerToDownloadableItemsQuery() { function( $item ) { return $this->expectedNode( 'customer.downloadableItems.nodes', - array( + [ $this->expectedField( 'url', $item['download_url'] ), $this->expectedField( 'accessExpires', @@ -369,7 +369,7 @@ function( $item ) { $this->expectedField( 'name', $item['download_name'] ), $this->expectedField( 'product.databaseId', $item['product_id'] ), $this->expectedField( 'download.downloadId', $item['download_id'] ), - ), + ], 0 ); }, diff --git a/tests/wpunit/IntrospectionQueryTest.php b/tests/wpunit/IntrospectionQueryTest.php index 503d57df5..d06447990 100644 --- a/tests/wpunit/IntrospectionQueryTest.php +++ b/tests/wpunit/IntrospectionQueryTest.php @@ -8,7 +8,7 @@ public function setUp(): void { $settings = get_option( 'graphql_general_settings' ); if ( ! $settings ) { - $settings = array(); + $settings = []; } $settings['public_introspection_enabled'] = 'on'; update_option( 'graphql_general_settings', $settings ); @@ -35,7 +35,7 @@ public function testSchema() { // Test introspection query. public function testIntrospectionQuery() { $query = \GraphQL\Type\Introspection::getIntrospectionQuery(); - $results = graphql( array( 'query' => $query ) ); + $results = graphql( [ 'query' => $query ] ); $this->assertArrayNotHasKey( 'errors', $results ); } diff --git a/tests/wpunit/MetaDataQueriesTest.php b/tests/wpunit/MetaDataQueriesTest.php index 1026bf2ca..4308c2dd5 100644 --- a/tests/wpunit/MetaDataQueriesTest.php +++ b/tests/wpunit/MetaDataQueriesTest.php @@ -9,8 +9,8 @@ public function setUp(): void { parent::setUp(); // Create users. - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); // Assign helpers. $this->cart = $this->getModule( '\Helper\Wpunit' )->cart(); @@ -40,25 +40,25 @@ public function set_user( $user ) { } private function createObjects() { - $data = array( - 'meta_data' => array( - array( + $data = [ + 'meta_data' => [ + [ 'id' => 0, 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'id' => 0, 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - array( + ], + [ 'id' => 0, 'key' => 'meta_1', 'value' => 75, - ), - ), - ); + ], + ], + ]; // Create Coupon with meta data. $this->coupon_id = $this->coupons->create( $data ); @@ -67,7 +67,7 @@ private function createObjects() { $this->customer_id = $this->customers->create( $data ); // Create Order and Refund with meta data. - $this->order_id = $this->orders->create( array_merge( $data, array( 'customer_id' => $this->customer ) ) ); + $this->order_id = $this->orders->create( array_merge( $data, [ 'customer_id' => $this->customer ] ) ); $this->order_items->add_fee( $this->order_id, $data ); $this->refund_id = $this->refunds->create( $this->order_id, $data ); @@ -76,23 +76,23 @@ private function createObjects() { $this->variation_ids = $this->variations->create( $this->product_id, $data ); // Add Cart Item with extra data. - $cart_meta_data = array( + $cart_meta_data = [ 'meta_1' => 'test_meta_1', 'meta_2' => 'test_meta_2', - ); + ]; // Clear cart. WC()->cart->empty_cart( true ); // Add item to cart. $this->cart_item_key = $this->cart->add( - array( + [ 'product_id' => $this->variation_ids['product'], 'quantity' => 2, 'variation_id' => $this->variation_ids['variations'][0], - 'variation' => array( 'attribute_pa_color' => 'red' ), + 'variation' => [ 'attribute_pa_color' => 'red' ], 'cart_item_data' => $cart_meta_data, - ) + ] )[0]; } @@ -119,30 +119,30 @@ public function testCartMetaDataQueries() { * * Query w/o filter */ - $actual = graphql( array( 'query' => $query ) ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + $actual = graphql( [ 'query' => $query ] ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $this->cart_item_key, - 'extraData' => array( - array( + 'extraData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -154,32 +154,32 @@ public function testCartMetaDataQueries() { * * Query w/ "key" filter */ - $variables = array( 'key' => 'meta_2' ); + $variables = [ 'key' => 'meta_2' ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) - ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + ] + ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $this->cart_item_key, - 'extraData' => array( - array( + 'extraData' => [ + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -191,32 +191,32 @@ public function testCartMetaDataQueries() { * * Query w/ "keysIn" filter */ - $variables = array( 'keysIn' => array( 'meta_2' ) ); + $variables = [ 'keysIn' => [ 'meta_2' ] ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) - ); - $expected = array( - 'data' => array( - 'cart' => array( - 'contents' => array( - 'nodes' => array( - array( + ] + ); + $expected = [ + 'data' => [ + 'cart' => [ + 'contents' => [ + 'nodes' => [ + [ 'key' => $this->cart_item_key, - 'extraData' => array( - array( + 'extraData' => [ + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -244,30 +244,30 @@ public function testCouponMetaDataQueries() { * Query w/o filters */ wp_set_current_user( $this->shop_manager ); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -279,29 +279,29 @@ public function testCouponMetaDataQueries() { * * Query w/ "key" filter */ - $variables = array( + $variables = [ 'id' => $id, 'key' => 'meta_2', - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -313,29 +313,29 @@ public function testCouponMetaDataQueries() { * * Query w/ "keysIn" filter */ - $variables = array( + $variables = [ 'id' => $id, - 'keysIn' => array( 'meta_2' ), - ); + 'keysIn' => [ 'meta_2' ], + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -347,34 +347,34 @@ public function testCouponMetaDataQueries() { * * Query w/ "key" filter and "multiple" set to true to get non-unique results. */ - $variables = array( + $variables = [ 'id' => $id, 'key' => 'meta_1', 'multiple' => true, - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_1', 'value' => '75', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -386,34 +386,34 @@ public function testCouponMetaDataQueries() { * * Query w/ "keysIn" filter and "multiple" set to true to get non-unique results. */ - $variables = array( + $variables = [ 'id' => $id, - 'keysIn' => array( 'meta_1' ), + 'keysIn' => [ 'meta_1' ], 'multiple' => true, - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_1', 'value' => '75', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -425,37 +425,37 @@ public function testCouponMetaDataQueries() { * * Query w/o filters and "multiple" set to true to get non-unique results. */ - $variables = array( + $variables = [ 'id' => $id, 'multiple' => true, - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'coupon' => array( + $expected = [ + 'data' => [ + 'coupon' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - array( + ], + [ 'key' => 'meta_1', 'value' => '75', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -480,24 +480,24 @@ public function testCustomerMetaDataQueries() { * Assertion One */ $this->set_user( $this->customer_id ); - $actual = graphql( array( 'query' => $query ) ); - $expected = array( - 'data' => array( - 'customer' => array( + $actual = graphql( [ 'query' => $query ] ); + $expected = [ + 'data' => [ + 'customer' => [ 'id' => Relay::toGlobalId( 'customer', $this->customer_id ), - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -533,46 +533,46 @@ public function testOrderMetaDataQueries() { /** * Assertion One */ - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'order' => array( + $expected = [ + 'data' => [ + 'order' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - 'feeLines' => array( - 'nodes' => array( - array( - 'metaData' => array( - array( + ], + ], + 'feeLines' => [ + 'nodes' => [ + [ + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -599,30 +599,30 @@ public function testProductMetaDataQueries() { /** * Assertion One */ - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -647,30 +647,30 @@ public function testProductVariationMetaDataQueries() { /** * Assertion One */ - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'productVariation' => array( + $expected = [ + 'data' => [ + 'productVariation' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -696,30 +696,30 @@ public function testRefundMetaDataQueries() { * Assertion One */ wp_set_current_user( $this->customer ); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'refund' => array( + $expected = [ + 'data' => [ + 'refund' => [ 'id' => $id, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'meta_1', 'value' => 'test_meta_1', - ), - array( + ], + [ 'key' => 'meta_2', 'value' => 'test_meta_2', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/tests/wpunit/OrderItemQueriesTest.php b/tests/wpunit/OrderItemQueriesTest.php index 2f1508e47..0b3437dcf 100644 --- a/tests/wpunit/OrderItemQueriesTest.php +++ b/tests/wpunit/OrderItemQueriesTest.php @@ -38,20 +38,20 @@ public function testCouponLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function( $item ) { return $this->expectedNode( 'order.couponLines.nodes', - array( + [ $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'code', $item->get_code() ), $this->expectedField( 'discount', $this->maybe( $item->get_discount(), self::IS_NULL ) ), $this->expectedField( 'discountTax', $this->maybe( $item->get_discount_tax(), self::IS_NULL ) ), $this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', \wc_get_coupon_id_by_code( $item->get_code() ) ) ), - ) + ] ); }, $coupon_lines @@ -92,13 +92,13 @@ public function testFeeLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function( $item ) { return $this->expectedNode( 'order.feeLines.nodes', - array( + [ $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'amount', $item->get_amount() ), @@ -112,7 +112,7 @@ function( $item ) { ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD' ), - ) + ] ); }, $fee_lines @@ -150,13 +150,13 @@ public function testShippingLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function( $item ) { return $this->expectedNode( 'order.shippingLines.nodes', - array( + [ $this->expectedField( 'databaseId', $item->get_id() ), $this->expectedField( 'orderId', $item->get_order_id() ), $this->expectedField( 'methodTitle', $item->get_method_title() ), @@ -170,7 +170,7 @@ function( $item ) { : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD' ), - ) + ] ); }, $shipping_lines @@ -211,20 +211,20 @@ public function testTaxLinesQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function( $item ) { return $this->expectedNode( 'order.taxLines.nodes', - array( + [ $this->expectedField( 'rateCode', $item->get_rate_code() ), $this->expectedField( 'label', $item->get_label() ), $this->expectedField( 'taxTotal', $item->get_tax_total() ), $this->expectedField( 'shippingTaxTotal', $item->get_shipping_tax_total() ), $this->expectedField( 'isCompound', $item->is_compound() ), $this->expectedField( 'taxRate.databaseId', $item->get_rate_id() ), - ) + ] ); }, $tax_lines @@ -281,13 +281,13 @@ public function testLineItemsQuery() { * Tests query and results */ $this->loginAsShopManager(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_map( function( $item ) { return $this->expectedNode( 'order.lineItems.nodes', - array( + [ $this->expectedField( 'productId', $item->get_product_id() ), $this->expectedField( 'variationId', $this->maybe( $item->get_variation_id(), self::IS_NULL ) ), $this->expectedField( 'quantity', $item->get_quantity() ), @@ -310,7 +310,7 @@ function( $item ) { ? $this->toRelayId( 'product_variation', $item->get_variation_id() ) : self::IS_NULL ), - ) + ] ); }, $line_items diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php index 3ac75cab2..451eeef27 100644 --- a/tests/wpunit/OrderMutationsTest.php +++ b/tests/wpunit/OrderMutationsTest.php @@ -9,8 +9,8 @@ public function setUp(): void { parent::setUp(); // Create users. - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); // Get helper instances $this->order = $this->getModule( '\Helper\Wpunit' )->order(); @@ -27,7 +27,7 @@ public function setUp(): void { // Create a tax rate. $this->tax->create( - array( + [ 'country' => '', 'state' => '', 'rate' => 20.000, @@ -36,7 +36,7 @@ public function setUp(): void { 'compound' => '0', 'shipping' => '1', 'class' => '', - ) + ] ); // Create sample order to be used as a parent order. $this->order_id = $this->order->create(); @@ -207,11 +207,11 @@ private function orderMutation( $input, $operation_name = 'createOrder', $input_ "; $actual = graphql( - array( + [ 'query' => $mutation, 'operation_name' => $operation_name, - 'variables' => array( 'input' => $input ), - ) + 'variables' => [ 'input' => $input ], + ] ); return $actual; @@ -220,25 +220,25 @@ private function orderMutation( $input, $operation_name = 'createOrder', $input_ // tests public function testCreateOrderMutation() { $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); - $input = array( + $input = [ 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => array( + 'coupons' => [ $coupon->get_code(), - ), + ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -248,8 +248,8 @@ public function testCreateOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -257,51 +257,51 @@ public function testCreateOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - 'lineItems' => array( - array( + ], + 'lineItems' => [ + [ 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_product_key', 'value' => 'test product value', - ), - ), - ), - array( + ], + ], + ], + [ 'productId' => $product_ids[1], 'quantity' => 2, - ), - array( + ], + [ 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ), - ), - 'shippingLines' => array( - array( + ], + ], + 'shippingLines' => [ + [ 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ), - ), - 'feeLines' => array( - array( + ], + ], + 'feeLines' => [ + [ 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ), - ), - 'metaData' => array( - array( + ], + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'test value', - ), - ), + ], + ], 'isPaid' => true, - ); + ]; /** * Assertion One @@ -333,37 +333,37 @@ public function testCreateOrderMutation() { $this->assertArrayHasKey( 'id', $actual['data']['createOrder']['order'] ); $order = \WC_Order_Factory::get_order( $actual['data']['createOrder']['order']['databaseId'] ); - $expected = array( - 'data' => array( - 'createOrder' => array( + $expected = [ + 'data' => [ + 'createOrder' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'couponLines' => array( + [ + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, - 'coupon' => array( + 'coupon' => [ 'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ), - ), - ); + ], + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => $item->get_amount(), @@ -374,17 +374,17 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( + ], + 'shippingLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -397,34 +397,34 @@ function( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'shipping' ) ) ), - ), - 'taxLines' => array( + ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -438,25 +438,25 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); } @@ -464,26 +464,26 @@ function( $item ) { public function testUpdateOrderMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); // Create initial order input. - $initial_input = array( + $initial_input = [ 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => array( + 'coupons' => [ $coupon->get_code(), - ), + ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -493,8 +493,8 @@ public function testUpdateOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -502,51 +502,51 @@ public function testUpdateOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - 'lineItems' => array( - array( + ], + 'lineItems' => [ + [ 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_product_key', 'value' => 'test product value', - ), - ), - ), - array( + ], + ], + ], + [ 'productId' => $product_ids[1], 'quantity' => 2, - ), - array( + ], + [ 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ), - ), - 'shippingLines' => array( - array( + ], + ], + 'shippingLines' => [ + [ 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ), - ), - 'feeLines' => array( - array( + ], + ], + 'feeLines' => [ + [ 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ), - ), - 'metaData' => array( - array( + ], + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'test value', - ), - ), + ], + ], 'isPaid' => false, - ); + ]; // Create order to update. wp_set_current_user( $this->shop_manager ); @@ -562,65 +562,65 @@ public function testUpdateOrderMutation() { $fee_lines = $order->get_items( 'fee' ); // Create update order input. - $updated_input = array( + $updated_input = [ 'id' => $this->order->to_relay_id( $order->get_id() ), 'clientMutationId' => 'someId', 'customerNote' => 'Customer test note', - 'coupons' => array( + 'coupons' => [ $coupon->get_code(), - ), - 'billing' => array( + ], + 'billing' => [ 'firstName' => 'Ben', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'Ben', - ), - 'lineItems' => array( - array( + ], + 'lineItems' => [ + [ 'id' => array_keys( $line_items )[0], 'quantity' => 6, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_product_key', 'value' => 'updated test product value', - ), - ), - ), - array( + ], + ], + ], + [ 'id' => array_keys( $line_items )[1], 'quantity' => 1, - ), - array( + ], + [ 'id' => array_keys( $line_items )[2], 'quantity' => 10, - ), - ), - 'shippingLines' => array( - array( + ], + ], + 'shippingLines' => [ + [ 'id' => array_keys( $shipping_lines )[0], 'methodId' => 'reduced_rate_shipping', 'methodTitle' => 'reduced Rate shipping', 'total' => '7', - ), - ), - 'feeLines' => array( - array( + ], + ], + 'feeLines' => [ + [ 'id' => array_keys( $fee_lines )[0], 'name' => 'Some Updated Fee', 'taxStatus' => 'TAXABLE', 'total' => '125', 'taxClass' => 'STANDARD', - ), - ), - 'metaData' => array( - array( + ], + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'new test value', - ), - ), + ], + ], 'isPaid' => true, - ); + ]; /** * Assertion One @@ -657,37 +657,37 @@ public function testUpdateOrderMutation() { // Apply new changes to order instances. $order = \WC_Order_Factory::get_order( $order->get_id() ); - $expected = array( - 'data' => array( - 'updateOrder' => array( + $expected = [ + 'data' => [ + 'updateOrder' => [ 'clientMutationId' => 'someId', 'order' => array_merge( $this->order->print_query( $order->get_id() ), - array( - 'couponLines' => array( + [ + 'couponLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'code' => $item->get_code(), 'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null, 'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null, - 'coupon' => array( + 'coupon' => [ 'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ), - ), - ); + ], + ]; }, $order->get_items( 'coupon' ) ) ), - ), - 'feeLines' => array( + ], + 'feeLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'amount' => ! empty( $item->get_amount() ) ? $item->get_amount() : null, @@ -698,17 +698,17 @@ function( $item ) { 'taxClass' => ! empty( $item->get_tax_class() ) ? WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'fee' ) ) ), - ), - 'shippingLines' => array( + ], + 'shippingLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'databaseId' => $item->get_id(), 'orderId' => $item->get_order_id(), 'methodTitle' => $item->get_method_title(), @@ -721,34 +721,34 @@ function( $item ) { ? WPEnumType::get_safe_name( 'inherit cart' ) : WPEnumType::get_safe_name( $item->get_tax_class() ) : 'STANDARD', - ); + ]; }, $order->get_items( 'shipping' ) ) ), - ), - 'taxLines' => array( + ], + 'taxLines' => [ 'nodes' => array_reverse( array_map( function( $item ) { - return array( + return [ 'rateCode' => $item->get_rate_code(), 'label' => $item->get_label(), 'taxTotal' => $item->get_tax_total(), 'shippingTaxTotal' => $item->get_shipping_tax_total(), 'isCompound' => $item->is_compound(), - 'taxRate' => array( 'databaseId' => $item->get_rate_id() ), - ); + 'taxRate' => [ 'databaseId' => $item->get_rate_id() ], + ]; }, $order->get_items( 'tax' ) ) ), - ), - 'lineItems' => array( + ], + 'lineItems' => [ 'nodes' => array_values( array_map( function( $item ) { - return array( + return [ 'productId' => $item->get_product_id(), 'variationId' => ! empty( $item->get_variation_id() ) ? $item->get_variation_id() @@ -762,25 +762,25 @@ function( $item ) { 'total' => ! empty( $item->get_total() ) ? $item->get_total() : null, 'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null, 'taxStatus' => strtoupper( $item->get_tax_status() ), - 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ), + 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ], 'variation' => ! empty( $item->get_variation_id() ) - ? array( - 'node' => array( + ? [ + 'node' => [ 'id' => $this->variation->to_relay_id( $item->get_variation_id() ), - ), - ) + ], + ] : null, - ); + ]; }, $order->get_items() ) ), - ), - ) + ], + ] ), - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $actual ); $this->assertNotEquals( $initial_response, $actual ); @@ -789,26 +789,26 @@ function( $item ) { public function testDeleteOrderMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); // Create initial order input. - $initial_input = array( + $initial_input = [ 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => array( + 'coupons' => [ $coupon->get_code(), - ), + ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -818,8 +818,8 @@ public function testDeleteOrderMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -827,51 +827,51 @@ public function testDeleteOrderMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - 'lineItems' => array( - array( + ], + 'lineItems' => [ + [ 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_product_key', 'value' => 'test product value', - ), - ), - ), - array( + ], + ], + ], + [ 'productId' => $product_ids[1], 'quantity' => 2, - ), - array( + ], + [ 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ), - ), - 'shippingLines' => array( - array( + ], + ], + 'shippingLines' => [ + [ 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ), - ), - 'feeLines' => array( - array( + ], + ], + 'feeLines' => [ + [ 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ), - ), - 'metaData' => array( - array( + ], + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'test value', - ), - ), + ], + ], 'isPaid' => false, - ); + ]; // Create order to delete. wp_set_current_user( $this->shop_manager ); @@ -893,11 +893,11 @@ public function testDeleteOrderMutation() { $tax_lines = $order->get_items( 'tax' ); // Create DeleteOrderInput. - $deleted_input = array( + $deleted_input = [ 'clientMutationId' => 'someId', 'id' => $this->order->to_relay_id( $order->get_id() ), 'forceDelete' => true, - ); + ]; /** * Assertion One @@ -940,26 +940,26 @@ public function testDeleteOrderMutation() { public function testDeleteOrderItemsMutation() { // Create products and coupons to be used in order creation. $variable = $this->variation->create( $this->product->create_variable() ); - $product_ids = array( + $product_ids = [ $this->product->create_simple(), $this->product->create_simple(), $variable['product'], - ); + ]; $coupon = new WC_Coupon( - $this->coupon->create( array( 'product_ids' => $product_ids ) ) + $this->coupon->create( [ 'product_ids' => $product_ids ] ) ); // Create initial order input. - $initial_input = array( + $initial_input = [ 'clientMutationId' => 'someId', 'customerId' => $this->customer, 'customerNote' => 'Customer test note', - 'coupons' => array( + 'coupons' => [ $coupon->get_code(), - ), + ], 'paymentMethod' => 'bacs', 'paymentMethodTitle' => 'Direct Bank Transfer', - 'billing' => array( + 'billing' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -969,8 +969,8 @@ public function testDeleteOrderItemsMutation() { 'country' => 'US', 'email' => 'superfreak500@gmail.com', 'phone' => '555-555-1234', - ), - 'shipping' => array( + ], + 'shipping' => [ 'firstName' => 'May', 'lastName' => 'Parker', 'address1' => '20 Ingram St', @@ -978,51 +978,51 @@ public function testDeleteOrderItemsMutation() { 'state' => 'NY', 'postcode' => '12345', 'country' => 'US', - ), - 'lineItems' => array( - array( + ], + 'lineItems' => [ + [ 'productId' => $product_ids[0], 'quantity' => 5, - 'metaData' => array( - array( + 'metaData' => [ + [ 'key' => 'test_product_key', 'value' => 'test product value', - ), - ), - ), - array( + ], + ], + ], + [ 'productId' => $product_ids[1], 'quantity' => 2, - ), - array( + ], + [ 'productId' => $product_ids[2], 'quantity' => 6, 'variationId' => $variable['variations'][0], - ), - ), - 'shippingLines' => array( - array( + ], + ], + 'shippingLines' => [ + [ 'methodId' => 'flat_rate_shipping', 'methodTitle' => 'Flat Rate shipping', 'total' => '10', - ), - ), - 'feeLines' => array( - array( + ], + ], + 'feeLines' => [ + [ 'name' => 'Some Fee', 'taxStatus' => 'TAXABLE', 'total' => '100', 'taxClass' => 'STANDARD', - ), - ), - 'metaData' => array( - array( + ], + ], + 'metaData' => [ + [ 'key' => 'test_key', 'value' => 'test value', - ), - ), + ], + ], 'isPaid' => false, - ); + ]; // Create order to delete. wp_set_current_user( $this->shop_manager ); @@ -1044,14 +1044,14 @@ public function testDeleteOrderItemsMutation() { $tax_lines = $order->get_items( 'tax' ); // Create DeleteOrderInput. - $deleted_items_input = array( + $deleted_items_input = [ 'clientMutationId' => 'someId', 'orderId' => $order->get_id(), - 'itemIds' => array( + 'itemIds' => [ current( $line_items )->get_id(), current( $coupon_lines )->get_id(), - ), - ); + ], + ]; /** * Assertion One diff --git a/tests/wpunit/OrderQueriesTest.php b/tests/wpunit/OrderQueriesTest.php index c1e99cd8e..c785de6f3 100644 --- a/tests/wpunit/OrderQueriesTest.php +++ b/tests/wpunit/OrderQueriesTest.php @@ -7,10 +7,10 @@ class OrderQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLT public function expectedOrderData( $order_id ) { $order = \wc_get_order( $order_id ); - $expected = array( + $expected = [ $this->expectedObject( 'order', - array( + [ $this->expectedField( 'id', $this->toRelayId( 'shop_order', $order_id ) ), $this->expectedField( 'databaseId', $order->get_id() ), $this->expectedField( 'currency', $this->maybe( $order->get_currency() ) ), @@ -18,14 +18,14 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'date', $order->get_date_created()->__toString() ), $this->expectedField( 'modified', $order->get_date_modified()->__toString() ), $this->expectedField( 'status', WPEnumType::get_safe_name( $order->get_status() ) ), - $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), array( 'currency' => $order->get_currency() ) ) ), - $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), array( 'currency' => $order->get_currency() ) ) ), + $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), [ 'currency' => $order->get_currency() ] ) ), + $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), [ 'currency' => $order->get_currency() ] ) ), $this->expectedField( 'orderNumber', $order->get_order_number() ), $this->expectedField( 'orderKey', $order->get_order_key() ), $this->expectedField( 'createdVia', $this->maybe( $order->get_created_via() ) ), @@ -34,10 +34,10 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'customer', $this->maybe( - array( + [ $order->get_customer_id(), - array( 'id' => $this->toRelayId( 'customer', $order->get_customer_id() ) ), - ), + [ 'id' => $this->toRelayId( 'customer', $order->get_customer_id() ) ], + ], self::IS_NULL ) ), @@ -46,7 +46,7 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'customerNote', $this->maybe( $order->get_customer_note() ) ), $this->expectedObject( 'billing', - array( + [ $this->expectedField( 'firstName', $this->maybe( $order->get_billing_first_name() ) ), $this->expectedField( 'lastName', $this->maybe( $order->get_billing_last_name() ) ), $this->expectedField( 'company', $this->maybe( $order->get_billing_company() ) ), @@ -58,11 +58,11 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'country', $this->maybe( $order->get_billing_country() ) ), $this->expectedField( 'email', $this->maybe( $order->get_billing_email() ) ), $this->expectedField( 'phone', $this->maybe( $order->get_billing_phone() ) ), - ) + ] ), $this->expectedObject( 'shipping', - array( + [ $this->expectedField( 'firstName', $this->maybe( $order->get_shipping_first_name() ) ), $this->expectedField( 'lastName', $this->maybe( $order->get_shipping_last_name() ) ), $this->expectedField( 'company', $this->maybe( $order->get_shipping_company() ) ), @@ -72,7 +72,7 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'state', $this->maybe( $order->get_shipping_state() ) ), $this->expectedField( 'postcode', $this->maybe( $order->get_shipping_postcode() ) ), $this->expectedField( 'country', $this->maybe( $order->get_shipping_country() ) ), - ) + ] ), $this->expectedField( 'paymentMethod', $this->maybe( $order->get_payment_method() ) ), $this->expectedField( 'paymentMethodTitle', $this->maybe( $order->get_payment_method_title() ) ), @@ -88,9 +88,9 @@ public function expectedOrderData( $order_id ) { $this->expectedField( 'hasDownloadableItem', $order->has_downloadable_item() ), $this->expectedField( 'needsPayment', $order->needs_payment() ), $this->expectedField( 'needsProcessing', $order->needs_processing() ), - ) + ] ), - ); + ]; return $expected; } @@ -194,9 +194,9 @@ public function testOrderQuery() { * Tests query as customer, should return "null" because the customer isn't authorized. */ $this->loginAsCustomer(); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'order', self::IS_NULL ) ); + $expected = [ $this->expectedField( 'order', self::IS_NULL ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -232,12 +232,12 @@ public function testOrderQueryAndIds() { * * Tests "ID" ID type. */ - $variables = array( + $variables = [ 'id' => $id, 'idType' => 'ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'order.id', $id ) ); + $expected = [ $this->expectedField( 'order.id', $id ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -246,10 +246,10 @@ public function testOrderQueryAndIds() { * * Tests "DATABASE_ID" ID type. */ - $variables = array( + $variables = [ 'id' => $order_id, 'idType' => 'DATABASE_ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -259,10 +259,10 @@ public function testOrderQueryAndIds() { * * Tests "ORDER_NUMBER" ID type */ - $variables = array( + $variables = [ 'id' => $this->factory->order->get_order_key( $order_id ), 'idType' => 'ORDER_NUMBER', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -281,33 +281,33 @@ public function testOrdersQueryAndWhereArgs() { // Create order for query response. $customer = $this->factory->customer->create(); $product = $this->factory->product->createSimple(); - $orders = array( + $orders = [ $this->factory->order->createNew( - array(), - array( - 'line_items' => array( - array( + [], + [ + 'line_items' => [ + [ 'product' => $product, 'qty' => 4, - ), - ), - ) + ], + ], + ] ), $this->factory->order->createNew( - array( + [ 'status' => 'completed', 'customer_id' => $customer, - ), - array( - 'line_items' => array( - array( + ], + [ + 'line_items' => [ + [ 'product' => $product, 'qty' => 2, - ), - ), - ) + ], + ], + ] ), - ); + ]; $query = ' query ($statuses: [OrderStatusEnum], $customerId: Int, $customersIn: [Int] $productId: Int) { @@ -332,7 +332,7 @@ public function testOrdersQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( $this->expectedField( 'orders.nodes', array() ) ); + $expected = [ $this->expectedField( 'orders.nodes', [] ) ]; $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -344,11 +344,11 @@ public function testOrdersQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( - $this->expectedNode( 'orders.nodes', array( 'id' => $this->toRelayId( 'shop_order', $orders[0] ) ) ), - $this->expectedNode( 'orders.nodes', array( 'id' => $this->toRelayId( 'shop_order', $orders[1] ) ) ), - $this->not()->expectedNode( 'orders.nodes', array( 'id' => $this->toRelayId( 'shop_order', $old_orders[0] ) ) ), - ); + $expected = [ + $this->expectedNode( 'orders.nodes', [ 'id' => $this->toRelayId( 'shop_order', $orders[0] ) ] ), + $this->expectedNode( 'orders.nodes', [ 'id' => $this->toRelayId( 'shop_order', $orders[1] ) ] ), + $this->not()->expectedNode( 'orders.nodes', [ 'id' => $this->toRelayId( 'shop_order', $old_orders[0] ) ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -358,11 +358,11 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "statuses" where argument */ - $variables = array( 'statuses' => array( 'COMPLETED' ) ); + $variables = [ 'statuses' => [ 'COMPLETED' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'orders.nodes', array( 'id' => $this->toRelayId( 'shop_order', $orders[1] ) ) ), - ); + $expected = [ + $this->expectedNode( 'orders.nodes', [ 'id' => $this->toRelayId( 'shop_order', $orders[1] ) ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); $this->clearLoaderCache( 'wc_post' ); @@ -372,7 +372,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "customerId" where argument */ - $variables = array( 'customerId' => $customer ); + $variables = [ 'customerId' => $customer ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -383,7 +383,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "customerIn" where argument */ - $variables = array( 'customersIn' => array( $customer ) ); + $variables = [ 'customersIn' => [ $customer ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -394,7 +394,7 @@ public function testOrdersQueryAndWhereArgs() { * * Tests "productId" where argument */ - $variables = array( 'productId' => $product ); + $variables = [ 'productId' => $product ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); diff --git a/tests/wpunit/PaymentGatewayQueriesTest.php b/tests/wpunit/PaymentGatewayQueriesTest.php index f80762800..7b811994c 100644 --- a/tests/wpunit/PaymentGatewayQueriesTest.php +++ b/tests/wpunit/PaymentGatewayQueriesTest.php @@ -9,29 +9,29 @@ public function setUp(): void { // Enable payment gateway. update_option( 'woocommerce_bacs_settings', - array( + [ 'enabled' => 'yes', 'title' => 'Direct bank transfer', 'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'instructions' => 'Instructions that will be added to the thank you page and emails.', 'account' => '', - ) + ] ); update_option( 'woocommerce_cheque_settings', - array( + [ 'enabled' => 'no', 'title' => 'Check payments', 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'instructions' => 'Instructions that will be added to the thank you page and emails.', 'account' => '', - ) + ] ); delete_option( 'woocommerce_stripe_settings', - array( + [ 'enabled' => 'no', 'title' => 'Credit Card (Stripe)', 'description' => 'Pay with your credit card via Stripe', @@ -56,7 +56,7 @@ public function setUp(): void { 'payment_request_button_height' => '44', 'saved_cards' => 'yes', 'logging' => 'no', - ) + ] ); // Reload gateways. @@ -83,16 +83,16 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * Tests query. */ $response = $this->graphql( compact( 'query' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'paymentGateways.nodes', - array( + [ $this->expectedField( 'id', 'bacs' ), $this->expectedField( 'title', 'Direct bank transfer' ), $this->expectedField( 'icon', self::IS_NULL ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -101,12 +101,12 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * * Tests query and "all" where argument response, expects errors due lack of capabilities. */ - $variables = array( 'all' => true ); + $variables = [ 'all' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedErrorPath( 'paymentGateways' ), $this->expectedField( 'paymentGateways', self::IS_NULL ), - ); + ]; $this->assertQueryError( $response, $expected ); @@ -116,43 +116,43 @@ public function testPaymentGatewaysQueryAndWhereArgs() { * Tests query and "all" where argument response with proper capabilities. */ $this->loginAsShopManager(); - $variables = array( 'all' => true ); + $variables = [ 'all' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'paymentGateways.nodes', - array( + [ $this->expectedField( 'id', 'bacs' ), $this->expectedField( 'title', 'Direct bank transfer' ), $this->expectedField( 'icon', self::IS_NULL ), - ) + ] ), $this->expectedNode( 'paymentGateways.nodes', - array( + [ $this->expectedField( 'id', 'cheque' ), $this->expectedField( 'title', 'Check payments' ), $this->expectedField( 'icon', self::IS_NULL ), - ) + ] ), $this->expectedNode( 'paymentGateways.nodes', - array( + [ $this->expectedField( 'id', 'cod' ), $this->expectedField( 'title', 'Cash on delivery' ), $this->expectedField( 'icon', self::IS_NULL ), - ) + ] ), $this->expectedNode( 'paymentGateways.nodes', - array( + [ $this->expectedField( 'id', 'stripe' ), $this->expectedField( 'title', 'Credit Card (Stripe)' ), $this->expectedField( 'icon', self::IS_NULL ), - ) + ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ProductAttributeQueriesTest.php b/tests/wpunit/ProductAttributeQueriesTest.php index 15924ac64..c79be95e2 100644 --- a/tests/wpunit/ProductAttributeQueriesTest.php +++ b/tests/wpunit/ProductAttributeQueriesTest.php @@ -11,8 +11,8 @@ class ProductAttributeQueriesTest extends \Codeception\TestCase\WPTestCase { public function setUp(): void { parent::setUp(); - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->helper = $this->getModule( '\Helper\Wpunit' )->product(); $this->variation_helper = $this->getModule( '\Helper\Wpunit' )->product_variation(); $this->product_id = $this->helper->create_variable(); @@ -45,22 +45,22 @@ public function testProductAttributeQuery() { } '; - $variables = array( 'id' => $this->helper->to_relay_id( $this->product_id ) ); + $variables = [ 'id' => $this->helper->to_relay_id( $this->product_id ) ]; $actual = graphql( - array( + [ 'query' => $query, 'operation_name' => 'attributeQuery', 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => $this->helper->to_relay_id( $this->product_id ), 'attributes' => $this->helper->print_attributes( $this->product_id ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -85,31 +85,31 @@ public function testProductAttributeToProductConnectionQuery() { } '; - $variables = array( 'color' => 'red' ); + $variables = [ 'color' => 'red' ]; $actual = graphql( - array( + [ 'query' => $query, 'operation_name' => 'attributeConnectionQuery', 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'allPaColor' => array( - 'nodes' => array( - array( - 'products' => array( - 'nodes' => array( - array( + $expected = [ + 'data' => [ + 'allPaColor' => [ + 'nodes' => [ + [ + 'products' => [ + 'nodes' => [ + [ 'id' => $this->helper->to_relay_id( $this->product_id ), - ), - ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -132,25 +132,25 @@ public function testProductAttributeToVariationConnectionQuery() { } '; - $variables = array( 'size' => 'small' ); + $variables = [ 'size' => 'small' ]; $actual = graphql( - array( + [ 'query' => $query, 'operation_name' => 'attributeConnectionQuery', 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'allPaSize' => array( - 'nodes' => array( - array( - 'variations' => array( + $expected = [ + 'data' => [ + 'allPaSize' => [ + 'nodes' => [ + [ + 'variations' => [ 'nodes' => $this->variation_helper->print_nodes( $this->variation_ids, - array( + [ 'filter' => function( $id ) { - $variation = new \WC_Product_Variation( $id ); + $variation = new \WC_Product_Variation( $id ); $small_attribute = array_filter( $variation->get_attributes(), function( $attribute ) { @@ -159,14 +159,14 @@ function( $attribute ) { ); return ! empty( $small_attribute ); }, - ) + ] ), - ), - ), - ), - ), - ), - ); + ], + ], + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/tests/wpunit/ProductQueriesTest.php b/tests/wpunit/ProductQueriesTest.php index ac0a5c0b3..e87d079d3 100644 --- a/tests/wpunit/ProductQueriesTest.php +++ b/tests/wpunit/ProductQueriesTest.php @@ -9,7 +9,7 @@ public function getExpectedProductData( $product_id ) { $is_shop_manager = true; } - return array( + return [ $this->expectedField( 'product.id', $this->toRelayId( 'product', $product_id ) ), $this->expectedField( 'product.databaseId', $product->get_id() ), $this->expectedField( 'product.name', $product->get_name() ), @@ -20,20 +20,20 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.description', $this->maybe( - array( $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ), + [ $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ], self::IS_NULL ) ), $this->expectedField( 'product.shortDescription', $this->maybe( - array( + [ $product->get_short_description(), apply_filters( 'get_the_excerpt', apply_filters( 'the_excerpt', $product->get_short_description() ) ), - ), + ], self::IS_NULL ) ), @@ -41,21 +41,21 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.price', $this->maybe( - array( $product->get_price(), \wc_graphql_price( $product->get_price() ) ), + [ $product->get_price(), \wc_graphql_price( $product->get_price() ) ], self::IS_NULL ) ), $this->expectedField( 'product.regularPrice', $this->maybe( - array( $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ), + [ $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ], self::IS_NULL ) ), $this->expectedField( 'product.salePrice', $this->maybe( - array( $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ), + [ $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ], self::IS_NULL ) ), @@ -147,24 +147,24 @@ public function getExpectedProductData( $product_id ) { $this->expectedField( 'product.totalSales', $this->maybe( - array( + [ $is_shop_manager && $product->get_total_sales(), $product->get_total_sales(), - ), + ], self::IS_NULL ) ), $this->expectedField( 'product.catalogVisibility', $this->maybe( - array( + [ $is_shop_manager && ! empty( $product->get_catalog_visibility() ), strtoupper( $product->get_catalog_visibility() ), - ), + ], self::IS_NULL ) ), - ); + ]; } public function getExpectedProductDownloadData( $product_id ) { @@ -174,9 +174,9 @@ public function getExpectedProductDownloadData( $product_id ) { return null; } - $results = array(); + $results = []; foreach ( $downloads as $download ) { - $results[] = array( + $results[] = [ 'name' => $download->get_name(), 'downloadId' => $download->get_id(), 'filePathType' => $download->get_type_of_file_path(), @@ -185,7 +185,7 @@ public function getExpectedProductDownloadData( $product_id ) { 'allowedFileType' => $download->is_allowed_filetype(), 'fileExists' => $download->file_exists(), 'file' => $download->get_file(), - ); + ]; } return $results; @@ -254,7 +254,7 @@ public function testSimpleProductQuery() { * * Test querying product. */ - $variables = array( 'id' => $this->toRelayId( 'product', $product_id ) ); + $variables = [ 'id' => $this->toRelayId( 'product', $product_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->getExpectedProductData( $product_id ); @@ -269,17 +269,17 @@ public function testSimpleProductQuery() { * Test querying product with unformatted content (edit-product cap required). */ $this->loginAsShopManager(); - $variables = array( + $variables = [ 'id' => $this->toRelayId( 'product', $product_id ), 'format' => 'RAW', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.description', $product->get_description() ), $this->expectedField( 'product.shortDescription', $product->get_short_description() ), $this->expectedField( 'product.totalSales', $product->get_total_sales() ), $this->expectedField( 'product.catalogVisibility', strtoupper( $product->get_catalog_visibility() ) ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -290,19 +290,19 @@ public function testProductTaxonomies() { $category_6 = $this->factory->product->createProductCategory( 'category-six', $category_5 ); $tag_2 = $this->factory->product->createProductTag( 'tag-two' ); $attachment_id = $this->factory->attachment->create( - array( + [ 'post_mime_type' => 'image/gif', 'post_author' => $this->admin, - ) + ] ); $product_id = $this->factory->product->createSimple( - array( + [ 'price' => 10, 'regular_price' => 10, - 'category_ids' => array( $category_5 ), - 'tag_ids' => array( $tag_2 ), + 'category_ids' => [ $category_5 ], + 'tag_ids' => [ $tag_2 ], 'image_id' => $attachment_id, - ) + ] ); $query = ' @@ -341,30 +341,30 @@ public function testProductTaxonomies() { * * Test querying product with "productId" argument. */ - $variables = array( + $variables = [ 'id' => $product_id, 'idType' => 'DATABASE_ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $this->toRelayId( 'product', $product_id ) ), $this->expectedField( 'product.image.id', $this->toRelayId( 'post', $attachment_id ) ), $this->expectedNode( 'product.productCategories.nodes', - array( + [ 'name' => 'category-five', 'image' => null, 'display' => 'DEFAULT', 'menuOrder' => 0, - 'children' => array( - 'nodes' => array( - array( 'name' => 'category-six' ), - ), - ), - ) + 'children' => [ + 'nodes' => [ + [ 'name' => 'category-six' ], + ], + ], + ] ), - $this->expectedNode( 'product.productTags.nodes', array( 'name' => 'tag-two' ) ), - ); + $this->expectedNode( 'product.productTags.nodes', [ 'name' => 'tag-two' ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -382,19 +382,19 @@ public function testProductQueryAndIds() { '; // Define expected data for coming assertions. - $expected = array( + $expected = [ $this->expectedField( 'product.id', $this->toRelayId( 'product', $product_id ) ), - ); + ]; /** * Assertion One * * Test querying product with 'DATABASE_ID' set as the "idType". */ - $variables = array( + $variables = [ 'id' => $product_id, 'idType' => 'DATABASE_ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -403,10 +403,10 @@ public function testProductQueryAndIds() { * * Test querying product with "ID" set as the "idType". */ - $variables = array( + $variables = [ 'id' => $this->toRelayId( 'product', $product_id ), 'idType' => 'ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -415,10 +415,10 @@ public function testProductQueryAndIds() { * * Test querying product with "SLUG" set as the "idType". */ - $variables = array( + $variables = [ 'id' => get_post_field( 'post_name', $product_id ), 'idType' => 'SLUG', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); @@ -427,10 +427,10 @@ public function testProductQueryAndIds() { * * Test querying product with "SKU" set as the "idType". */ - $variables = array( + $variables = [ 'id' => get_post_meta( $product_id, '_sku', true ), 'idType' => 'SKU', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, $expected ); } @@ -438,29 +438,29 @@ public function testProductQueryAndIds() { public function testProductsQueryAndWhereArgs() { $category_3 = $this->factory->product->createProductCategory( 'category-three' ); $category_4 = $this->factory->product->createProductCategory( 'category-four' ); - $product_ids = array( + $product_ids = [ $this->factory->product->createSimple( - array( + [ 'slug' => 'test-product-1', 'price' => 6000, 'regular_price' => 6000, - ) + ] ), $this->factory->product->createSimple( - array( + [ 'price' => 2, 'regular_price' => 2, - 'category_ids' => array( $category_3, $category_4 ), - ) + 'category_ids' => [ $category_3, $category_4 ], + ] ), $this->factory->product->createSimple( - array( + [ 'featured' => 'true', - 'category_ids' => array( $category_3 ), - ) + 'category_ids' => [ $category_3 ], + ] ), $this->factory->product->createExternal(), - ); + ]; $query = ' query ( @@ -517,7 +517,7 @@ public function testProductsQueryAndWhereArgs() { function( $product_id ) { return $this->expectedNode( 'products.nodes', - array( 'id' => $this->toRelayId( 'product', $product_id ) ) + [ 'id' => $this->toRelayId( 'product', $product_id ) ] ); }, $product_ids @@ -537,7 +537,7 @@ function( $product_id ) { * Tests query with "slug" where argument, and expect the product with * the slug "test-product-1" to be returned. */ - $variables = array( 'slugIn' => array( 'test-product-1' ) ); + $variables = [ 'slugIn' => [ 'test-product-1' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -557,9 +557,9 @@ function( $node, $index ) use ( $product_ids ) { * a status of "pending" to be returned, which there are none among the test * product with that status. */ - $variables = array( 'status' => 'pending' ); + $variables = [ 'status' => 'pending' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'products.nodes', array() ) ); + $expected = [ $this->expectedField( 'products.nodes', [] ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -569,7 +569,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "type" where argument, and expect only "simple" products * to be returned. */ - $variables = array( 'type' => 'SIMPLE' ); + $variables = [ 'type' => 'SIMPLE' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -588,7 +588,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "typeIn" where argument, and expect only "simple" products * to be returned. */ - $variables = array( 'typeIn' => array( 'SIMPLE' ) ); + $variables = [ 'typeIn' => [ 'SIMPLE' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -600,7 +600,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "typeNotIn" where argument, and expect all types of products * with except "simple" to be returned. */ - $variables = array( 'typeNotIn' => array( 'SIMPLE' ) ); + $variables = [ 'typeNotIn' => [ 'SIMPLE' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -619,7 +619,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "featured" where argument, expect only featured products * to be returned. */ - $variables = array( 'featured' => true ); + $variables = [ 'featured' => true ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -638,7 +638,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "maxPrice" where argument, and expect all product * with a price of 10.00+ to be returned. */ - $variables = array( 'maxPrice' => 10.00 ); + $variables = [ 'maxPrice' => 10.00 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -657,28 +657,28 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "orderby" where argument, and expect products to * be return in descending order by "price". */ - $variables = array( - 'orderby' => array( - array( + $variables = [ + 'orderby' => [ + [ 'field' => 'PRICE', 'order' => 'DESC', - ), - ), - ); + ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'products.nodes', - array( 'id' => $this->toRelayId( 'product', $product_ids[0] ) ), + [ 'id' => $this->toRelayId( 'product', $product_ids[0] ) ], 0 ), $this->expectedNode( 'products.nodes', - array( 'id' => $this->toRelayId( 'product', $product_ids[1] ) ), + [ 'id' => $this->toRelayId( 'product', $product_ids[1] ) ], 3 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -688,7 +688,7 @@ function( $node, $index ) use ( $product_ids ) { * Tests query with "category" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = array( 'category' => 'category-three' ); + $variables = [ 'category' => 'category-three' ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -709,7 +709,7 @@ function( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryIn" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = array( 'categoryIn' => array( 'category-three' ) ); + $variables = [ 'categoryIn' => [ 'category-three' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -721,7 +721,7 @@ function( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryId" where argument, and expect products in * the "category-three" category to be returned. */ - $variables = array( 'categoryId' => $category_3 ); + $variables = [ 'categoryId' => $category_3 ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion either. @@ -733,7 +733,7 @@ function( $node, $index ) use ( $product_ids, $category_3 ) { * Tests query with "categoryNotIn" where argument, and expect all products * except products in the "category-four" category to be returned. */ - $variables = array( 'categoryNotIn' => array( 'category-four' ) ); + $variables = [ 'categoryNotIn' => [ 'category-four' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -752,7 +752,7 @@ function( $node, $index ) use ( $product_ids, $category_4 ) { * Tests query with "categoryIdNotIn" where argument, and expect all products * except products in the "category-four" category to be returned. */ - $variables = array( 'categoryIdNotIn' => array( $category_4 ) ); + $variables = [ 'categoryIdNotIn' => [ $category_4 ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // No need to reassign the $expected for this assertion. @@ -764,7 +764,7 @@ function( $node, $index ) use ( $product_ids, $category_4 ) { * Tests query with "categoryIdIn" where argument, and expect products in * the "category-four" category to be returned. */ - $variables = array( 'categoryIdIn' => array( $category_4 ) ); + $variables = [ 'categoryIdIn' => [ $category_4 ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -782,22 +782,22 @@ function( $node, $index ) use ( $product_ids, $category_4 ) { * * Tests "taxonomyFilter" where argument */ - $variables = array( - 'taxonomyFilter' => array( + $variables = [ + 'taxonomyFilter' => [ 'relation' => 'AND', - 'filters' => array( - array( + 'filters' => [ + [ 'taxonomy' => 'PRODUCTCATEGORY', - 'terms' => array( 'category-three' ), - ), - array( + 'terms' => [ 'category-three' ], + ], + [ 'taxonomy' => 'PRODUCTCATEGORY', - 'terms' => array( 'category-four' ), + 'terms' => [ 'category-four' ], 'operator' => 'NOT_IN', - ), - ), - ), - ); + ], + ], + ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = array_filter( $all_expected_product_nodes, @@ -816,28 +816,28 @@ function( $node, $index ) use ( $product_ids, $category_4, $category_3 ) { * * Tests "include" where argument */ - $variables = array( - 'include' => array( $product_ids[0] ), - ); + $variables = [ + 'include' => [ $product_ids[0] ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'products.nodes', - array( 'id' => $this->toRelayId( 'product', $product_ids[0] ) ) + [ 'id' => $this->toRelayId( 'product', $product_ids[0] ) ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); - $variables = array( - 'include' => array( 1000 ), - ); + $variables = [ + 'include' => [ 1000 ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.nodes', - array() + [] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); /** @@ -845,26 +845,26 @@ function( $node, $index ) use ( $product_ids, $category_4, $category_3 ) { * * Tests "exclude" where argument */ - $variables = array( - 'exclude' => array( $product_ids[0] ), - ); + $variables = [ + 'exclude' => [ $product_ids[0] ], + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->not()->expectedNode( 'products.nodes', - array( 'id' => $this->toRelayId( 'product', $product_ids[0] ) ) + [ 'id' => $this->toRelayId( 'product', $product_ids[0] ) ] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); - $variables = array( 'exclude' => $product_ids ); + $variables = [ 'exclude' => $product_ids ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'products.nodes', - array() + [] ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -872,10 +872,10 @@ public function testProductToTermConnection() { $test_category = $this->factory->product->createProductCategory( 'test-product-category-1' ); $test_tag = $this->factory->product->createProductTag( 'test-product-tag-1' ); $product_id = $this->factory->product->createSimple( - array( - 'tag_ids' => array( $test_tag ), - 'category_ids' => array( $test_category ), - ) + [ + 'tag_ids' => [ $test_tag ], + 'category_ids' => [ $test_category ], + ] ); $relay_id = $this->toRelayId( 'product', $product_id ); @@ -899,21 +899,21 @@ public function testProductToTermConnection() { } '; - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $relay_id ), $this->expectedNode( 'product.productTags.nodes', - array( 'name' => 'test-product-tag-1' ), + [ 'name' => 'test-product-tag-1' ], 0 ), $this->expectedNode( 'product.productCategories.nodes', - array( 'name' => 'test-product-category-1' ), + [ 'name' => 'test-product-category-1' ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -921,21 +921,21 @@ public function testProductToTermConnection() { public function testTermToProductConnection() { $test_tag = $this->factory->product->createProductTag( 'test-product-tag-2' ); $image_id = $this->factory->post->create( - array( + [ 'post_author' => $this->shop_manager, 'post_status' => 'publish', 'post_title' => 'Product Image', 'post_type' => 'attachment', - ) + ] ); $test_category = $this->factory->product->createProductCategory( 'test-product-category-2' ); update_term_meta( $test_category, 'thumbnail_id', $image_id ); $product_id = $this->factory->product->createSimple( - array( - 'tag_ids' => array( $test_tag ), - 'category_ids' => array( $test_category ), - ) + [ + 'tag_ids' => [ $test_tag ], + 'category_ids' => [ $test_category ], + ] ); $query = ' @@ -971,51 +971,51 @@ public function testTermToProductConnection() { '; $response = graphql( compact( 'query' ) ); - $expected = array( + $expected = [ $this->expectedNode( 'productTags.nodes', - array( + [ 'name' => 'test-product-tag-2', - 'products' => array( - 'nodes' => array( - array( 'id' => $this->toRelayId( 'product', $product_id ) ), - ), - ), - ), + 'products' => [ + 'nodes' => [ + [ 'id' => $this->toRelayId( 'product', $product_id ) ], + ], + ], + ], 0 ), $this->expectedNode( 'productCategories.nodes', - array( + [ 'name' => 'test-product-category-2', - 'image' => array( 'id' => $this->toRelayId( 'post', $image_id ) ), - 'products' => array( - 'nodes' => array( - array( 'id' => $this->toRelayId( 'product', $product_id ) ), - ), - ), - ), + 'image' => [ 'id' => $this->toRelayId( 'post', $image_id ) ], + 'products' => [ + 'nodes' => [ + [ 'id' => $this->toRelayId( 'product', $product_id ) ], + ], + ], + ], 0 ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testProductToMediaItemConnections() { $image_id = $this->factory->post->create( - array( + [ 'post_author' => $this->shop_manager, 'post_status' => 'publish', 'post_title' => 'Product Image', 'post_type' => 'attachment', - ) + ] ); $product_id = $this->factory->product->createSimple( - array( + [ 'image_id' => $image_id, - 'gallery_image_ids' => array( $image_id ), - ) + 'gallery_image_ids' => [ $image_id ], + ] ); $product_relay_id = $this->toRelayId( 'product', $product_id ); @@ -1039,23 +1039,23 @@ public function testProductToMediaItemConnections() { } '; - $variables = array( 'id' => $product_relay_id ); + $variables = [ 'id' => $product_relay_id ]; $response = graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $product_relay_id ), $this->expectedField( 'product.image.id', $image_relay_id ), - $this->expectedNode( 'product.galleryImages.nodes', array( 'id' => $image_relay_id ) ), - ); + $this->expectedNode( 'product.galleryImages.nodes', [ 'id' => $image_relay_id ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testProductDownloads() { $product_id = $this->factory->product->createSimple( - array( + [ 'downloadable' => true, - 'downloads' => array( $this->factory->product->createDownload() ), - ) + 'downloads' => [ $this->factory->product->createDownload() ], + ] ); $relay_id = $this->toRelayId( 'product', $product_id ); @@ -1080,22 +1080,22 @@ public function testProductDownloads() { } '; - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.downloads', $this->getExpectedProductDownloadData( $product_id ) ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testExternalProductQuery() { $product_id = $this->factory->product->createExternal( - array( + [ 'product_url' => 'http://woographql.com', 'button_text' => 'Buy a external product', - ) + ] ); $relay_id = $this->toRelayId( 'product', $product_id ); @@ -1111,34 +1111,34 @@ public function testExternalProductQuery() { } '; - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.buttonText', 'Buy a external product' ), $this->expectedField( 'product.externalUrl', 'http://woographql.com' ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testGroupProductConnections() { $product_id = $this->factory->product->createGrouped( - array( + [ 'name' => 'Test Group', - 'children' => array(), - ) - ); - $grouped_product_ids = array( - $this->factory->product->createSimple( array( 'regular_price' => '1.00' ) ), - $this->factory->product->createSimple( array( 'regular_price' => '5.00' ) ), - $this->factory->product->createSimple( array( 'regular_price' => '10.00' ) ), + 'children' => [], + ] ); + $grouped_product_ids = [ + $this->factory->product->createSimple( [ 'regular_price' => '1.00' ] ), + $this->factory->product->createSimple( [ 'regular_price' => '5.00' ] ), + $this->factory->product->createSimple( [ 'regular_price' => '10.00' ] ), + ]; $product = \wc_get_product( $product_id ); $this->factory->product->update_object( $product, - array( 'children' => $grouped_product_ids ) + [ 'children' => $grouped_product_ids ] ); $relay_id = $this->toRelayId( 'product', $product_id ); @@ -1158,9 +1158,9 @@ public function testGroupProductConnections() { } '; - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.addToCartText', 'View products' ), $this->expectedField( @@ -1168,12 +1168,12 @@ public function testGroupProductConnections() { /* translators: %s: Group name */ sprintf( __( 'View products in the “%s” group', 'wp-graphql-woocommerce' ), 'Test Group' ) ), - ); + ]; foreach ( $product->get_children() as $grouped_product_id ) { $expected[] = $this->expectedNode( 'product.products.nodes', - array( 'id' => $this->toRelayId( 'product', $grouped_product_id ) ) + [ 'id' => $this->toRelayId( 'product', $grouped_product_id ) ] ); } @@ -1190,7 +1190,7 @@ public function testGroupProductConnections() { '; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'product.price', '$1.00 - $10.00' ) ); + $expected = [ $this->expectedField( 'product.price', '$1.00 - $10.00' ) ]; $this->assertQuerySuccessful( $response, $expected ); } @@ -1228,25 +1228,25 @@ public function testRelatedProductConnections() { } '; - $variables = array( 'id' => $this->toRelayId( 'product', $products['product'] ) ); + $variables = [ 'id' => $this->toRelayId( 'product', $products['product'] ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array(); + $expected = []; foreach ( $products['related'] + $products['cross_sell'] + $products['upsell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.related.nodes', - array( 'id' => $this->toRelayId( 'product', $product_id ) ) + [ 'id' => $this->toRelayId( 'product', $product_id ) ] ); } foreach ( $products['cross_sell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.crossSell.nodes', - array( 'id' => $this->toRelayId( 'product', $product_id ) ) + [ 'id' => $this->toRelayId( 'product', $product_id ) ] ); } foreach ( $products['upsell'] as $product_id ) { $expected[] = $this->expectedNode( 'product.upsell.nodes', - array( 'id' => $this->toRelayId( 'product', $product_id ) ) + [ 'id' => $this->toRelayId( 'product', $product_id ) ] ); } @@ -1255,13 +1255,13 @@ public function testRelatedProductConnections() { public function testProductToReviewConnections() { $product_id = $this->factory->product->createSimple(); - $reviews = array( + $reviews = [ $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), $this->factory->product->createReview( $product_id ), - ); + ]; $relay_id = $this->toRelayId( 'product', $product_id ); $product = \wc_get_product( $product_id ); @@ -1282,20 +1282,20 @@ public function testProductToReviewConnections() { } '; - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'product.id', $relay_id ), $this->expectedField( 'product.reviews.averageRating', floatval( $product->get_average_rating() ) ), - ); + ]; foreach ( $reviews as $review_id ) { $expected[] = $this->expectedEdge( 'product.reviews.edges', - array( + [ 'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ), - 'node' => array( 'id' => $this->toRelayId( 'comment', $review_id ) ), - ) + 'node' => [ 'id' => $this->toRelayId( 'comment', $review_id ) ], + ] ); } @@ -1304,13 +1304,13 @@ public function testProductToReviewConnections() { public function testProductGalleryImagesConnection() { $image_id = $this->factory->post->create( - array( + [ 'post_type' => 'attachment', 'post_content' => 'Lorem ipsum dolor...', - ) + ] ); $product_id = $this->factory->product->createSimple( - array( 'gallery_image_ids' => array( $image_id ) ) + [ 'gallery_image_ids' => [ $image_id ] ] ); $query = ' @@ -1325,16 +1325,16 @@ public function testProductGalleryImagesConnection() { } '; - $variables = array( 'id' => $this->toRelayId( 'product', $product_id ) ); + $variables = [ 'id' => $this->toRelayId( 'product', $product_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $this->assertQuerySuccessful( $response, - array( + [ $this->expectedNode( 'product.galleryImages.nodes', - array( 'id' => $this->toRelayId( 'post', $image_id ) ) + [ 'id' => $this->toRelayId( 'post', $image_id ) ] ), - ) + ] ); } } diff --git a/tests/wpunit/ProductReviewMutationsTest.php b/tests/wpunit/ProductReviewMutationsTest.php index 2cdfd9c8b..ec96ba33f 100644 --- a/tests/wpunit/ProductReviewMutationsTest.php +++ b/tests/wpunit/ProductReviewMutationsTest.php @@ -9,8 +9,8 @@ public function setUp(): void { parent::setUp(); // your set up methods here - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->products = $this->getModule( '\Helper\Wpunit' )->product(); } @@ -29,10 +29,10 @@ private function run_mutation( $mutation_name, $input = null ) { "; $results = graphql( - array( + [ 'query' => $mutation, - 'variables' => array( 'input' => $input ), - ) + 'variables' => [ 'input' => $input ], + ] ); // Use --debug flag to view @@ -44,134 +44,134 @@ private function run_mutation( $mutation_name, $input = null ) { // tests public function testCreateNewReviewMutation() { wp_set_current_user( $this->shop_manager ); - $input = array( + $input = [ 'clientMutationId' => 'some_id', 'rating' => 1, 'commentOn' => $this->products->create_simple(), 'content' => 'It came covered in poop!!!', 'author' => 'Rude customer', 'authorEmail' => 'rude-guy@example.com', - ); + ]; $actual = $this->run_mutation( 'writeReview', $input ); - $expected = array( - 'data' => array( - 'writeReview' => array( + $expected = [ + 'data' => [ + 'writeReview' => [ 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => array( + 'review' => [ 'content' => 'It came covered in poop!!!', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } public function testUpdateReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - array( + [ 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ) + ] ); update_comment_meta( $comment_id, 'rating', 1 ); - $input = array( + $input = [ 'clientMutationId' => 'some_id', 'rating' => 5, 'id' => Relay::toGlobalId( 'comment', $comment_id ), 'content' => 'Turns out it was Nutella. My bad =P', - ); + ]; $actual = $this->run_mutation( 'updateReview', $input ); - $expected = array( - 'data' => array( - 'updateReview' => array( + $expected = [ + 'data' => [ + 'updateReview' => [ 'clientMutationId' => 'some_id', 'rating' => 5.0, - 'review' => array( + 'review' => [ 'content' => 'Turns out it was Nutella. My bad =P', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } public function testDeleteReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - array( + [ 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ) + ] ); update_comment_meta( $comment_id, 'rating', 1 ); - $input = array( + $input = [ 'clientMutationId' => 'some_id', 'id' => Relay::toGlobalID( 'comment', $comment_id ), - ); + ]; $actual = $this->run_mutation( 'deleteReview', $input ); - $expected = array( - 'data' => array( - 'deleteReview' => array( + $expected = [ + 'data' => [ + 'deleteReview' => [ 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => array( + 'review' => [ 'content' => 'It came covered in poop!!!', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } public function testRestoreReviewMutation() { wp_set_current_user( $this->shop_manager ); $comment_id = $this->factory()->comment->create( - array( + [ 'comment_author' => 'Rude customer', 'comment_author_email' => 'rude-guy@example.com', 'comment_post_ID' => $this->products->create_simple(), 'comment_content' => 'It came covered in poop!!!', 'comment_approved' => 1, 'comment_type' => 'review', - ) + ] ); update_comment_meta( $comment_id, 'rating', 1 ); // Trash comment wp_delete_comment( $comment_id ); - $input = array( + $input = [ 'clientMutationId' => 'some_id', 'id' => Relay::toGlobalID( 'comment', $comment_id ), - ); + ]; $actual = $this->run_mutation( 'restoreReview', $input ); - $expected = array( - 'data' => array( - 'restoreReview' => array( + $expected = [ + 'data' => [ + 'restoreReview' => [ 'clientMutationId' => 'some_id', 'rating' => 1.0, - 'review' => array( + 'review' => [ 'content' => 'It came covered in poop!!!', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals( $expected, $actual ); } } diff --git a/tests/wpunit/ProductVariationQueriesTest.php b/tests/wpunit/ProductVariationQueriesTest.php index 33897c79b..c9325dac8 100644 --- a/tests/wpunit/ProductVariationQueriesTest.php +++ b/tests/wpunit/ProductVariationQueriesTest.php @@ -10,8 +10,8 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase { public function setUp(): void { parent::setUp(); - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->product_helper = $this->getModule( '\Helper\Wpunit' )->product(); $this->helper = $this->getModule( '\Helper\Wpunit' )->product_variation(); $this->products = $this->helper->create( $this->product_helper->create_variable() ); @@ -74,17 +74,17 @@ public function testVariationQuery() { * * Tests "ID" ID type. */ - $variables = array( + $variables = [ 'id' => $id, 'idType' => 'ID', - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( 'data' => array( 'productVariation' => $this->helper->print_query( $variation_id ) ) ); + $expected = [ 'data' => [ 'productVariation' => $this->helper->print_query( $variation_id ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -98,18 +98,18 @@ public function testVariationQuery() { * * Tests "DATABASE_ID" ID type. */ - $variables = array( + $variables = [ 'id' => $variation_id, 'idType' => 'DATABASE_ID', - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( 'data' => array( 'productVariation' => $this->helper->print_query( $variation_id ) ) ); + $expected = [ 'data' => [ 'productVariation' => $this->helper->print_query( $variation_id ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -156,12 +156,12 @@ public function testVariationsQueryAndWhereArgs() { * Test query with no arguments */ wp_set_current_user( $this->shop_manager ); - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); // use --debug flag to view. @@ -174,7 +174,7 @@ public function testVariationsQueryAndWhereArgs() { foreach ( $variations as $vid ) { $this->assertTrue( in_array( - array( 'id' => $this->helper->to_relay_id( $vid ) ), + [ 'id' => $this->helper->to_relay_id( $vid ) ], $product_data['variations']['nodes'], true ), @@ -183,7 +183,7 @@ public function testVariationsQueryAndWhereArgs() { } // Assert prices. - $prices = $this->product_helper->field( $this->products['product'], 'variation_prices', array( true ) ); + $prices = $this->product_helper->field( $this->products['product'], 'variation_prices', [ true ] ); $expected_price = \wc_graphql_price( current( $prices['price'] ) ) . ' - ' . \wc_graphql_price( end( $prices['price'] ) ); @@ -201,15 +201,15 @@ public function testVariationsQueryAndWhereArgs() { * * Test "minPrice" where argument */ - $variables = array( + $variables = [ 'id' => $id, 'minPrice' => 15, - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); // use --debug flag to view. @@ -227,7 +227,7 @@ public function testVariationsQueryAndWhereArgs() { foreach ( array_filter( $variations, $filter ) as $vid ) { $this->assertTrue( in_array( - array( 'id' => $this->helper->to_relay_id( $vid ) ), + [ 'id' => $this->helper->to_relay_id( $vid ) ], $product_data['variations']['nodes'], true ), @@ -249,26 +249,26 @@ public function testProductVariationToMediaItemConnections() { } '; - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'productVariation' => array( + $expected = [ + 'data' => [ + 'productVariation' => [ 'id' => $id, - 'image' => array( + 'image' => [ 'id' => Relay::toGlobalId( 'post', $this->helper->field( $this->products['variations'][1], 'image_id' ) ), - ), - ), - ), - ); + ], + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -297,21 +297,21 @@ public function testProductVariationDownloads() { } '; - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'productVariation' => array( + $expected = [ + 'data' => [ + 'productVariation' => [ 'id' => $id, 'downloads' => $this->helper->print_downloads( $this->products['variations'][0] ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/tests/wpunit/QLSessionHandlerTest.php b/tests/wpunit/QLSessionHandlerTest.php index 741e269ad..23b491a97 100644 --- a/tests/wpunit/QLSessionHandlerTest.php +++ b/tests/wpunit/QLSessionHandlerTest.php @@ -121,12 +121,12 @@ public function test_set_customer_session_token() { // Should fail to set headers if run before initialization. $session->set_customer_session_token( true ); - $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() ); + $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] ); $this->assertArrayNotHasKey( 'woocommerce-session', $graphql_response_headers ); // Should success when run after initialization. $session->init_session_token(); - $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() ); + $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] ); $this->assertArrayHasKey( 'woocommerce-session', $graphql_response_headers ); } diff --git a/tests/wpunit/RefundQueriesTest.php b/tests/wpunit/RefundQueriesTest.php index 89f81b7b3..330340980 100644 --- a/tests/wpunit/RefundQueriesTest.php +++ b/tests/wpunit/RefundQueriesTest.php @@ -6,7 +6,7 @@ class RefundQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL public function expectedRefundData( $refund_id ) { $refund = \wc_get_order( $refund_id ); - return array( + return [ $this->expectedField( 'refund.id', $this->toRelayId( 'shop_order_refund', $refund_id ) ), $this->expectedField( 'refund.databaseId', $refund->get_id() ), $this->expectedField( 'refund.title', $refund->get_post_title() ), @@ -14,13 +14,13 @@ public function expectedRefundData( $refund_id ) { $this->expectedField( 'refund.amount', floatval( $refund->get_amount() ) ), $this->expectedField( 'refund.refundedBy.databaseId', $refund->get_refunded_by() ), $this->expectedField( 'refund.date', (string) $refund->get_date_modified() ), - ); + ]; } // tests public function testRefundQuery() { $customer_id = $this->factory->customer->create(); - $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) ); + $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] ); $refund_id = $this->factory->refund->createNew( $order_id ); $relay_id = $this->toRelayId( 'shop_order_refund', $refund_id ); @@ -46,9 +46,9 @@ public function testRefundQuery() { * Test query and failed results for users lacking required caps */ $this->loginAs( $customer_id ); - $variables = array( 'id' => $relay_id ); + $variables = [ 'id' => $relay_id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( + $expected = [ $this->expectedField( 'refund.id', $relay_id ), $this->expectedField( 'refund.databaseId', $refund_id ), $this->expectedField( 'refund.title', self::IS_NULL ), @@ -56,7 +56,7 @@ public function testRefundQuery() { $this->expectedField( 'refund.amount', self::IS_NULL ), $this->expectedField( 'refund.refundedBy', self::IS_NULL ), $this->expectedField( 'refund.date', self::IS_NULL ), - ); + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -77,7 +77,7 @@ public function testRefundQuery() { public function testRefundQueryAndIds() { $customer_id = $this->factory->customer->create(); - $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) ); + $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] ); $refund_id = $this->factory->refund->createNew( $order_id ); $relay_id = $this->toRelayId( 'shop_order_refund', $refund_id ); @@ -95,12 +95,12 @@ public function testRefundQueryAndIds() { * Test query and "id" argument */ $this->loginAs( $customer_id ); - $variables = array( + $variables = [ 'id' => $relay_id, 'idType' => 'ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( $this->expectedField( 'refund.id', $relay_id ) ); + $expected = [ $this->expectedField( 'refund.id', $relay_id ) ]; $this->assertQuerySuccessful( $response, $expected ); @@ -111,10 +111,10 @@ public function testRefundQueryAndIds() { * * Test query and "refundId" argument */ - $variables = array( + $variables = [ 'id' => $refund_id, 'idType' => 'DATABASE_ID', - ); + ]; $response = $this->graphql( compact( 'query', 'variables' ) ); // Same $expected as last assertion. @@ -123,12 +123,12 @@ public function testRefundQueryAndIds() { public function testRefundsQueryAndWhereArgs() { $order_id = $this->factory->order->createNew(); - $refunds = array( + $refunds = [ $this->factory->refund->createNew( $order_id ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - $this->factory->refund->createNew( $this->factory->order->createNew(), array( 'status' => 'pending' ) ), + $this->factory->refund->createNew( $this->factory->order->createNew(), [ 'status' => 'pending' ] ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - ); + ]; $query = ' query ( $statuses: [String], $orderIn: [Int] ) { @@ -150,9 +150,9 @@ public function testRefundsQueryAndWhereArgs() { */ $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( - $this->expectedField( 'refunds.nodes', array() ), - ); + $expected = [ + $this->expectedField( 'refunds.nodes', [] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -165,12 +165,12 @@ public function testRefundsQueryAndWhereArgs() { */ $this->loginAsShopManager(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ), - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[2] ) ), - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ), - ); + $expected = [ + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ), + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[2] ] ), + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -182,14 +182,14 @@ public function testRefundsQueryAndWhereArgs() { * Test "statuses" where argument results should be empty * Note: This argument is functionally useless Refunds' "post_status" is always set to "completed". */ - $variables = array( 'statuses' => array( 'completed' ) ); + $variables = [ 'statuses' => [ 'completed' ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ), - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ), - ); + $expected = [ + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ), + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); @@ -200,29 +200,29 @@ public function testRefundsQueryAndWhereArgs() { * * Test "orderIn" where argument */ - $variables = array( 'orderIn' => array( $order_id ) ); + $variables = [ 'orderIn' => [ $order_id ] ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ), - ); + $expected = [ + $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testOrderToRefundsConnection() { $order_id = $this->factory->order->createNew(); - $refunds = array( - $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ), + $refunds = [ + $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ), $this->factory->refund->createNew( $order_id, - array( + [ 'status' => 'pending', 'amount' => 0.5, - ) + ] ), $this->factory->refund->createNew( $this->factory->order->createNew() ), - ); + ]; $query = ' query ( $id: ID! ) { @@ -237,30 +237,30 @@ public function testOrderToRefundsConnection() { '; $this->loginAsShopManager(); - $variables = array( 'id' => $this->toRelayId( 'shop_order', $order_id ) ); + $variables = [ 'id' => $this->toRelayId( 'shop_order', $order_id ) ]; $response = $this->graphql( compact( 'query', 'variables' ) ); - $expected = array( - $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[0] ) ), - $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[1] ) ), - ); + $expected = [ + $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[0] ] ), + $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[1] ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); } public function testCustomerToRefundsConnection() { - $order_id = $this->factory->order->createNew( array( 'customer_id' => $this->customer ) ); - $refunds = array( + $order_id = $this->factory->order->createNew( [ 'customer_id' => $this->customer ] ); + $refunds = [ $this->factory->refund->createNew( $this->factory->order->createNew() ), - $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ), + $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ), $this->factory->refund->createNew( $order_id, - array( + [ 'status' => 'pending', 'amount' => 0.5, - ) + ] ), - ); + ]; $query = ' query { @@ -277,11 +277,11 @@ public function testCustomerToRefundsConnection() { $this->loginAsCustomer(); $response = $this->graphql( compact( 'query' ) ); - $expected = array( - $this->not()->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[0] ) ), - $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[1] ) ), - $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[2] ) ), - ); + $expected = [ + $this->not()->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[0] ] ), + $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[1] ] ), + $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[2] ] ), + ]; $this->assertQuerySuccessful( $response, $expected ); } diff --git a/tests/wpunit/ShippingMethodQueriesTest.php b/tests/wpunit/ShippingMethodQueriesTest.php index 4055ac708..1a83a0c7e 100644 --- a/tests/wpunit/ShippingMethodQueriesTest.php +++ b/tests/wpunit/ShippingMethodQueriesTest.php @@ -11,8 +11,8 @@ class ShippingMethodQueriesTest extends \Codeception\TestCase\WPTestCase { public function setUp(): void { parent::setUp(); - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->helper = $this->getModule( '\Helper\Wpunit' )->shipping_method(); $this->method = 'flat_rate'; } @@ -37,17 +37,17 @@ public function testShippingMethodQueryAndArgs() { * * Test "ID" ID type. */ - $variables = array( + $variables = [ 'id' => $id, 'idType' => 'ID', - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( 'data' => array( 'shippingMethod' => $this->helper->print_query( $this->method ) ) ); + $expected = [ 'data' => [ 'shippingMethod' => $this->helper->print_query( $this->method ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -59,17 +59,17 @@ public function testShippingMethodQueryAndArgs() { * * Test "DATABASE_ID" ID type. */ - $variables = array( + $variables = [ 'id' => $this->method, 'idType' => 'DATABASE_ID', - ); + ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( 'data' => array( 'shippingMethod' => $this->helper->print_query( $this->method ) ) ); + $expected = [ 'data' => [ 'shippingMethod' => $this->helper->print_query( $this->method ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -82,7 +82,7 @@ public function testShippingMethodsQuery() { $methods = array_values( array_map( function( $method ) { - return array( 'id' => Relay::toGlobalId( 'shipping_method', $method->id ) ); + return [ 'id' => Relay::toGlobalId( 'shipping_method', $method->id ) ]; }, $wc_shipping->get_shipping_methods() ) @@ -104,7 +104,7 @@ function( $method ) { * Tests query */ $actual = do_graphql_request( $query, 'shippingMethodQuery' ); - $expected = array( 'data' => array( 'shippingMethods' => array( 'nodes' => $methods ) ) ); + $expected = [ 'data' => [ 'shippingMethods' => [ 'nodes' => $methods ] ] ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/tests/wpunit/TaxRateQueriesTest.php b/tests/wpunit/TaxRateQueriesTest.php index 194aaf468..8c5a59924 100644 --- a/tests/wpunit/TaxRateQueriesTest.php +++ b/tests/wpunit/TaxRateQueriesTest.php @@ -11,8 +11,8 @@ class TaxRateQueriesTest extends \Codeception\TestCase\WPTestCase { public function setUp(): void { parent::setUp(); - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->helper = $this->getModule( '\Helper\Wpunit' )->tax_rate(); $this->rate = $this->helper->create(); } @@ -46,9 +46,9 @@ class * * Tests query, "id" query arg, and results */ - $variables = array( 'id' => $id ); + $variables = [ 'id' => $id ]; $actual = do_graphql_request( $query, 'taxRateQuery', $variables ); - $expected = array( 'data' => array( 'taxRate' => $this->helper->print_query( $this->rate ) ) ); + $expected = [ 'data' => [ 'taxRate' => $this->helper->print_query( $this->rate ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -60,12 +60,12 @@ class * * Tests query, "rateId" query arg, and results */ - $variables = array( + $variables = [ 'id' => $this->rate, 'idType' => 'DATABASE_ID', - ); + ]; $actual = do_graphql_request( $query, 'taxRateQuery', $variables ); - $expected = array( 'data' => array( 'taxRate' => $this->helper->print_query( $this->rate ) ) ); + $expected = [ 'data' => [ 'taxRate' => $this->helper->print_query( $this->rate ) ] ]; // use --debug flag to view. codecept_debug( $actual ); @@ -74,10 +74,10 @@ class } public function testTaxesQuery() { - $rates = array( + $rates = [ $this->rate, $this->helper->create( - array( + [ 'country' => 'US', 'state' => 'AL', 'city' => 'Montgomery', @@ -88,10 +88,10 @@ public function testTaxesQuery() { 'compound' => '1', 'shipping' => '1', 'class' => 'reduced-rate', - ) + ] ), $this->helper->create( - array( + [ 'country' => 'US', 'state' => 'VA', 'city' => 'Norfolk', @@ -102,9 +102,9 @@ public function testTaxesQuery() { 'compound' => '1', 'shipping' => '1', 'class' => 'zero-rate', - ) + ] ), - ); + ]; $query = ' query ( $class: TaxClassEnum, $postCode: String, $postCodeIn: [String] ) { @@ -121,19 +121,19 @@ public function testTaxesQuery() { * * Tests query */ - $actual = graphql( array( 'query' => $query ) ); - $expected = array( - 'data' => array( - 'taxRates' => array( + $actual = graphql( [ 'query' => $query ] ); + $expected = [ + 'data' => [ + 'taxRates' => [ 'nodes' => array_map( function( $id ) { - return array( 'id' => Relay::toGlobalId( 'tax_rate', $id ) ); + return [ 'id' => Relay::toGlobalId( 'tax_rate', $id ) ]; }, $rates ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -145,19 +145,19 @@ function( $id ) { * * Tests "class" where arg */ - $variables = array( 'class' => 'REDUCED_RATE' ); + $variables = [ 'class' => 'REDUCED_RATE' ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'taxRates' => array( + $expected = [ + 'data' => [ + 'taxRates' => [ 'nodes' => array_map( function( $id ) { - return array( 'id' => Relay::toGlobalId( 'tax_rate', $id ) ); + return [ 'id' => Relay::toGlobalId( 'tax_rate', $id ) ]; }, array_values( array_filter( @@ -169,9 +169,9 @@ function( $id ) { ) ) ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -183,25 +183,25 @@ function( $id ) { * * Tests "postCode" where arg */ - $variables = array( 'postCode' => '23451' ); + $variables = [ 'postCode' => '23451' ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'taxRates' => array( + $expected = [ + 'data' => [ + 'taxRates' => [ 'nodes' => array_map( function( $id ) { - return array( 'id' => Relay::toGlobalId( 'tax_rate', $id ) ); + return [ 'id' => Relay::toGlobalId( 'tax_rate', $id ) ]; }, - array( $rates[2] ) + [ $rates[2] ] ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -213,25 +213,25 @@ function( $id ) { * * Tests "postCodeIn" where arg */ - $variables = array( 'postCodeIn' => array( '123456', '23451' ) ); + $variables = [ 'postCodeIn' => [ '123456', '23451' ] ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'taxRates' => array( + $expected = [ + 'data' => [ + 'taxRates' => [ 'nodes' => array_map( function( $id ) { - return array( 'id' => Relay::toGlobalId( 'tax_rate', $id ) ); + return [ 'id' => Relay::toGlobalId( 'tax_rate', $id ) ]; }, - array( $rates[1], $rates[2] ) + [ $rates[1], $rates[2] ] ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/tests/wpunit/VariationAttributeQueriesTest.php b/tests/wpunit/VariationAttributeQueriesTest.php index e3d8b2c31..b431d0deb 100644 --- a/tests/wpunit/VariationAttributeQueriesTest.php +++ b/tests/wpunit/VariationAttributeQueriesTest.php @@ -10,8 +10,8 @@ public function setUp(): void { // before parent::setUp(); - $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) ); - $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) ); + $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] ); + $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] ); $this->product = $this->getModule( '\Helper\Wpunit' )->product(); $this->variation = $this->getModule( '\Helper\Wpunit' )->product_variation(); $ids = $this->variation->create( $this->product->create_variable() ); @@ -44,21 +44,21 @@ public function testProductVariationToVariationAttributeQuery() { * * Test query and results */ - $variables = array( 'id' => $this->variation->to_relay_id( $this->variation_id ) ); + $variables = [ 'id' => $this->variation->to_relay_id( $this->variation_id ) ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'productVariation' => array( + $expected = [ + 'data' => [ + 'productVariation' => [ 'id' => $this->variation->to_relay_id( $this->variation_id ), 'attributes' => $this->variation->print_attributes( $this->variation_id ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); @@ -90,21 +90,21 @@ public function testProductToVariationAttributeQuery() { * * Test query and results */ - $variables = array( 'id' => $this->product->to_relay_id( $this->product_id ) ); + $variables = [ 'id' => $this->product->to_relay_id( $this->product_id ) ]; $actual = graphql( - array( + [ 'query' => $query, 'variables' => $variables, - ) + ] ); - $expected = array( - 'data' => array( - 'product' => array( + $expected = [ + 'data' => [ + 'product' => [ 'id' => $this->product->to_relay_id( $this->product_id ), 'defaultAttributes' => $this->variation->print_attributes( $this->product_id, 'PRODUCT' ), - ), - ), - ); + ], + ], + ]; // use --debug flag to view. codecept_debug( $actual ); diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index 13917b371..905631f81 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -20,13 +20,15 @@ * @license GPL-3 */ +namespace WPGraphQL\WooCommerce; + // Exit if accessed directly. defined( 'ABSPATH' ) || exit; /** * Setups WPGraphQL WooCommerce constants */ -function woographql_constants() { +function constants() { // Plugin version. if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) ) { define( 'WPGRAPHQL_WOOCOMMERCE_VERSION', '0.11.1' ); @@ -49,11 +51,52 @@ function woographql_constants() { } } +/** + * Returns path to plugin root directory. + * + * @return string + */ +function get_plugin_directory() { + return trailingslashit( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR ); +} + +/** + * Returns path to plugin "includes" directory. + * + * @return string + */ +function get_includes_directory() { + return trailingslashit( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR ) . 'includes/'; +} + +/** + * Returns path to plugin "vendor" directory. + * + * @return string + */ +function get_vendor_directory() { + return trailingslashit( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR ) . 'vendor/'; +} + +/** + * Returns url to a plugin file. + * + * @param string $filepath Relative path to plugin file. + * + * @return string + */ +function plugin_file_url( $filepath ) { + return plugins_url( $filepath, __FILE__ ); +} + /** * Checks if WPGraphQL WooCommerce required plugins are installed and activated + * + * @param array $deps Unloaded dependencies list. + * + * @return bool */ -function woographql_dependencies_not_ready() { - $deps = array(); +function dependencies_not_ready( &$deps = [] ) { if ( ! class_exists( '\WPGraphQL' ) ) { $deps[] = 'WPGraphQL'; } @@ -67,12 +110,9 @@ function woographql_dependencies_not_ready() { /** * Initializes WPGraphQL WooCommerce */ -function woographql_init() { - woographql_constants(); - - $not_ready = woographql_dependencies_not_ready(); - if ( empty( $not_ready ) ) { - require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'includes/class-wp-graphql-woocommerce.php'; +function init() { + if ( empty( dependencies_not_ready( $not_ready ) ) ) { + require_once get_includes_directory() . 'class-wp-graphql-woocommerce.php'; return WP_GraphQL_WooCommerce::instance(); } @@ -96,7 +136,11 @@ function() use ( $dep ) { } ); } - - return false; } -add_action( 'graphql_init', 'woographql_init' ); +add_action( 'graphql_init', 'WPGraphQL\WooCommerce\init' ); + +// Load constants. +constants(); + +// Load access functions. +require_once get_plugin_directory() . 'access-functions.php'; From 547de9dc83cd9fe6426a452f0366de67ed4c5bdb Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 26 Aug 2022 14:22:21 -0400 Subject: [PATCH 2/3] chore: lint compliance met. --- access-functions.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/access-functions.php b/access-functions.php index e858ce28e..f5aa64501 100644 --- a/access-functions.php +++ b/access-functions.php @@ -62,7 +62,7 @@ function wc_graphql_map_tax_statements( $raw_taxes ) { return array_values( $taxes ); } -} +}//end if if ( ! function_exists( 'wc_graphql_get_order_statuses' ) ) { /** @@ -157,7 +157,7 @@ function wc_graphql_price( $price, $args = [] ) { */ return apply_filters( 'graphql_woocommerce_price', $return, $price, $args, $unformatted_price, $symbol ); } -} +}//end if if ( ! function_exists( 'wc_graphql_price_range' ) ) { /** @@ -182,7 +182,7 @@ function wc_graphql_price_range( $from, $to ) { return apply_filters( 'graphql_woocommerce_format_price_range', $price, $from, $to ); } -} +}//end if if ( ! function_exists( 'wc_graphql_underscore_to_camel_case' ) ) { /** @@ -227,7 +227,8 @@ function wc_graphql_camel_case_to_underscore( $string ) { return implode( '_', $ret ); } -} +}//end if + @@ -237,6 +238,5 @@ function wc_graphql_camel_case_to_underscore( $string ) { - From 41cbbb0f43553f53a3e87fea3bb36f334c3f0b98 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 26 Aug 2022 14:40:47 -0400 Subject: [PATCH 3/3] chore: composer/installers added back to allow-plugins --- bin/_env.sh | 2 +- bin/_lib.sh | 2 +- composer.json | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/_env.sh b/bin/_env.sh index 50219749b..611b776f5 100644 --- a/bin/_env.sh +++ b/bin/_env.sh @@ -13,7 +13,7 @@ fi DB_HOST=${DB_HOST-localhost} DB_PASS=${DB_PASSWORD-""} -WP_VERSION=${WP_VERSION-5} +WP_VERSION=${WP_VERSION-6} PROJECT_ROOT_DIR=$(pwd) WP_CORE_DIR=${WP_CORE_DIR:-local/public} PLUGINS_DIR=${PLUGINS_DIR:-"$WP_CORE_DIR/wp-content/plugins"} diff --git a/bin/_lib.sh b/bin/_lib.sh index 17c7e242d..ea9d57e0c 100644 --- a/bin/_lib.sh +++ b/bin/_lib.sh @@ -22,7 +22,7 @@ install_wordpress() { # Install Wordpress + integrated plugins for testing/development. composer install composer require --dev -W \ - composer/installers:~1.0 \ + composer/installers \ johnpbloch/wordpress:~${WP_VERSION} \ wp-graphql/wp-graphql-jwt-authentication \ wpackagist-plugin/woocommerce \ diff --git a/composer.json b/composer.json index 0e1a09c92..e31df057d 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "process-timeout": 0, "sort-packages": true, "allow-plugins": { - "johnpbloch/wordpress-core-installer": true + "johnpbloch/wordpress-core-installer": true, + "composer/installers": true } }, "autoload-dev": {