diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index b819c6fc2..9ff26a88b 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -34,7 +34,7 @@ jobs: wordpress: '6.1' debug: '--debug' - wordpress: '6.2' - hpos: 0 + hpos: 1 fail-fast: false name: Running Automated Tests w/ WPBrowser in WordPress v${{ matrix.wordpress }} on PHP${{ matrix.php }} ${{ matrix.hpos == 1 && 'with HPOS activated ' || '' }}${{ matrix.coverage == '--coverage --coverage-xml' && 'with Codecoverage ' || '' }}${{ matrix.debug == '--debug' && 'in Debug Mode ' || '' }} diff --git a/.gitignore b/.gitignore index d0cef9d22..3b862ddf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store phpcs.xml phpunit.xml +phpstan.neon Thumbs.db wp-cli.local.yml node_modules/ diff --git a/composer.json b/composer.json index 09a61a6a5..21c67d6ae 100644 --- a/composer.json +++ b/composer.json @@ -25,14 +25,12 @@ "firebase/php-jwt": "^6.1.0" }, "require-dev": { - "automattic/vipwpcs": "^2.3", + "axepress/wp-graphql-cs": "^1.0.0-beta", "axepress/wp-graphql-stubs": "1.14.0", "php-stubs/woocommerce-stubs": "7.5.0", "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", - "squizlabs/php_codesniffer": "^3.5", - "szepeviktor/phpstan-wordpress": "^1.3", - "wp-coding-standards/wpcs": "^2.3" + "szepeviktor/phpstan-wordpress": "^1.3" }, "config": { "platform": { diff --git a/composer.lock b/composer.lock index 0c0d54d66..e3cc052ad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1fe0d1a5418403ab97ed669378c504f9", + "content-hash": "80fff7fe58495246e8a37a729ee89164", "packages": [ { "name": "firebase/php-jwt", @@ -123,6 +123,66 @@ }, "time": "2021-09-29T16:20:23+00:00" }, + { + "name": "axepress/wp-graphql-cs", + "version": "1.0.0-beta.2", + "source": { + "type": "git", + "url": "https://github.com/AxeWP/WPGraphQL-Coding-Standards.git", + "reference": "e45e4d5eb627c6a7add20c2ebf8d337febdf499d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/AxeWP/WPGraphQL-Coding-Standards/zipball/e45e4d5eb627c6a7add20c2ebf8d337febdf499d", + "reference": "e45e4d5eb627c6a7add20c2ebf8d337febdf499d", + "shasum": "" + }, + "require": { + "automattic/vipwpcs": "^2.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": ">=7.2", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "slevomat/coding-standard": "^8.12", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^8.5 || ^9" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "AxePress Development", + "email": "support@axepress.dev", + "homepage": "https://axepress.dev" + }, + { + "name": "David Levine", + "role": "Developer" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) for the WPGraphQL ecosystem.", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress", + "wpcs", + "wpgraphql" + ], + "support": { + "issues": "https://github.com/AxeWP/WPGraphQL-Coding-Standards/issues", + "source": "https://github.com/AxeWP/WPGraphQL-Coding-Standards" + }, + "time": "2023-06-17T14:52:55+00:00" + }, { "name": "axepress/wp-graphql-stubs", "version": "v1.14.0", @@ -339,6 +399,180 @@ }, "time": "2023-05-18T04:35:23+00:00" }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2022-10-25T01:46:02+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+00:00" + }, { "name": "phpstan/extension-installer", "version": "1.3.1", @@ -383,6 +617,53 @@ }, "time": "2023-05-24T08:59:17+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.22.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/65c39594fbd8c67abfc68bb323f86447bab79cc0", + "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.1" + }, + "time": "2023-06-29T20:46:06+00:00" + }, { "name": "phpstan/phpstan", "version": "1.10.25", @@ -503,6 +784,71 @@ }, "time": "2023-03-31T16:46:32+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "8.13.1", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "a13c15e20f2d307a1ca8dec5313ec462a4466470" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/a13c15e20f2d307a1ca8dec5313ec462a4466470", + "reference": "a13c15e20f2d307a1ca8dec5313ec462a4466470", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.22.0", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.21", + "phpstan/phpstan-deprecation-rules": "1.1.3", + "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan-strict-rules": "1.5.1", + "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.2" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.13.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2023-06-25T12:52:34+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.7.2", @@ -752,7 +1098,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "axepress/wp-graphql-cs": 10 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/includes/admin/class-general.php b/includes/admin/class-general.php index 6fb8810ed..a699ddbee 100644 --- a/includes/admin/class-general.php +++ b/includes/admin/class-general.php @@ -11,7 +11,6 @@ * General class */ class General extends Section { - /** * Returns the other nonce values besides the one provided. * @@ -102,7 +101,7 @@ public static function get_fields() { ), 'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ), 'disabled' => $enable_auth_urls_hardcoded, - 'sanitize_callback' => static function( $value ) { + 'sanitize_callback' => static function ( $value ) { if ( empty( $value ) ) { return []; } diff --git a/includes/admin/class-section.php b/includes/admin/class-section.php index 7da621815..80d21c227 100644 --- a/includes/admin/class-section.php +++ b/includes/admin/class-section.php @@ -11,7 +11,6 @@ * Section class */ abstract class Section { - /** * Returns Section settings fields. * diff --git a/includes/class-acf-schema-filters.php b/includes/class-acf-schema-filters.php index f6fce85ee..05b19e923 100644 --- a/includes/class-acf-schema-filters.php +++ b/includes/class-acf-schema-filters.php @@ -12,7 +12,6 @@ * Class ACF_Schema_Filters */ class ACF_Schema_Filters { - /** * Register filters * @@ -20,8 +19,8 @@ class ACF_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs && taxonomies. - 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 ); + add_filter( 'graphql_acf_get_root_id', [ self::class, 'resolve_crud_root_id' ], 10, 2 ); + add_filter( 'graphql_acf_post_object_source', [ self::class, 'resolve_post_object_source' ], 10, 2 ); } /** diff --git a/includes/class-admin.php b/includes/class-admin.php index cc27cb7d0..55cd5bbef 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -15,7 +15,6 @@ * Class Admin */ class Admin { - /** * Admin constructor */ diff --git a/includes/class-core-schema-filters.php b/includes/class-core-schema-filters.php index a5e642a4c..1bbb7c36b 100644 --- a/includes/class-core-schema-filters.php +++ b/includes/class-core-schema-filters.php @@ -26,14 +26,14 @@ class Core_Schema_Filters { */ public static function add_filters() { // Registers WooCommerce CPTs. - 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 ); + add_filter( 'register_post_type_args', [ self::class, 'register_post_types' ], 10, 2 ); + add_filter( 'graphql_post_entities_allowed_post_types', [ self::class, 'skip_type_registry' ], 10 ); // Registers WooCommerce taxonomies. - add_filter( 'register_taxonomy_args', [ __CLASS__, 'register_taxonomy_args' ], 10, 2 ); + add_filter( 'register_taxonomy_args', [ self::class, 'register_taxonomy_args' ], 10, 2 ); // Add data-loaders to AppContext. - add_filter( 'graphql_data_loaders', [ __CLASS__, 'graphql_data_loaders' ], 10, 2 ); + add_filter( 'graphql_data_loaders', [ self::class, 'graphql_data_loaders' ], 10, 2 ); // Add node resolvers. add_filter( @@ -52,21 +52,21 @@ public static function add_filters() { // Filter Unions. add_filter( 'graphql_wp_union_type_config', - [ __CLASS__, 'inject_union_types' ], + [ self::class, 'inject_union_types' ], 10, 2 ); add_filter( 'graphql_union_resolve_type', - [ __CLASS__, 'inject_type_resolver' ], + [ self::class, 'inject_type_resolver' ], 10, 2 ); add_filter( 'graphql_interface_resolve_type', - [ __CLASS__, 'inject_type_resolver' ], + [ self::class, 'inject_type_resolver' ], 10, 2 ); @@ -120,7 +120,7 @@ public static function add_filters() { add_filter( 'woographql_cart_connection_definitions', - [ __CLASS__, 'skip_cart_item_connection' ] + [ self::class, 'skip_cart_item_connection' ] ); } @@ -141,7 +141,7 @@ public static function register_post_types( $args, $post_type ) { $args['graphql_interfaces'] = [ 'ContentNode' ]; $args['graphql_register_root_field'] = false; $args['graphql_register_root_connection'] = false; - $args['graphql_resolve_type'] = static function( $value ) { + $args['graphql_resolve_type'] = static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); $possible_types = WooGraphQL::get_enabled_product_types(); if ( isset( $possible_types[ $value->type ] ) ) { @@ -306,7 +306,7 @@ public static function inject_union_types( $config, $wp_union ) { $config['typeNames'] = array_merge( array_filter( $config['typeNames'], - static function( $type ) { + static function ( $type ) { return 'Product' !== $type; } ), diff --git a/includes/class-jwt-auth-schema-filters.php b/includes/class-jwt-auth-schema-filters.php index af33d1f25..c20c288a4 100644 --- a/includes/class-jwt-auth-schema-filters.php +++ b/includes/class-jwt-auth-schema-filters.php @@ -24,10 +24,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', [ __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 ); + add_filter( 'graphql_jwt_user_types', [ self::class, 'add_customer_to_jwt_user_types' ], 10 ); + add_filter( 'graphql_registerCustomerPayload_fields', [ self::class, 'add_jwt_output_fields' ], 10, 3 ); + add_filter( 'graphql_updateCustomerPayload_fields', [ self::class, 'add_jwt_output_fields' ], 10, 3 ); + add_action( 'graphql_register_types', [ self::class, 'add_customer_to_login_payload' ], 10 ); } } @@ -59,7 +59,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) 'authToken' => [ 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); if ( ! $user ) { @@ -83,7 +83,7 @@ public static function add_jwt_output_fields( $fields, $object, $type_registry ) 'refreshToken' => [ 'type' => $type_registry->get_type( 'String' ), 'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $user = get_user_by( 'ID', $payload['id'] ); if ( ! $user ) { @@ -122,7 +122,7 @@ public static function add_customer_to_login_payload() { [ 'type' => 'Customer', 'description' => __( 'Customer object of authenticated user.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $id = $payload['id']; return new Customer( $id ); }, @@ -136,7 +136,7 @@ public static function add_customer_to_login_payload() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { /** * Session Handler. * diff --git a/includes/class-type-registry.php b/includes/class-type-registry.php index a27779e96..2fb8dff30 100644 --- a/includes/class-type-registry.php +++ b/includes/class-type-registry.php @@ -12,8 +12,6 @@ * Class Type_Registry */ class Type_Registry { - - /** * Registers WooGraphQL types, connections, unions, and mutations to GraphQL schema * diff --git a/includes/class-woocommerce-filters.php b/includes/class-woocommerce-filters.php index 76793fb91..5e6ea366b 100644 --- a/includes/class-woocommerce-filters.php +++ b/includes/class-woocommerce-filters.php @@ -14,7 +14,6 @@ * Class WooCommerce_Filters */ class WooCommerce_Filters { - /** * Stores instance session header name. * @@ -32,13 +31,13 @@ public static function setup() { // Check if request is a GraphQL POST request. if ( ! self::is_session_handler_disabled() ) { - 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_filter( 'woocommerce_session_handler', [ self::class, 'woocommerce_session_handler' ] ); + add_filter( 'graphql_response_headers_to_send', [ self::class, 'add_session_header_to_expose_headers' ] ); + add_filter( 'graphql_access_control_allow_headers', [ self::class, 'add_session_header_to_allow_headers' ] ); } // Add better support for Stripe payment gateway. - add_filter( 'graphql_stripe_process_payment_args', [ __CLASS__, 'woographql_stripe_gateway_args' ], 10, 2 ); + add_filter( 'graphql_stripe_process_payment_args', [ self::class, 'woographql_stripe_gateway_args' ], 10, 2 ); } /** diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index 8604738cf..6d1c9d326 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -17,7 +17,6 @@ * Class WP_GraphQL_WooCommerce */ final class WP_GraphQL_WooCommerce { - /** * Stores the instance of the WP_GraphQL_WooCommerce class * diff --git a/includes/connection/class-comments.php b/includes/connection/class-comments.php index 88e62bc2e..968fd3b53 100644 --- a/includes/connection/class-comments.php +++ b/includes/connection/class-comments.php @@ -18,7 +18,6 @@ * Class - Comments */ class Comments extends Comments_Core { - /** * Registers connection. */ @@ -34,7 +33,7 @@ public static function register_connections() { 'averageRating' => [ 'type' => 'Float', 'description' => __( 'Average review rating for this product.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -47,7 +46,7 @@ public static function register_connections() { 'rating' => [ 'type' => 'Float', 'description' => __( 'Review rating', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $review = $source['node']; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $rating = get_comment_meta( $review->commentId, 'rating', true ); @@ -55,7 +54,7 @@ public static function register_connections() { }, ], ], - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post_type', 'product' ); @@ -78,14 +77,14 @@ public static function register_connections() { 'isCustomerNote' => [ 'type' => 'Boolean', 'description' => __( 'Is this a customer note?', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $note = $source['node']; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return get_comment_meta( $note->commentId, 'is_customer_note', true ); }, ], ], - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new \WPGraphQL\Data\Connection\CommentConnectionResolver( $source, $args, $context, $info ); $resolver->set_query_arg( 'post_id', $source->ID ); diff --git a/includes/connection/class-coupons.php b/includes/connection/class-coupons.php index 7aafe1403..a05e66616 100644 --- a/includes/connection/class-coupons.php +++ b/includes/connection/class-coupons.php @@ -15,7 +15,6 @@ * Class - Coupons */ class Coupons { - /** * Registers the various connections from other Types to Coupon * diff --git a/includes/connection/class-customers.php b/includes/connection/class-customers.php index d5a249d07..56276905c 100644 --- a/includes/connection/class-customers.php +++ b/includes/connection/class-customers.php @@ -18,7 +18,6 @@ * Class - Customers */ class Customers { - /** * Registers the various connections from other Types to Customer * diff --git a/includes/connection/class-orders.php b/includes/connection/class-orders.php index c8f0cd239..81ecde55a 100644 --- a/includes/connection/class-orders.php +++ b/includes/connection/class-orders.php @@ -17,7 +17,6 @@ * Class - Orders */ class Orders { - /** * Registers the various connections from other Types to Customer * @@ -35,7 +34,7 @@ public static function register_connections() { [ 'fromType' => 'Customer', 'fromFieldName' => 'orders', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info ); return self::get_customer_order_connection( $resolver, $source ); @@ -63,7 +62,7 @@ public static function register_connections() { 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' ); $resolver->set_should_execute( true ); @@ -83,7 +82,7 @@ public static function register_connections() { 'toType' => 'Refund', 'fromFieldName' => 'refunds', 'connectionArgs' => self::get_refund_connection_args(), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Order_Connection_Resolver( $source, $args, $context, $info, 'shop_order_refund' ); return self::get_customer_refund_connection( $resolver, $source ); @@ -213,7 +212,7 @@ public static function get_connection_config( $args = [], $post_type = 'shop_ord 'toType' => 'Order', 'fromFieldName' => 'orders', 'connectionArgs' => self::get_connection_args( 'private' ), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $post_object ) { // Check if user shop manager. $not_manager = ! current_user_can( $post_object->cap->edit_posts ); diff --git a/includes/connection/class-payment-gateways.php b/includes/connection/class-payment-gateways.php index 6118f74a7..6dcd3766c 100644 --- a/includes/connection/class-payment-gateways.php +++ b/includes/connection/class-payment-gateways.php @@ -17,7 +17,6 @@ * Class - PaymentGateways */ class Payment_Gateways { - /** * Registers the various connections from other Types to Customer. * diff --git a/includes/connection/class-posts.php b/includes/connection/class-posts.php index d0e94d94d..6a530bec6 100644 --- a/includes/connection/class-posts.php +++ b/includes/connection/class-posts.php @@ -18,7 +18,6 @@ * Class - Posts */ class Posts extends PostObjects { - /** * Registers the various connections from other WooCommerce Types to other WordPress post-types. */ diff --git a/includes/connection/class-product-attributes.php b/includes/connection/class-product-attributes.php index c0c13bdcb..0061a62b5 100644 --- a/includes/connection/class-product-attributes.php +++ b/includes/connection/class-product-attributes.php @@ -18,7 +18,6 @@ * Class Product_Attributes */ class Product_Attributes { - /** * Registers the various connections from other Types to ProductAttribute. * diff --git a/includes/connection/class-products.php b/includes/connection/class-products.php index e52d1d5fd..e1479d43a 100644 --- a/includes/connection/class-products.php +++ b/includes/connection/class-products.php @@ -18,7 +18,6 @@ * Class - Products */ class Products { - /** * Registers the various connections from other Types to Product * @@ -33,10 +32,10 @@ public static function register_connections() { self::get_connection_config( [ 'fromType' => 'Coupon', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post__in', $source->product_ids ); @@ -55,10 +54,10 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProducts', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post__in', $source->excluded_product_ids ); @@ -88,16 +87,16 @@ public static function register_connections() { ], ] ), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); // Bypass randomization by default for pagination support. if ( empty( $args['where']['shuffle'] ) ) { add_filter( 'woocommerce_product_related_posts_shuffle', - static function() { + static function () { return false; } ); @@ -121,10 +120,10 @@ static function() { [ 'fromType' => 'Product', 'fromFieldName' => 'upsell', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post__in', $source->upsell_ids ); @@ -144,10 +143,10 @@ static function() { self::get_connection_config( [ 'fromType' => 'GroupProduct', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post__in', $source->grouped_ids ); @@ -165,10 +164,10 @@ static function() { // Product cross-sell connections. $cross_sell_config = [ 'fromFieldName' => 'crossSell', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post__in', $source->cross_sell_ids ); @@ -198,10 +197,10 @@ static function() { 'fromType' => 'VariableProduct', 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'post_parent', $source->ID ); $resolver->set_query_arg( 'post_type', 'product_variation' ); @@ -228,14 +227,14 @@ static function() { 'description' => __( 'The parent of the node. The parent object can be of various types', 'wp-graphql-woocommerce' ), 'oneToOne' => true, 'queryClass' => '\WC_Product_Query', - 'resolve' => static function( $source, $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, $args, AppContext $context, ResolveInfo $info ) { if ( empty( $source->parent_id ) ) { return null; } - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver->set_query_arg( 'p', $source->parent_id ); @@ -255,11 +254,11 @@ static function() { 'fromType' => ucfirst( graphql_format_field_name( $attribute ) ), 'toType' => 'ProductVariation', 'fromFieldName' => 'variations', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { global $wpdb; - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product_variation' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $attribute_meta_key = 'attribute_' . strtolower( preg_replace( '/([A-Z])/', '_$1', $source->taxonomyName ) ); @@ -325,10 +324,10 @@ public static function set_connection_config( $config ) { $taxonomies = self::get_product_connected_taxonomies(); if ( 'Product' === $to_type && in_array( $from_type, $taxonomies, true ) ) { - $config['resolve'] = static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + $config['resolve'] = static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $tax_query = [ [ 'taxonomy' => $source->taxonomyName, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase @@ -362,10 +361,10 @@ public static function get_connection_config( $args = [] ): array { 'fromFieldName' => 'products', 'queryClass' => '\WC_Product_Query', 'connectionArgs' => self::get_connection_args(), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { - add_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10, 3 ); + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { + add_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10, 3 ); $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'product' ); - remove_filter( 'graphql_post_object_connection_args', [ __CLASS__, 'bypass_get_args_sanitization' ], 10 ); + remove_filter( 'graphql_post_object_connection_args', [ self::class, 'bypass_get_args_sanitization' ], 10 ); $resolver = self::set_ordering_query_args( $resolver, $args ); @@ -903,5 +902,4 @@ public static function map_input_fields_to_wp_query( $query_args, $args, $source return $query_args; } - } diff --git a/includes/connection/class-shipping-methods.php b/includes/connection/class-shipping-methods.php index edd36b594..732dc528c 100644 --- a/includes/connection/class-shipping-methods.php +++ b/includes/connection/class-shipping-methods.php @@ -18,7 +18,6 @@ * Class - Shipping_Methods */ class Shipping_Methods { - /** * Registers the various connections from other Types to TaxRate * @@ -43,7 +42,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'ShippingMethod', 'fromFieldName' => 'shippingMethods', 'connectionArgs' => [], - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Shipping_Method_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); diff --git a/includes/connection/class-tax-rates.php b/includes/connection/class-tax-rates.php index 64b1633b4..be9f22535 100644 --- a/includes/connection/class-tax-rates.php +++ b/includes/connection/class-tax-rates.php @@ -18,7 +18,6 @@ * Class - Tax_Rates */ class Tax_Rates { - /** * Registers the various connections from other Types to TaxRate * @@ -43,7 +42,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'TaxRate', 'fromFieldName' => 'taxRates', 'connectionArgs' => self::get_connection_args(), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Tax_Rate_Connection_Resolver( $source, $args, $context, $info ); return $resolver->get_connection(); diff --git a/includes/connection/class-variation-attributes.php b/includes/connection/class-variation-attributes.php index db169af1e..f30f69dad 100644 --- a/includes/connection/class-variation-attributes.php +++ b/includes/connection/class-variation-attributes.php @@ -19,7 +19,6 @@ * Class Product_Attributes */ class Variation_Attributes { - /** * Registers the various connections from other Types to VariationAttribute * @@ -57,7 +56,7 @@ public static function get_connection_config( $args = [] ): array { 'toType' => 'VariationAttribute', 'fromFieldName' => 'attributes', 'connectionArgs' => [], - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { $resolver = new Variation_Attribute_Connection_Resolver(); return $resolver->resolve( $source, $args, $context, $info ); diff --git a/includes/connection/class-wc-terms.php b/includes/connection/class-wc-terms.php index a8ca83d3b..dbc1a078a 100644 --- a/includes/connection/class-wc-terms.php +++ b/includes/connection/class-wc-terms.php @@ -22,7 +22,6 @@ * Class - WC_Terms */ class WC_Terms extends TermObjects { - /** * Registers the various connections from other Types to WooCommerce taxonomies. * @@ -60,7 +59,7 @@ public static function register_connections() { 'fromType' => $post_type_object->graphql_single_name, 'toType' => $tax_object->graphql_single_name, 'fromFieldName' => $tax_object->graphql_plural_name, - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $term_ids = \wc_get_object_terms( $source->ID, $tax_object->name, 'term_id' ); @@ -88,7 +87,7 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'productCategories', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $resolver->set_query_arg( 'term_taxonomy_id', $source->product_category_ids ); @@ -103,7 +102,7 @@ public static function register_connections() { [ 'fromType' => 'Coupon', 'fromFieldName' => 'excludedProductCategories', - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) use ( $tax_object ) { $resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name ); $resolver->set_query_arg( 'term_taxonomy_id', $source->excluded_product_category_ids ); @@ -120,7 +119,7 @@ public static function register_connections() { 'queryClass' => 'WP_Term_Query', 'fromFieldName' => 'terms', 'connectionArgs' => self::get_connection_args(), - 'resolve' => static function( $source, array $args, AppContext $context, ResolveInfo $info ) { + 'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) { if ( ! $source->is_taxonomy() ) { throw new UserError( __( 'Invalid product attribute', 'wp-graphql-woocommerce' ) ); } diff --git a/includes/data/class-db-hooks.php b/includes/data/class-db-hooks.php index a20e7b42c..b81b4fea7 100644 --- a/includes/data/class-db-hooks.php +++ b/includes/data/class-db-hooks.php @@ -14,7 +14,6 @@ * Class DB_Hooks */ class DB_Hooks { - /** * DB_Hooks constructor. */ diff --git a/includes/data/connection/class-cart-item-connection-resolver.php b/includes/data/connection/class-cart-item-connection-resolver.php index 88c127e81..56fe1f2b3 100644 --- a/includes/data/connection/class-cart-item-connection-resolver.php +++ b/includes/data/connection/class-cart-item-connection-resolver.php @@ -20,7 +20,6 @@ * @package WPGraphQL\WooCommerce\Data\Connection */ class Cart_Item_Connection_Resolver extends AbstractConnectionResolver { - /** * Return the name of the loader to be used with the connection resolver * @@ -50,7 +49,7 @@ public function get_query_args() { $where_args = $this->args['where']; if ( isset( $where_args['needsShipping'] ) ) { $needs_shipping = $where_args['needsShipping']; - $query_args['filters'][] = static function( $cart_item ) use ( $needs_shipping ) { + $query_args['filters'][] = static function ( $cart_item ) use ( $needs_shipping ) { $product = \WC()->product_factory->get_product( $cart_item['product_id'] ); if ( ! is_object( $product ) ) { diff --git a/includes/data/connection/class-coupon-connection-resolver.php b/includes/data/connection/class-coupon-connection-resolver.php index ce07e42a1..083230b16 100644 --- a/includes/data/connection/class-coupon-connection-resolver.php +++ b/includes/data/connection/class-coupon-connection-resolver.php @@ -48,6 +48,7 @@ public function __construct( $source, $args, $context, $info ) { * Set the post type for the resolver */ $this->post_type = 'shop_coupon'; + /** * Call the parent construct to setup class data */ diff --git a/includes/data/connection/class-downloadable-item-connection-resolver.php b/includes/data/connection/class-downloadable-item-connection-resolver.php index c91646d8a..5fb546d19 100644 --- a/includes/data/connection/class-downloadable-item-connection-resolver.php +++ b/includes/data/connection/class-downloadable-item-connection-resolver.php @@ -21,7 +21,6 @@ * @package WPGraphQL\WooCommerce\Data\Connection */ class Downloadable_Item_Connection_Resolver extends AbstractConnectionResolver { - /** * Return the name of the loader to be used with the connection resolver * @@ -52,7 +51,7 @@ public function get_query_args() { if ( isset( $where_args['active'] ) ) { $active = $where_args['active']; - $query_args['filters'][] = static function( $downloadable_item ) use ( $active ) { + $query_args['filters'][] = static function ( $downloadable_item ) use ( $active ) { $is_expired = isset( $downloadable_item['access_expires'] ) ? time() > $downloadable_item['access_expires']->getTimestamp() : false; @@ -67,7 +66,7 @@ public function get_query_args() { if ( isset( $where_args['expired'] ) ) { $expired = $where_args['expired']; - $query_args['filters'][] = static function( $downloadable_item ) use ( $expired ) { + $query_args['filters'][] = static function ( $downloadable_item ) use ( $expired ) { $is_expired = isset( $downloadable_item['access_expires'] ) ? time() < $downloadable_item['access_expires']->getTimestamp() : false; @@ -79,7 +78,7 @@ public function get_query_args() { if ( isset( $where_args['hasDownloadsRemaining'] ) ) { $has_downloads_remaining = $where_args['hasDownloadsRemaining']; - $query_args['filters'][] = static function( $downloadable_item ) use ( $has_downloads_remaining ) { + $query_args['filters'][] = static function ( $downloadable_item ) use ( $has_downloads_remaining ) { $downloads_remaining = ( 'integer' === gettype( $downloadable_item['downloads_remaining'] ) ) ? 0 < $downloadable_item['downloads_remaining'] : true; diff --git a/includes/data/connection/class-order-item-connection-resolver.php b/includes/data/connection/class-order-item-connection-resolver.php index 711378282..b4937fb12 100644 --- a/includes/data/connection/class-order-item-connection-resolver.php +++ b/includes/data/connection/class-order-item-connection-resolver.php @@ -16,7 +16,6 @@ * Class Order_Item_Connection_Resolver */ class Order_Item_Connection_Resolver extends AbstractConnectionResolver { - /** * Return the name of the loader to be used with the connection resolver * @@ -122,7 +121,7 @@ public function get_query() { $items = array_reverse( $items ); } - $get_item_id = static function( $item ) { + $get_item_id = static function ( $item ) { return $item->get_id(); }; diff --git a/includes/data/connection/class-product-attribute-connection-resolver.php b/includes/data/connection/class-product-attribute-connection-resolver.php index 9a8f2dba9..5b3af9b83 100644 --- a/includes/data/connection/class-product-attribute-connection-resolver.php +++ b/includes/data/connection/class-product-attribute-connection-resolver.php @@ -55,7 +55,7 @@ private function get_items( $attributes, $source, $args, $context, $info, $type case 'local': $items = array_filter( $items, - static function( $item ) { + static function ( $item ) { return ! $item->is_taxonomy(); } ); @@ -63,7 +63,7 @@ static function( $item ) { case 'global': $items = array_filter( $items, - static function( $item ) { + static function ( $item ) { return $item->is_taxonomy(); } ); diff --git a/includes/data/connection/class-shipping-method-connection-resolver.php b/includes/data/connection/class-shipping-method-connection-resolver.php index d7bb22299..a0b2881eb 100644 --- a/includes/data/connection/class-shipping-method-connection-resolver.php +++ b/includes/data/connection/class-shipping-method-connection-resolver.php @@ -16,7 +16,6 @@ * Class Shipping_Method_Connection_Resolver */ class Shipping_Method_Connection_Resolver extends AbstractConnectionResolver { - /** * Return the name of the loader to be used with the connection resolver * @@ -57,7 +56,7 @@ public function get_query() { // Get shipping method IDs. $methods = array_map( - static function( $item ) { + static function ( $item ) { return $item->id; }, array_values( $methods ) @@ -116,5 +115,4 @@ public function get_offset() { */ return $offset; } - } diff --git a/includes/data/connection/class-tax-rate-connection-resolver.php b/includes/data/connection/class-tax-rate-connection-resolver.php index a5a34eb9a..789688b01 100644 --- a/includes/data/connection/class-tax-rate-connection-resolver.php +++ b/includes/data/connection/class-tax-rate-connection-resolver.php @@ -136,7 +136,7 @@ public function get_query() { }//end if $results = array_map( - static function( $rate ) { + static function ( $rate ) { return $rate->tax_rate_id; }, (array) $results diff --git a/includes/data/connection/class-variation-attribute-connection-resolver.php b/includes/data/connection/class-variation-attribute-connection-resolver.php index 1421990a2..b6c8284a9 100644 --- a/includes/data/connection/class-variation-attribute-connection-resolver.php +++ b/includes/data/connection/class-variation-attribute-connection-resolver.php @@ -21,7 +21,6 @@ * @package WPGraphQL\WooCommerce\Data\Connection */ class Variation_Attribute_Connection_Resolver { - /** * Returns data array from WC_Product_Attribute ArrayAccess object. * diff --git a/includes/data/cursor/class-cot-cursor.php b/includes/data/cursor/class-cot-cursor.php index 0d871b945..18f0c8da5 100644 --- a/includes/data/cursor/class-cot-cursor.php +++ b/includes/data/cursor/class-cot-cursor.php @@ -69,7 +69,6 @@ class COT_Cursor extends AbstractCursor { * @param string|null $cursor Whether to generate the before or after cursor. Default "after". */ public function __construct( $query_vars, $query, $cursor = 'after' ) { - // Initialize the class properties. parent::__construct( $query_vars, $cursor ); diff --git a/includes/data/loader/class-wc-cpt-loader.php b/includes/data/loader/class-wc-cpt-loader.php index 354f76b79..bf681d85b 100644 --- a/includes/data/loader/class-wc-cpt-loader.php +++ b/includes/data/loader/class-wc-cpt-loader.php @@ -178,7 +178,7 @@ static function ( $split, \WP_Query $query ) { * instead of loading once per entity, thus reducing the n+1 problem. */ $load_dependencies = new Deferred( - function() use ( $key, $post_type, $customer_id, $parent_id, $context ) { + function () use ( $key, $post_type, $customer_id, $parent_id, $context ) { if ( ! empty( $customer_id ) ) { $context->get_loader( 'wc_customer' )->load( $customer_id ); } @@ -200,7 +200,7 @@ function() use ( $key, $post_type, $customer_id, $parent_id, $context ) { * Once dependencies are loaded, return the Post Object */ $loaded_posts[ $key ] = $load_dependencies->then( - static function() use ( $post_type, $key ) { + static function () use ( $post_type, $key ) { return self::resolve_model( $post_type, $key ); } ); diff --git a/includes/data/loader/class-wc-db-loader.php b/includes/data/loader/class-wc-db-loader.php index cce75849e..bcdd55f89 100644 --- a/includes/data/loader/class-wc-db-loader.php +++ b/includes/data/loader/class-wc-db-loader.php @@ -42,6 +42,7 @@ class WC_Db_Loader extends AbstractDataLoader { */ public function __construct( $context, $loader_type ) { $this->loader_type = $loader_type; + parent::__construct( $context ); } diff --git a/includes/data/mutation/class-cart-mutation.php b/includes/data/mutation/class-cart-mutation.php index 2d9354f3c..11d92aa2d 100644 --- a/includes/data/mutation/class-cart-mutation.php +++ b/includes/data/mutation/class-cart-mutation.php @@ -172,7 +172,6 @@ public static function prepare_cart_fee( $input, $context, $info ) { return apply_filters( 'graphql_woocommerce_new_cart_fee_data', $cart_item_args, $input, $context, $info ); } - /** * Validates coupon and checks if application is possible * diff --git a/includes/data/mutation/class-checkout-mutation.php b/includes/data/mutation/class-checkout-mutation.php index d83db3120..5a7ae58ac 100644 --- a/includes/data/mutation/class-checkout-mutation.php +++ b/includes/data/mutation/class-checkout-mutation.php @@ -17,7 +17,6 @@ * Class - Checkout_Mutation */ class Checkout_Mutation { - /** * Caches customer object. @see get_value. * diff --git a/includes/data/mutation/class-coupon-mutation.php b/includes/data/mutation/class-coupon-mutation.php index 6adb03111..6175e2a46 100644 --- a/includes/data/mutation/class-coupon-mutation.php +++ b/includes/data/mutation/class-coupon-mutation.php @@ -12,7 +12,6 @@ * Class - Coupon_Mutation */ class Coupon_Mutation { - /** * Prepares coupon args from input. * diff --git a/includes/functions.php b/includes/functions.php index 97b7fbee7..7cc4e9971 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -37,7 +37,7 @@ function woographql_swp_result_possible_types( array $type_names ) { $type_names = array_merge( array_filter( $type_names, - static function( $type_name ) { + static function ( $type_name ) { return 'Product' !== $type_name; } ), diff --git a/includes/model/class-coupon.php b/includes/model/class-coupon.php index defaa240b..e5cc56707 100644 --- a/includes/model/class-coupon.php +++ b/includes/model/class-coupon.php @@ -46,7 +46,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Coupon extends WC_Post { - /** * Coupon constructor * @@ -66,61 +65,61 @@ protected function init() { parent::init(); $fields = [ - 'ID' => function() { + 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->ID ) ? Relay::toGlobalId( 'shop_coupon', "{$this->ID}" ) : null; }, - 'code' => function() { + 'code' => function () { return ! empty( $this->wc_data->get_code() ) ? $this->wc_data->get_code() : null; }, - 'date' => function() { + 'date' => function () { return ! empty( $this->wc_data->get_date_created() ) ? $this->wc_data->get_date_created() : null; }, - 'modified' => function() { + 'modified' => function () { return ! empty( $this->wc_data->get_date_modified() ) ? $this->wc_data->get_date_modified() : null; }, - 'description' => function() { + 'description' => function () { return ! empty( $this->wc_data->get_description() ) ? $this->wc_data->get_description() : null; }, - 'discountType' => function() { + 'discountType' => function () { return ! empty( $this->wc_data->get_discount_type() ) ? $this->wc_data->get_discount_type() : null; }, - 'amount' => function() { + 'amount' => function () { return ! empty( $this->wc_data->get_amount() ) ? $this->wc_data->get_amount() : null; }, - 'dateExpiry' => function() { + 'dateExpiry' => function () { return ! empty( $this->wc_data->get_date_expires() ) ? $this->wc_data->get_date_expires() : null; }, - 'usageCount' => function() { + 'usageCount' => function () { return $this->wc_data->get_usage_count(); }, - 'individualUse' => function() { + 'individualUse' => function () { return $this->wc_data->get_individual_use(); }, - 'usageLimit' => function() { + 'usageLimit' => function () { return ! empty( $this->wc_data->get_usage_limit() ) ? $this->wc_data->get_usage_limit() : null; }, - 'usageLimitPerUser' => function() { + 'usageLimitPerUser' => function () { return ! empty( $this->wc_data->get_usage_limit_per_user() ) ? $this->wc_data->get_usage_limit_per_user() : null; }, - 'limitUsageToXItems' => function() { + 'limitUsageToXItems' => function () { return ! empty( $this->wc_data->get_limit_usage_to_x_items() ) ? $this->wc_data->get_limit_usage_to_x_items() : null; }, - 'freeShipping' => function() { + 'freeShipping' => function () { return $this->wc_data->get_free_shipping(); }, - 'excludeSaleItems' => function() { + 'excludeSaleItems' => function () { return $this->wc_data->get_exclude_sale_items(); }, - 'minimumAmount' => function() { + 'minimumAmount' => function () { return ! empty( $this->wc_data->get_minimum_amount() ) ? $this->wc_data->get_minimum_amount() : null; }, - 'maximumAmount' => function() { + 'maximumAmount' => function () { return ! empty( $this->wc_data->get_maximum_amount() ) ? $this->wc_data->get_maximum_amount() : null; }, - 'emailRestrictions' => function() { + 'emailRestrictions' => function () { return ! empty( $this->wc_data->get_email_restrictions() ) ? $this->wc_data->get_email_restrictions() : null; }, /** @@ -129,19 +128,19 @@ protected function init() { * These field resolvers are used in connection resolvers to define WP_Query argument * Note: underscore naming style is used as a quick identifier */ - 'product_ids' => function() { + 'product_ids' => function () { return ! empty( $this->wc_data->get_product_ids() ) ? $this->wc_data->get_product_ids() : [ '0' ]; }, - 'excluded_product_ids' => function() { + 'excluded_product_ids' => function () { return ! empty( $this->wc_data->get_excluded_product_ids() ) ? $this->wc_data->get_excluded_product_ids() : [ '0' ]; }, - 'product_category_ids' => function() { + 'product_category_ids' => function () { return ! empty( $this->wc_data->get_product_categories() ) ? $this->wc_data->get_product_categories() : [ '0' ]; }, - 'excluded_product_category_ids' => function() { + 'excluded_product_category_ids' => function () { return ! empty( $this->wc_data->get_excluded_product_categories() ) ? $this->wc_data->get_excluded_product_categories() : [ '0' ]; }, - 'used_by_ids' => function() { + 'used_by_ids' => function () { return ! empty( $this->wc_data->get_used_by() ) ? $this->wc_data->get_used_by() : [ '0' ]; }, ]; diff --git a/includes/model/class-customer.php b/includes/model/class-customer.php index a6bd349c3..2a6c019be 100644 --- a/includes/model/class-customer.php +++ b/includes/model/class-customer.php @@ -43,7 +43,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Customer extends Model { - /** * Customer constructor * @@ -61,6 +60,7 @@ public function __construct( $id = 'session' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound $restricted_cap = apply_filters( 'customer_restricted_cap', 'session' === $id ? '' : 'list_users' ); + parent::__construct( $restricted_cap, $allowed_restricted_fields, $this->data->get_id() ); } @@ -81,63 +81,63 @@ public function __call( $method, $args ) { protected function init() { if ( empty( $this->fields ) ) { $this->fields = [ - 'ID' => function() { + 'ID' => function () { return ( ! empty( $this->data->get_id() ) ) ? $this->data->get_id() : \WC()->session->get_customer_id(); }, - 'id' => function() { + 'id' => function () { return ( ! empty( $this->data->get_id() ) ) ? Relay::toGlobalId( 'customer', $this->data->get_id() ) : 'guest'; }, - 'databaseId' => function() { + 'databaseId' => function () { return ! empty( $this->ID ) ? $this->ID : null; }, - 'isVatExempt' => function() { + 'isVatExempt' => function () { return ! is_null( $this->data->get_is_vat_exempt() ) ? $this->data->get_is_vat_exempt() : null; }, - 'hasCalculatedShipping' => function() { + 'hasCalculatedShipping' => function () { return ! is_null( $this->data->has_calculated_shipping() ) ? $this->data->has_calculated_shipping() : null; }, - 'calculatedShipping' => function() { + 'calculatedShipping' => function () { return ! is_null( $this->data->get_calculated_shipping() ) ? $this->data->get_calculated_shipping() : null; }, - 'orderCount' => function() { + 'orderCount' => function () { return ! is_null( $this->data->get_order_count() ) ? $this->data->get_order_count() : null; }, - 'totalSpent' => function() { + 'totalSpent' => function () { return ! is_null( $this->data->get_total_spent() ) ? $this->data->get_total_spent() : null; }, - 'username' => function() { + 'username' => function () { return ( ! empty( $this->data->get_username() ) ) ? $this->data->get_username() : null; }, - 'email' => function() { + 'email' => function () { return ( ! empty( $this->data->get_email() ) ) ? $this->data->get_email() : null; }, - 'firstName' => function() { + 'firstName' => function () { return ( ! empty( $this->data->get_first_name() ) ) ? $this->data->get_first_name() : null; }, - 'lastName' => function() { + 'lastName' => function () { return ( ! empty( $this->data->get_last_name() ) ) ? $this->data->get_last_name() : null; }, - 'displayName' => function() { + 'displayName' => function () { return ( ! empty( $this->data->get_display_name() ) ) ? $this->data->get_display_name() : null; }, - 'role' => function() { + 'role' => function () { return ( ! empty( $this->data->get_role() ) ) ? $this->data->get_role() : null; }, - 'date' => function() { + 'date' => function () { return ( ! empty( $this->data->get_date_created() ) ) ? $this->data->get_date_created() : null; }, - 'modified' => function() { + 'modified' => function () { return ( ! empty( $this->data->get_date_modified() ) ) ? $this->data->get_date_modified() : null; }, - 'billing' => function() { + 'billing' => function () { return ( ! empty( $this->data->get_billing() ) ) ? $this->data->get_billing() : null; }, - 'shipping' => function() { + 'shipping' => function () { return ( ! empty( $this->data->get_shipping() ) ) ? $this->data->get_shipping() : null; }, - 'isPayingCustomer' => function() { + 'isPayingCustomer' => function () { return ( ! is_null( $this->data->get_is_paying_customer() ) ) ? $this->data->get_is_paying_customer() : null; }, /** @@ -146,7 +146,7 @@ protected function init() { * These field resolvers are used in connection resolvers to define WP_Query argument * Note: underscore naming style is used as a quick identifier */ - 'last_order_id' => function() { + 'last_order_id' => function () { return ( ! empty( $this->data->get_last_order() ) ) ? $this->data->get_last_order()->get_id() : null; }, ]; diff --git a/includes/model/class-order-item.php b/includes/model/class-order-item.php index 7326cc8fe..a46c306dc 100644 --- a/includes/model/class-order-item.php +++ b/includes/model/class-order-item.php @@ -65,7 +65,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Order_Item extends Model { - /** * Stores order item type. * @@ -122,22 +121,22 @@ public function __call( $method, $args ) { protected function init() { if ( empty( $this->fields ) ) { $this->fields = [ - 'ID' => function() { + 'ID' => function () { return $this->data->get_id(); }, - 'databaseId' => function() { + 'databaseId' => function () { return ! empty( $this->ID ) ? $this->ID : null; }, - 'orderId' => function() { + 'orderId' => function () { return ! empty( $this->data->get_order_id() ) ? $this->data->get_order_id() : null; }, - 'id' => function() { + 'id' => function () { return ( ! empty( $this->orderId ) && ! empty( $this->ID ) ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase ? Relay::toGlobalId( 'order_item', $this->orderId . '+' . $this->ID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase : null; }, - 'type' => function() { + 'type' => function () { return ! empty( $this->data->get_type() ) ? $this->data->get_type() : null; }, ]; @@ -147,17 +146,17 @@ protected function init() { $this->fields = array_merge( $this->fields, [ - 'code' => function() { + 'code' => function () { return ! empty( $this->data->get_code() ) ? $this->data->get_code() : null; }, - 'discount' => function() { + 'discount' => function () { return ! empty( $this->data->get_discount() ) ? $this->data->get_discount() : null; }, - 'discountTax' => function() { + 'discountTax' => function () { return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : null; }, 'coupon_id' => [ - 'callback' => function() { + 'callback' => function () { $coupon_id = \wc_get_coupon_id_by_code( $this->data->get_code() ); return ! empty( $coupon_id ) ? $coupon_id : null; }, @@ -171,16 +170,16 @@ protected function init() { $this->fields = array_merge( $this->fields, [ - 'amount' => function() { + 'amount' => function () { return ! empty( $this->data->get_amount() ) ? $this->data->get_amount() : null; }, - 'name' => function() { + 'name' => function () { return ! empty( $this->data->get_name() ) ? $this->data->get_name() : null; }, - 'taxStatus' => function() { + 'taxStatus' => function () { return ! empty( $this->data->get_tax_status() ) ? $this->data->get_tax_status() : null; }, - 'taxClass' => function() { + 'taxClass' => function () { if ( $this->data->get_tax_status() === 'taxable' ) { return ! empty( $this->data->get_tax_class() ) ? $this->data->get_tax_class() @@ -188,13 +187,13 @@ protected function init() { } return null; }, - 'total' => function() { + 'total' => function () { return ! empty( $this->data->get_total() ) ? $this->data->get_total() : null; }, - 'totalTax' => function() { + 'totalTax' => function () { return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : null; }, - 'taxes' => function() { + 'taxes' => function () { return ! empty( $this->data->get_taxes() ) ? \wc_graphql_map_tax_statements( $this->data->get_taxes() ) : null; @@ -207,27 +206,27 @@ protected function init() { $this->fields = array_merge( $this->fields, [ - 'name' => function() { + 'name' => function () { return ! empty( $this->data->get_name() ) ? $this->data->get_name() : null; }, - 'methodTitle' => function() { + 'methodTitle' => function () { return ! empty( $this->data->get_method_title() ) ? $this->data->get_method_title() : null; }, - 'total' => function() { + 'total' => function () { return ! empty( $this->data->get_total() ) ? $this->data->get_total() : null; }, - 'totalTax' => function() { + 'totalTax' => function () { return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : null; }, - 'taxes' => function() { + 'taxes' => function () { return ! empty( $this->data->get_taxes() ) ? \wc_graphql_map_tax_statements( $this->data->get_taxes() ) : null; }, - 'taxClass' => function() { + 'taxClass' => function () { return ! empty( $this->data->get_tax_class() ) ? $this->data->get_tax_class() : 'standard'; }, - 'method_id' => function() { + 'method_id' => function () { return ! empty( $this->data->get_method_id() ) ? $this->data->get_method_id() : null; }, ] @@ -238,22 +237,22 @@ protected function init() { $this->fields = array_merge( $this->fields, [ - 'rateCode' => function() { + 'rateCode' => function () { return ! empty( $this->data->get_rate_code() ) ? $this->data->get_rate_code() : null; }, - 'label' => function() { + 'label' => function () { return ! empty( $this->data->get_label() ) ? $this->data->get_label() : null; }, - 'taxTotal' => function() { + 'taxTotal' => function () { return ! empty( $this->data->get_tax_total() ) ? $this->data->get_tax_total() : null; }, - 'shippingTaxTotal' => function() { + 'shippingTaxTotal' => function () { return ! is_null( $this->data->get_shipping_tax_total() ) ? $this->data->get_shipping_tax_total() : 0; }, - 'isCompound' => function() { + 'isCompound' => function () { return ! is_null( $this->data->is_compound() ) ? $this->data->is_compound() : false; }, - 'rate_id' => function() { + 'rate_id' => function () { return ! empty( $this->data->get_rate_id() ) ? $this->data->get_rate_id() : null; }, ] @@ -263,39 +262,39 @@ protected function init() { $this->fields = array_merge( $this->fields, [ - 'productId' => function() { + 'productId' => function () { return ! empty( $this->data->get_product_id() ) ? $this->data->get_product_id() : null; }, - 'variationId' => function() { + 'variationId' => function () { return ! empty( $this->data->get_variation_id() ) ? $this->data->get_variation_id() : null; }, - 'quantity' => function() { + 'quantity' => function () { return ! empty( $this->data->get_quantity() ) ? $this->data->get_quantity() : null; }, - 'subtotal' => function() { + 'subtotal' => function () { return ! empty( $this->data->get_subtotal() ) ? $this->data->get_subtotal() : null; }, - 'subtotalTax' => function() { + 'subtotalTax' => function () { return ! empty( $this->data->get_subtotal_tax() ) ? $this->data->get_subtotal_tax() : null; }, - 'total' => function() { + 'total' => function () { return ! empty( $this->data->get_total() ) ? $this->data->get_total() : null; }, - 'totalTax' => function() { + 'totalTax' => function () { return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : null; }, - 'taxes' => function() { + 'taxes' => function () { return ! empty( $this->data->get_taxes() ) ? \wc_graphql_map_tax_statements( $this->data->get_taxes() ) : null; }, - 'itemDownloads' => function() { + 'itemDownloads' => function () { return ! empty( $this->data->get_item_downloads() ) ? $this->data->get_item_downloads() : null; }, - 'taxStatus' => function() { + 'taxStatus' => function () { return ! empty( $this->data->get_tax_status() ) ? $this->data->get_tax_status() : null; }, - 'taxClass' => function() { + 'taxClass' => function () { if ( $this->data->get_tax_status() === 'taxable' ) { return ! empty( $this->data->get_tax_class() ) ? $this->data->get_tax_class() @@ -312,7 +311,6 @@ protected function init() { parent::prepare_fields(); } - /** * Determines if the order item should be considered private * diff --git a/includes/model/class-order.php b/includes/model/class-order.php index a473cca4f..ae0279b4e 100644 --- a/includes/model/class-order.php +++ b/includes/model/class-order.php @@ -79,7 +79,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Order extends Model { - /** * Stores the incoming order data * @@ -198,7 +197,7 @@ public function __call( $method, $args ) { return $this->data->$method( ...$args ); } - $class = __CLASS__; + $class = self::class; throw new \BadMethodCallException( "Call to undefined method {$method} on the {$class}" ); } @@ -264,7 +263,6 @@ public function get_parent_id() { return absint( $this->data->get_parent_id() ); } - /** * Whether or not the customer of the order matches the current user. * @@ -367,85 +365,85 @@ public function delete( $force_delete = false ) { */ protected function abstract_order_fields() { return [ - 'ID' => function() { + 'ID' => function () { return ! empty( $this->data->get_id() ) ? $this->data->get_id() : null; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->ID ) ? Relay::toGlobalId( 'order', "{$this->ID}" ) : null; }, - 'databaseId' => function() { + 'databaseId' => function () { return $this->ID; }, - 'parent_id' => function() { + 'parent_id' => function () { return ! empty( $this->data->get_parent_id() ) ? $this->data->get_parent_id() : null; }, - 'status' => function() { + 'status' => function () { return ! empty( $this->data->get_status() ) ? $this->data->get_status() : null; }, - 'currency' => function() { + 'currency' => function () { return ! empty( $this->data->get_currency() ) ? $this->data->get_currency() : null; }, - 'version' => function() { + 'version' => function () { return ! empty( $this->data->get_version() ) ? $this->data->get_version() : null; }, - 'pricesIncludeTax' => function() { + 'pricesIncludeTax' => function () { return ! empty( $this->data->get_prices_include_tax() ) ? $this->data->get_prices_include_tax() : null; }, - 'dateCreated' => function() { + 'dateCreated' => function () { return ! empty( $this->data->get_date_created() ) ? $this->data->get_date_created() : null; }, - 'dateModified' => function() { + 'dateModified' => function () { return ! empty( $this->data->get_date_modified() ) ? $this->data->get_date_modified() : null; }, - 'discountTotal' => function() { + 'discountTotal' => function () { $price = ! is_null( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0; return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); }, - 'discountTotalRaw' => function() { + 'discountTotalRaw' => function () { return ! empty( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0; }, - 'discountTax' => function() { + 'discountTax' => function () { $price = ! is_null( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0; return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); }, - 'discountTaxRaw' => function() { + 'discountTaxRaw' => function () { return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0; }, - 'shippingTotal' => function() { + 'shippingTotal' => function () { $price = ! is_null( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0; return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); }, - 'shippingTotalRaw' => function() { + 'shippingTotalRaw' => function () { return ! empty( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0; }, - 'shippingTax' => function() { + 'shippingTax' => function () { $price = ! is_null( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0; return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); }, - 'shippingTaxRaw' => function() { + 'shippingTaxRaw' => function () { return ! empty( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0; }, - 'cartTax' => function() { + 'cartTax' => function () { $price = ! is_null( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0; return wc_graphql_price( $price, [ 'currency' => $this->data->get_currency() ] ); }, - 'cartTaxRaw' => function() { + 'cartTaxRaw' => function () { return ! empty( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0; }, - 'total' => function() { + 'total' => function () { return ! is_null( $this->data->get_total() ) ? wc_graphql_price( $this->data->get_total(), [ 'currency' => $this->data->get_currency() ] ) : null; }, - 'totalRaw' => function() { + 'totalRaw' => function () { return ! empty( $this->data->get_total() ) ? $this->data->get_total() : 0; }, - 'totalTax' => function() { + 'totalTax' => function () { return ! is_null( $this->data->get_total_tax() ) ? wc_graphql_price( $this->data->get_total_tax(), [ 'currency' => $this->data->get_currency() ] ) : null; }, - 'totalTaxRaw' => function() { + 'totalTaxRaw' => function () { return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : 0; }, ]; @@ -458,127 +456,127 @@ protected function abstract_order_fields() { */ protected function order_fields() { return [ - 'date' => function() { + 'date' => function () { return ! empty( $this->data->get_date_created() ) ? $this->data->get_date_created() : null; }, - 'modified' => function() { + 'modified' => function () { return ! empty( $this->data->get_date_modified() ) ? $this->data->get_date_modified() : null; }, - 'orderKey' => function() { + 'orderKey' => function () { $order_key = method_exists( $this->data, 'get_order_key' ) ? $this->data->get_order_key() : null; return ! empty( $order_key ) ? $order_key : null; }, - 'paymentMethod' => function() { + 'paymentMethod' => function () { $payment_method = method_exists( $this->data, 'get_payment_method' ) ? $this->data->get_payment_method() : null; return ! empty( $payment_method ) ? $payment_method : null; }, - 'paymentMethodTitle' => function() { + 'paymentMethodTitle' => function () { $payment_method_title = method_exists( $this->data, 'get_payment_method_title' ) ? $this->data->get_payment_method_title() : null; return ! empty( $payment_method_title ) ? $payment_method_title : null; }, - 'transactionId' => function() { + 'transactionId' => function () { $transaction_id = method_exists( $this->data, 'get_transaction_id' ) ? $this->data->get_transaction_id() : null; return ! empty( $transaction_id ) ? $transaction_id : null; }, - 'customerIpAddress' => function() { + 'customerIpAddress' => function () { $customer_ip_address = method_exists( $this->data, 'get_customer_ip_address' ) ? $this->data->get_customer_ip_address() : null; return ! empty( $customer_ip_address ) ? $customer_ip_address : null; }, - 'customerUserAgent' => function() { + 'customerUserAgent' => function () { $customer_user_agent = method_exists( $this->data, 'get_customer_user_agent' ) ? $this->data->get_customer_user_agent() : null; return ! empty( $customer_user_agent ) ? $customer_user_agent : null; }, - 'createdVia' => function() { + 'createdVia' => function () { $created_via = method_exists( $this->data, 'get_created_via' ) ? $this->data->get_created_via() : null; return ! empty( $created_via ) ? $created_via : null; }, - 'dateCompleted' => function() { + 'dateCompleted' => function () { return ! empty( $this->data->get_date_completed() ) ? $this->data->get_date_completed() : null; }, - 'datePaid' => function() { + 'datePaid' => function () { return ! empty( $this->data->get_date_paid() ) ? $this->data->get_date_paid() : null; }, - 'subtotal' => function() { + 'subtotal' => function () { return ! empty( $this->data->get_subtotal() ) ? wc_graphql_price( $this->data->get_subtotal(), [ 'currency' => $this->data->get_currency() ] ) : null; }, - 'subtotalRaw' => function() { + 'subtotalRaw' => function () { return ! empty( $this->data->get_subtotal() ) ? $this->data->get_subtotal() : 0; }, - 'orderNumber' => function() { + 'orderNumber' => function () { $order_number = method_exists( $this->data, 'get_order_number' ) ? $this->data->get_order_number() : null; return ! empty( $order_number ) ? $order_number : null; }, - 'orderVersion' => function() { + 'orderVersion' => function () { return ! empty( $this->data->get_version() ) ? $this->data->get_version() : null; }, - 'pricesIncludeTax' => function() { + 'pricesIncludeTax' => function () { return ! is_null( $this->data->get_prices_include_tax() ) ? $this->data->get_prices_include_tax() : null; }, - 'cartHash' => function() { + 'cartHash' => function () { $cart_hash = method_exists( $this->data, 'get_cart_hash' ) ? $this->data->get_cart_hash() : null; return ! empty( $cart_hash ) ? $cart_hash : null; }, - 'customerNote' => function() { + 'customerNote' => function () { $customer_note = method_exists( $this->data, 'get_customer_note' ) ? $this->data->get_customer_note() : null; return ! empty( $customer_note ) ? $customer_note : null; }, - 'isDownloadPermitted' => function() { + 'isDownloadPermitted' => function () { if ( ! method_exists( $this->data, 'is_download_permitted' ) ) { return null; } return $this->data->is_download_permitted(); }, - 'billing' => function() { + 'billing' => function () { $billing = method_exists( $this->data, 'get_address' ) ? $this->data->get_address( 'billing' ) : null; return ! empty( $billing ) ? $billing : null; }, - 'shipping' => function() { + 'shipping' => function () { $shipping = method_exists( $this->data, 'get_address' ) ? $this->data->get_address( 'shipping' ) : null; return ! empty( $shipping ) ? $shipping : null; }, - 'shippingAddressMapUrl' => function() { + 'shippingAddressMapUrl' => function () { $shipping_address_map_url = method_exists( $this->data, 'get_shipping_address_map_url' ) ? $this->data->get_shipping_address_map_url() : null; return ! empty( $shipping_address_map_url ) ? $shipping_address_map_url : null; }, - 'hasBillingAddress' => function() { + 'hasBillingAddress' => function () { if ( ! method_exists( $this->data, 'has_billing_address' ) ) { return null; } return $this->data->has_billing_address(); }, - 'hasShippingAddress' => function() { + 'hasShippingAddress' => function () { if ( ! method_exists( $this->data, 'has_shipping_address' ) ) { return null; } return $this->data->has_shipping_address(); }, - 'needsShippingAddress' => function() { + 'needsShippingAddress' => function () { if ( ! method_exists( $this->data, 'needs_shipping_address' ) ) { return null; } return $this->data->needs_shipping_address(); }, - 'hasDownloadableItem' => function() { + 'hasDownloadableItem' => function () { if ( ! method_exists( $this->data, 'has_downloadable_item' ) ) { return null; } return $this->data->has_downloadable_item(); }, - 'needsPayment' => function() { + 'needsPayment' => function () { if ( ! method_exists( $this->data, 'needs_payment' ) ) { return null; } return $this->data->needs_payment(); }, - 'needsProcessing' => function() { + 'needsProcessing' => function () { if ( ! method_exists( $this->data, 'needs_processing' ) ) { return null; } @@ -591,11 +589,11 @@ protected function order_fields() { * These field resolvers are used in connection resolvers to define WP_Query argument * Note: underscore naming style is used as a quick identifier */ - 'customer_id' => function() { + 'customer_id' => function () { $customer_id = method_exists( $this->data, 'get_customer_id' ) ? $this->data->get_customer_id() : null; return ! empty( $customer_id ) ? $customer_id : null; }, - 'downloadable_items' => function() { + 'downloadable_items' => function () { $downloadable_items = method_exists( $this->data, 'get_downloadable_items' ) ? $this->data->get_downloadable_items() : null; return ! empty( $downloadable_items ) ? $downloadable_items : null; }, @@ -605,7 +603,7 @@ protected function order_fields() { * These fields are used primarily by WPGraphQL core Node* interfaces * and some fields act as aliases/decorator for existing fields. */ - 'commentCount' => function() { + 'commentCount' => function () { remove_filter( 'comments_clauses', [ 'WC_Comments', 'exclude_order_comments' ] ); $args = [ @@ -634,7 +632,7 @@ protected function order_fields() { return is_array( $notes ) ? count( $notes ) : 0; }, - 'commentStatus' => function() { + 'commentStatus' => function () { $is_allowed_to_comment = null !== $this->post_type_object ? current_user_can( $this->post_type_object->cap->edit_posts, $this->ID ) : current_user_can( 'manage_woocommerce' ); @@ -650,26 +648,26 @@ protected function order_fields() { */ protected function refund_fields() { return [ - 'title' => function() { + 'title' => function () { $post_title = method_exists( $this->data, 'get_post_title' ) ? $this->data->get_post_title() : null; return ! empty( $post_title ) ? $post_title : null; }, - 'amount' => function() { + 'amount' => function () { $amount = method_exists( $this->data, 'get_amount' ) ? $this->data->get_amount() : null; return ! empty( $amount ) ? $amount : null; }, - 'reason' => function() { + 'reason' => function () { $reason = method_exists( $this->data, 'get_reason' ) ? $this->data->get_reason() : null; return ! empty( $reason ) ? $reason : null; }, 'refunded_by_id' => [ - 'callback' => function() { + 'callback' => function () { $refunded_by = method_exists( $this->data, 'get_refunded_by' ) ? $this->data->get_refunded_by() : null; return ! empty( $refunded_by ) ? $refunded_by : null; }, 'capability' => 'list_users', ], - 'date' => function() { + 'date' => function () { return ! empty( $this->data->get_date_modified() ) ? $this->data->get_date_modified() : null; }, ]; diff --git a/includes/model/class-product-variation.php b/includes/model/class-product-variation.php index 739695a08..0c3d50f62 100644 --- a/includes/model/class-product-variation.php +++ b/includes/model/class-product-variation.php @@ -65,7 +65,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Product_Variation extends WC_Post { - /** * Product_Variation constructor * @@ -92,128 +91,128 @@ protected function init() { parent::init(); $fields = [ - 'ID' => function() { + 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->ID ) ? Relay::toGlobalId( 'product_variation', "{$this->ID}" ) : null; }, - 'name' => function() { + 'name' => function () { return ! empty( $this->wc_data->get_name() ) ? $this->wc_data->get_name() : null; }, - 'date' => function() { + 'date' => function () { return ! empty( $this->wc_data ) ? $this->wc_data->get_date_created() : null; }, - 'modified' => function() { + 'modified' => function () { return ! empty( $this->wc_data ) ? $this->wc_data->get_date_modified() : null; }, - 'description' => function() { + 'description' => function () { return ! empty( $this->wc_data->get_description() ) ? $this->wc_data->get_description() : null; }, - 'sku' => function() { + 'sku' => function () { return ! empty( $this->wc_data->get_sku() ) ? $this->wc_data->get_sku() : null; }, - 'price' => function() { + 'price' => function () { return ! empty( $this->wc_data->get_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_price() ] ) ) : null; }, - 'regularPrice' => function() { + 'regularPrice' => function () { return ! empty( $this->wc_data->get_regular_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) ) : null; }, - 'salePrice' => function() { + 'salePrice' => function () { return ! empty( $this->wc_data->get_sale_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_sale_price() ] ) ) : null; }, - 'dateOnSaleFrom' => function() { + 'dateOnSaleFrom' => function () { return ! empty( $this->wc_data->get_date_on_sale_from() ) ? $this->wc_data->get_date_on_sale_from() : null; }, - 'dateOnSaleTo' => function() { + 'dateOnSaleTo' => function () { return ! empty( $this->wc_data->get_date_on_sale_to() ) ? $this->wc_data->get_date_on_sale_to() : null; }, 'onSale' => function () { return $this->wc_data->is_on_sale(); }, - 'status' => function() { + 'status' => function () { return ! empty( $this->wc_data->get_status() ) ? $this->wc_data->get_status() : null; }, - 'purchasable' => function() { + 'purchasable' => function () { return ! empty( $this->wc_data->is_purchasable() ) ? $this->wc_data->is_purchasable() : null; }, - 'virtual' => function() { + 'virtual' => function () { return $this->wc_data->is_virtual(); }, - 'downloadable' => function() { + 'downloadable' => function () { return $this->wc_data->is_downloadable(); }, - 'downloads' => function() { + 'downloads' => function () { return ! empty( $this->wc_data->get_downloads() ) ? $this->wc_data->get_downloads() : null; }, - 'downloadLimit' => function() { + 'downloadLimit' => function () { return ! empty( $this->wc_data->get_download_limit() ) ? $this->wc_data->get_download_limit() : null; }, - 'downloadExpiry' => function() { + 'downloadExpiry' => function () { return ! empty( $this->wc_data->get_download_expiry() ) ? $this->wc_data->get_download_expiry() : null; }, - 'taxStatus' => function() { + 'taxStatus' => function () { return ! empty( $this->wc_data->get_tax_status() ) ? $this->wc_data->get_tax_status() : null; }, - 'taxClass' => function() { + 'taxClass' => function () { return $this->wc_data->get_tax_class(); }, - 'manageStock' => function() { + 'manageStock' => function () { return ! empty( $this->wc_data->get_manage_stock() ) ? $this->wc_data->get_manage_stock() : null; }, - 'stockQuantity' => function() { + 'stockQuantity' => function () { return ! empty( $this->wc_data->get_stock_quantity() ) ? $this->wc_data->get_stock_quantity() : null; }, - 'stockStatus' => function() { + 'stockStatus' => function () { return ! empty( $this->wc_data->get_stock_status() ) ? $this->wc_data->get_stock_status() : null; }, - 'backorders' => function() { + 'backorders' => function () { return ! empty( $this->wc_data->get_backorders() ) ? $this->wc_data->get_backorders() : null; }, - 'backordersAllowed' => function() { + 'backordersAllowed' => function () { return $this->wc_data->backorders_allowed(); }, - 'weight' => function() { + 'weight' => function () { return ! empty( $this->wc_data->get_weight() ) ? $this->wc_data->get_weight() : null; }, - 'length' => function() { + 'length' => function () { return ! empty( $this->wc_data->get_length() ) ? $this->wc_data->get_length() : null; }, - 'width' => function() { + 'width' => function () { return ! empty( $this->wc_data->get_width() ) ? $this->wc_data->get_width() : null; }, - 'height' => function() { + 'height' => function () { return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null; }, - 'menuOrder' => function() { + 'menuOrder' => function () { return ! empty( $this->wc_data->get_menu_order() ) ? $this->wc_data->get_menu_order() : null; }, - 'purchaseNote' => function() { + 'purchaseNote' => function () { return ! empty( $this->wc_data->get_purchase_note() ) ? $this->wc_data->get_purchase_note() : null; }, - 'catalogVisibility' => function() { + 'catalogVisibility' => function () { return ! empty( $this->wc_data->get_catalog_visibility() ) ? $this->wc_data->get_catalog_visibility() : null; }, - 'hasAttributes' => function() { + 'hasAttributes' => function () { return ! empty( $this->wc_data->has_attributes() ) ? $this->wc_data->has_attributes() : null; }, - 'type' => function() { + 'type' => function () { return ! empty( $this->wc_data->get_type() ) ? $this->wc_data->get_type() : null; }, - 'priceRaw' => function() { + 'priceRaw' => function () { return ! empty( $this->wc_data->get_price() ) ? $this->wc_data->get_price() : null; }, - 'regularPriceRaw' => function() { + 'regularPriceRaw' => function () { return ! empty( $this->wc_data->get_regular_price() ) ? $this->wc_data->get_regular_price() : null; }, - 'salePriceRaw' => function() { + 'salePriceRaw' => function () { return ! empty( $this->wc_data->get_sale_price() ) ? $this->wc_data->get_sale_price() : null; }, @@ -223,19 +222,19 @@ protected function init() { * These field resolvers are used in connection resolvers to define WP_Query argument. * Note: underscore naming style is used as a quick identifier */ - 'parent_id' => function() { + 'parent_id' => function () { return ! empty( $this->wc_data->get_parent_id() ) ? $this->wc_data->get_parent_id() : null; }, - 'parentId' => function() { + 'parentId' => function () { return ! empty( $this->wc_data->get_parent_id() ) ? Relay::toGlobalId( 'product', (string) $this->wc_data->get_parent_id() ) : null; }, - 'shipping_class_id' => function() { + 'shipping_class_id' => function () { return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null; }, - 'image_id' => function() { + 'image_id' => function () { return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null; }, - 'attributes' => function() { + 'attributes' => function () { return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : null; }, ]; diff --git a/includes/model/class-product.php b/includes/model/class-product.php index 0f0b73a8d..1ce241b08 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -95,7 +95,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Product extends WC_Post { - /** * Stores the product type: external, grouped, simple, variable. * @@ -192,43 +191,43 @@ protected function init() { $type = $this->wc_data->get_type(); $fields = [ - 'ID' => function() { + 'ID' => function () { return ! empty( $this->wc_data->get_id() ) ? $this->wc_data->get_id() : null; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->ID ) ? Relay::toGlobalId( 'product', "{$this->ID}" ) : null; }, - 'type' => function() { + 'type' => function () { return ! empty( $this->wc_data->get_type() ) ? $this->wc_data->get_type() : null; }, - 'slug' => function() { + 'slug' => function () { return ! empty( $this->wc_data->get_slug() ) ? $this->wc_data->get_slug() : null; }, - 'name' => function() { + 'name' => function () { return ! empty( $this->wc_data->get_name() ) ? html_entity_decode( $this->wc_data->get_name() ) : null; }, - 'date' => function() { + 'date' => function () { return ! empty( $this->wc_data ) ? $this->wc_data->get_date_created() : null; }, - 'modified' => function() { + 'modified' => function () { return ! empty( $this->wc_data ) ? $this->wc_data->get_date_modified() : null; }, - 'status' => function() { + 'status' => function () { return ! empty( $this->wc_data->get_status() ) ? $this->wc_data->get_status() : null; }, - 'featured' => function() { + 'featured' => function () { return $this->wc_data->get_featured(); }, - 'description' => function() { + 'description' => function () { return ! empty( $this->wc_data->get_description() ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ? apply_filters( 'the_content', $this->wc_data->get_description() ) : null; }, - 'descriptionRaw' => function() { + 'descriptionRaw' => function () { return ! empty( $this->wc_data->get_description() ) ? $this->wc_data->get_description() : null; }, - 'shortDescription' => function() { + 'shortDescription' => function () { $short_description = ! empty( $this->wc_data->get_short_description() ) ? apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound @@ -241,31 +240,31 @@ protected function init() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound return apply_filters( 'the_excerpt', $short_description ); }, - 'shortDescriptionRaw' => function() { + 'shortDescriptionRaw' => function () { return ! empty( $this->wc_data->get_short_description() ) ? $this->wc_data->get_short_description() : null; }, - 'sku' => function() { + 'sku' => function () { return ! empty( $this->wc_data->get_sku() ) ? $this->wc_data->get_sku() : null; }, - 'dateOnSaleFrom' => function() { + 'dateOnSaleFrom' => function () { return ! empty( $this->wc_data->get_date_on_sale_from() ) ? $this->wc_data->get_date_on_sale_from() : null; }, - 'dateOnSaleTo' => function() { + 'dateOnSaleTo' => function () { return ! empty( $this->wc_data->get_date_on_sale_to() ) ? $this->wc_data->get_date_on_sale_to() : null; }, - 'reviewsAllowed' => function() { + 'reviewsAllowed' => function () { return ! empty( $this->wc_data->get_reviews_allowed() ) ? $this->wc_data->get_reviews_allowed() : null; }, - 'purchaseNote' => function() { + 'purchaseNote' => function () { return ! empty( $this->wc_data->get_purchase_note() ) ? $this->wc_data->get_purchase_note() : null; }, - 'menuOrder' => function() { + 'menuOrder' => function () { return $this->wc_data->get_menu_order(); }, - 'averageRating' => function() { + 'averageRating' => function () { return $this->wc_data->get_average_rating(); }, - 'reviewCount' => function() { + 'reviewCount' => function () { return $this->wc_data->get_review_count(); }, 'onSale' => function () { @@ -279,13 +278,13 @@ protected function init() { * Editor/Shop Manager only fields */ 'catalogVisibility' => [ - 'callback' => function() { + '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' => [ - 'callback' => function() { + 'callback' => function () { return $this->wc_data->get_total_sales(); }, 'capability' => $this->post_type_object->cap->edit_posts, @@ -297,33 +296,33 @@ protected function init() { * These field resolvers are used in connection resolvers to define WP_Query argument * Note: underscore naming style is used as a quick identifier */ - 'upsell_ids' => function() { + 'upsell_ids' => function () { return ! empty( $this->wc_data->get_upsell_ids() ) ? array_map( 'absint', $this->wc_data->get_upsell_ids() ) : [ '0' ]; }, - 'attributes' => function() { + 'attributes' => function () { return ! empty( $this->wc_data->get_attributes() ) ? $this->wc_data->get_attributes() : []; }, - 'default_attributes' => function() { + 'default_attributes' => function () { 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() { + 'gallery_image_ids' => function () { return ! empty( $this->wc_data->get_gallery_image_ids() ) ? $this->wc_data->get_gallery_image_ids() : [ '0' ]; }, - 'category_ids' => function() { + 'category_ids' => function () { return ! empty( $this->wc_data->get_category_ids() ) ? $this->wc_data->get_category_ids() : [ '0' ]; }, - 'tag_ids' => function() { + 'tag_ids' => function () { return ! empty( $this->wc_data->get_tag_ids() ) ? $this->wc_data->get_tag_ids() : [ '0' ]; }, - 'parent_id' => function() { + 'parent_id' => function () { return ! empty( $this->wc_data->get_parent_id() ) ? $this->wc_data->get_parent_id() : null; }, - 'post' => function() { + 'post' => function () { return ! empty( $this->wc_data->post ) ? $this->wc_data->post : null; }, ]; @@ -335,23 +334,23 @@ protected function init() { ) ) { $fields += [ - 'price' => function() { + 'price' => function () { return ! empty( $this->wc_data->get_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data ) ) : null; }, - 'priceRaw' => function() { + 'priceRaw' => function () { return ! empty( $this->wc_data->get_price() ) ? $this->wc_data->get_price() : null; }, - 'regularPrice' => function() { + 'regularPrice' => function () { return ! empty( $this->wc_data->get_regular_price() ) ? wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) ) : null; }, - 'regularPriceRaw' => function() { + 'regularPriceRaw' => function () { return ! empty( $this->wc_data->get_regular_price() ) ? $this->wc_data->get_regular_price() : null; }, - 'salePrice' => function() { + 'salePrice' => function () { return ! empty( $this->wc_data->get_sale_price() ) ? wc_graphql_price( \wc_get_price_to_display( @@ -363,13 +362,13 @@ protected function init() { ) : null; }, - 'salePriceRaw' => function() { + 'salePriceRaw' => function () { return ! empty( $this->wc_data->get_sale_price() ) ? $this->wc_data->get_sale_price() : null; }, - 'taxStatus' => function() { + 'taxStatus' => function () { return ! empty( $this->wc_data->get_tax_status() ) ? $this->wc_data->get_tax_status() : null; }, - 'taxClass' => function() { + 'taxClass' => function () { return $this->wc_data->get_tax_class(); }, ]; @@ -382,48 +381,48 @@ protected function init() { ) ) { $fields += [ - 'manageStock' => function() { + 'manageStock' => function () { return $this->wc_data->get_manage_stock(); }, - 'stockQuantity' => function() { + 'stockQuantity' => function () { return ! empty( $this->wc_data->get_stock_quantity() ) ? $this->wc_data->get_stock_quantity() : null; }, - 'backorders' => function() { + 'backorders' => function () { return ! empty( $this->wc_data->get_backorders() ) ? $this->wc_data->get_backorders() : null; }, - 'backordersAllowed' => function() { + 'backordersAllowed' => function () { return $this->wc_data->backorders_allowed(); }, - 'soldIndividually' => function() { + 'soldIndividually' => function () { return $this->wc_data->is_sold_individually(); }, - 'weight' => function() { + 'weight' => function () { return ! empty( $this->wc_data->get_weight() ) ? $this->wc_data->get_weight() : null; }, - 'length' => function() { + 'length' => function () { return ! empty( $this->wc_data->get_length() ) ? $this->wc_data->get_length() : null; }, - 'width' => function() { + 'width' => function () { return ! empty( $this->wc_data->get_width() ) ? $this->wc_data->get_width() : null; }, - 'height' => function() { + 'height' => function () { return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null; }, 'shippingClassId' => function () { return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_shipping_class_id() : null; }, - 'shippingRequired' => function() { + 'shippingRequired' => function () { return $this->wc_data->needs_shipping(); }, - 'shippingTaxable' => function() { + 'shippingTaxable' => function () { return $this->wc_data->is_shipping_taxable(); }, - 'cross_sell_ids' => function() { + 'cross_sell_ids' => function () { return ! empty( $this->wc_data->get_cross_sell_ids() ) ? array_map( 'absint', $this->wc_data->get_cross_sell_ids() ) : [ '0' ]; }, - 'stockStatus' => function() { + 'stockStatus' => function () { return ! empty( $this->wc_data->get_stock_status() ) ? $this->wc_data->get_stock_status() : null; }, ]; @@ -432,53 +431,53 @@ protected function init() { switch ( true ) { case apply_filters( "graphql_{$type}_product_model_use_virtual_data_fields", 'simple' === $type ): $fields += [ - 'virtual' => function() { + 'virtual' => function () { return $this->wc_data->is_virtual(); }, - 'downloadExpiry' => function() { + 'downloadExpiry' => function () { return $this->wc_data->get_download_expiry(); }, - 'downloadable' => function() { + 'downloadable' => function () { return $this->wc_data->is_downloadable(); }, - 'downloadLimit' => function() { + 'downloadLimit' => function () { return ! empty( $this->wc_data->get_download_limit() ) ? $this->wc_data->get_download_limit() : null; }, - 'downloads' => function() { + '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 = [ - 'price' => function() { + 'price' => function () { return $this->get_variation_price(); }, - 'regularPrice' => function() { + 'regularPrice' => function () { return $this->get_variation_price( 'regular' ); }, - 'salePrice' => function() { + 'salePrice' => function () { return $this->get_variation_price( 'sale' ); }, - 'variation_ids' => function() { + 'variation_ids' => function () { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) : [ '0' ]; }, - 'priceRaw' => function() { + 'priceRaw' => function () { return $this->get_variation_price( '', true ); }, - 'regularPriceRaw' => function() { + 'regularPriceRaw' => function () { return $this->get_variation_price( 'regular', true ); }, - 'salePriceRaw' => function() { + 'salePriceRaw' => function () { return $this->get_variation_price( 'sale', true ); }, ] + $fields; break; case apply_filters( "graphql_{$type}_product_model_use_external_fields", 'external' === $type ): $fields += [ - 'externalUrl' => function() { + 'externalUrl' => function () { /** * External product * @@ -487,7 +486,7 @@ protected function init() { $data = $this->wc_data; return ! empty( $data->get_product_url() ) ? $data->get_product_url() : null; }, - 'buttonText' => function() { + 'buttonText' => function () { /** * External product * @@ -500,15 +499,15 @@ protected function init() { break; case apply_filters( "graphql_{$type}_product_model_use_grouped_fields", 'grouped' === $type ): $fields += [ - 'addToCartText' => function() { + 'addToCartText' => function () { return ! empty( $this->wc_data->add_to_cart_text() ) ? $this->wc_data->add_to_cart_text() : null; }, - 'addToCartDescription' => function() { + 'addToCartDescription' => function () { return ! empty( $this->wc_data->add_to_cart_description() ) ? $this->wc_data->add_to_cart_description() : null; }, - 'grouped_ids' => function() { + 'grouped_ids' => function () { return ! empty( $this->wc_data->get_children() ) ? array_map( 'absint', $this->wc_data->get_children() ) : [ '0' ]; @@ -524,11 +523,11 @@ protected function init() { * and some fields act as aliases/decorator for existing fields. */ $fields += [ - 'commentCount' => function() { + 'commentCount' => function () { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return ! empty( $this->reviewCount ) ? $this->reviewCount : null; }, - 'commentStatus' => function() { + 'commentStatus' => function () { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase return isset( $this->reviewsAllowed ) && $this->reviewsAllowed ? 'open' : 'closed'; }, diff --git a/includes/model/class-shipping-method.php b/includes/model/class-shipping-method.php index ef3a627ef..7015ec2d3 100644 --- a/includes/model/class-shipping-method.php +++ b/includes/model/class-shipping-method.php @@ -27,7 +27,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Shipping_Method extends Model { - /** * Shipping_Method constructor * @@ -64,19 +63,19 @@ protected function is_private() { protected function init() { if ( empty( $this->fields ) ) { $this->fields = [ - 'ID' => function() { + 'ID' => function () { return $this->data->id; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->data->id ) ? Relay::toGlobalId( 'shipping_method', $this->data->id ) : null; }, - 'databaseId' => function() { + 'databaseId' => function () { return ! empty( $this->ID ) ? $this->ID : null; }, - 'title' => function() { + 'title' => function () { return ! empty( $this->data->method_title ) ? $this->data->method_title : null; }, - 'description' => function() { + '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 08eb2e99e..5c3ebbf16 100644 --- a/includes/model/class-tax-rate.php +++ b/includes/model/class-tax-rate.php @@ -49,7 +49,6 @@ * @package WPGraphQL\WooCommerce\Model */ class Tax_Rate extends Model { - /** * Tax_Rate constructor * @@ -86,46 +85,46 @@ protected function is_private() { protected function init() { if ( empty( $this->fields ) ) { $this->fields = [ - 'ID' => function() { + 'ID' => function () { return $this->data->tax_rate_id; }, - 'id' => function() { + 'id' => function () { return ! empty( $this->data->tax_rate_id ) ? Relay::toGlobalId( 'tax_rate', (string) $this->data->tax_rate_id ) : null; }, - 'databaseId' => function() { + 'databaseId' => function () { return ! empty( $this->ID ) ? $this->ID : null; }, - 'country' => function() { + 'country' => function () { return ! empty( $this->data->tax_rate_country ) ? $this->data->tax_rate_country : null; }, - 'state' => function() { + 'state' => function () { return ! empty( $this->data->tax_rate_state ) ? $this->data->tax_rate_state : null; }, - 'city' => function() { + 'city' => function () { return ! empty( $this->data->tax_rate_city ) ? $this->data->tax_rate_city : [ '*' ]; }, - 'postcode' => function() { + 'postcode' => function () { return ! empty( $this->data->tax_rate_postcode ) ? $this->data->tax_rate_postcode : [ '*' ]; }, - 'rate' => function() { + 'rate' => function () { return ! empty( $this->data->tax_rate ) ? $this->data->tax_rate : null; }, - 'name' => function() { + 'name' => function () { return ! empty( $this->data->tax_rate_name ) ? $this->data->tax_rate_name : null; }, - 'priority' => function() { + 'priority' => function () { return ! empty( $this->data->tax_rate_priority ) ? $this->data->tax_rate_priority : null; }, - 'compound' => function() { + 'compound' => function () { return ! empty( $this->data->tax_rate_compound ) ? $this->data->tax_rate_compound : null; }, - 'shipping' => function() { + 'shipping' => function () { return ! empty( $this->data->tax_rate_shipping ) ? $this->data->tax_rate_shipping : null; }, - 'order' => function() { + 'order' => function () { return ! is_null( $this->data->tax_rate_order ) ? absint( $this->data->tax_rate_order ) : null; }, - 'class' => function() { + 'class' => function () { return ! is_null( $this->data->tax_rate_class ) ? $this->data->tax_rate_class : ''; }, ]; diff --git a/includes/model/class-wc-post.php b/includes/model/class-wc-post.php index 5d1f4a076..b5c494cc1 100644 --- a/includes/model/class-wc-post.php +++ b/includes/model/class-wc-post.php @@ -22,7 +22,6 @@ * @package WPGraphQL\WooCommerce\Model */ abstract class WC_Post extends Post { - /** * Stores the WC_Data object connected to the model. * @@ -107,7 +106,7 @@ public function __call( $method, $args ) { return $this->wc_data->$method( ...$args ); } - $class = __CLASS__; + $class = self::class; throw new \BadMethodCallException( "Call to undefined method {$method} on the {$class}" ); } diff --git a/includes/mutation/class-cart-add-fee.php b/includes/mutation/class-cart-add-fee.php index 68a2e8d7a..41a08b394 100644 --- a/includes/mutation/class-cart-add-fee.php +++ b/includes/mutation/class-cart-add-fee.php @@ -19,7 +19,6 @@ * Class - Cart_Add_Fee */ class Cart_Add_Fee { - /** * Registers mutation * @@ -86,7 +85,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( ! current_user_can( 'edit_shop_orders' ) ) { diff --git a/includes/mutation/class-cart-add-item.php b/includes/mutation/class-cart-add-item.php index 32be9e569..3e8cb3c6a 100644 --- a/includes/mutation/class-cart-add-item.php +++ b/includes/mutation/class-cart-add-item.php @@ -19,7 +19,6 @@ * Class - Cart_Add_Item */ class Cart_Add_Item { - /** * Registers mutation * @@ -89,7 +88,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Prepare args for "add_to_cart" from input data. diff --git a/includes/mutation/class-cart-add-items.php b/includes/mutation/class-cart-add-items.php index 485ba2653..5e2a6ae92 100644 --- a/includes/mutation/class-cart-add-items.php +++ b/includes/mutation/class-cart-add-items.php @@ -97,7 +97,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Throw error, if no cart item data provided. diff --git a/includes/mutation/class-cart-apply-coupon.php b/includes/mutation/class-cart-apply-coupon.php index 0d64e8089..dbd12a178 100644 --- a/includes/mutation/class-cart-apply-coupon.php +++ b/includes/mutation/class-cart-apply-coupon.php @@ -17,7 +17,6 @@ * Class - Cart_Apply_Coupon */ class Cart_Apply_Coupon { - /** * Registers mutation * @@ -57,7 +56,7 @@ public static function get_output_fields() { return [ 'applied' => [ 'type' => 'AppliedCoupon', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['code']; }, ], @@ -71,7 +70,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input ) { + return static function ( $input ) { Cart_Mutation::check_session_token(); $reason = ''; diff --git a/includes/mutation/class-cart-empty.php b/includes/mutation/class-cart-empty.php index f1ffd3a0a..5aef54647 100644 --- a/includes/mutation/class-cart-empty.php +++ b/includes/mutation/class-cart-empty.php @@ -19,7 +19,6 @@ * Class - Cart_Empty */ class Cart_Empty { - /** * Registers mutation * @@ -61,7 +60,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Get/Clone WC_Cart instance. diff --git a/includes/mutation/class-cart-fill.php b/includes/mutation/class-cart-fill.php index 78bdcf5ac..ae767bce4 100644 --- a/includes/mutation/class-cart-fill.php +++ b/includes/mutation/class-cart-fill.php @@ -78,14 +78,14 @@ public static function get_output_fields() { ], 'applied' => [ 'type' => [ 'list_of' => 'AppliedCoupon' ], - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $codes = $payload['applied']; return ! empty( $codes ) ? $codes : null; }, ], 'chosenShippingMethods' => [ 'type' => [ 'list_of' => 'String' ], - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $methods = $payload['chosen_shipping_methods']; return ! empty( $methods ) ? $methods : null; }, @@ -150,7 +150,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Throw error, if no cart item data provided. diff --git a/includes/mutation/class-cart-remove-coupons.php b/includes/mutation/class-cart-remove-coupons.php index aeaa67344..9ebf2813d 100644 --- a/includes/mutation/class-cart-remove-coupons.php +++ b/includes/mutation/class-cart-remove-coupons.php @@ -17,7 +17,6 @@ * Class - Cart_Remove_Coupons */ class Cart_Remove_Coupons { - /** * Registers mutation * @@ -65,7 +64,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input ) { + return static function ( $input ) { Cart_Mutation::check_session_token(); // Retrieve product database ID if relay ID provided. diff --git a/includes/mutation/class-cart-remove-items.php b/includes/mutation/class-cart-remove-items.php index 796f1bd91..0a0b265d1 100644 --- a/includes/mutation/class-cart-remove-items.php +++ b/includes/mutation/class-cart-remove-items.php @@ -19,7 +19,6 @@ * Class - Cart_Remove_Items */ class Cart_Remove_Items { - /** * Registers mutation * @@ -77,7 +76,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( \WC()->cart->is_empty() ) { diff --git a/includes/mutation/class-cart-restore-items.php b/includes/mutation/class-cart-restore-items.php index 11aaaa6d9..2f6979a1e 100644 --- a/includes/mutation/class-cart-restore-items.php +++ b/includes/mutation/class-cart-restore-items.php @@ -19,7 +19,6 @@ * Class - Cart_Restore_Items */ class Cart_Restore_Items { - /** * Registers mutation * @@ -65,7 +64,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); if ( empty( $input['keys'] ) ) { diff --git a/includes/mutation/class-cart-update-item-quantities.php b/includes/mutation/class-cart-update-item-quantities.php index 23c9fefb3..80bcf9f02 100644 --- a/includes/mutation/class-cart-update-item-quantities.php +++ b/includes/mutation/class-cart-update-item-quantities.php @@ -20,7 +20,6 @@ * Class - Cart_Update_Item_Quantities */ class Cart_Update_Item_Quantities { - /** * Registers mutation * @@ -96,7 +95,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Confirm "items" exists. @@ -138,7 +137,7 @@ public static function mutate_and_get_payload() { $errors = array_keys( array_filter( array_merge( $removed, $updated ), - static function( $value ) { + static function ( $value ) { return ! $value; } ) diff --git a/includes/mutation/class-cart-update-shipping-method.php b/includes/mutation/class-cart-update-shipping-method.php index 500bcc65c..cf44f0db9 100644 --- a/includes/mutation/class-cart-update-shipping-method.php +++ b/includes/mutation/class-cart-update-shipping-method.php @@ -17,7 +17,6 @@ * Class - Cart_Update_Shipping_Method */ class Cart_Update_Shipping_Method { - /** * Registers mutation * @@ -64,7 +63,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input ) { + return static function ( $input ) { Cart_Mutation::check_session_token(); if ( empty( $input['shippingMethods'] ) ) { diff --git a/includes/mutation/class-checkout.php b/includes/mutation/class-checkout.php index e70c83593..f8e9d0d36 100644 --- a/includes/mutation/class-checkout.php +++ b/includes/mutation/class-checkout.php @@ -22,7 +22,6 @@ * Class Checkout */ class Checkout { - /** * Registers mutation * @@ -98,25 +97,25 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, ], 'customer' => [ 'type' => 'Customer', - 'resolve' => static function() { + 'resolve' => static function () { return is_user_logged_in() ? new Customer( get_current_user_id() ) : new Customer(); }, ], 'result' => [ 'type' => 'String', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['result']; }, ], 'redirect' => [ 'type' => 'String', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['redirect']; }, ], @@ -129,7 +128,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Create order. $order = null; try { diff --git a/includes/mutation/class-coupon-create.php b/includes/mutation/class-coupon-create.php index f38f3685d..f351f2bdb 100644 --- a/includes/mutation/class-coupon-create.php +++ b/includes/mutation/class-coupon-create.php @@ -21,7 +21,6 @@ * Class Coupon_Create */ class Coupon_Create { - /** * Registers mutation * @@ -33,7 +32,7 @@ public static function register_mutation() { [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ __CLASS__, 'mutate_and_get_payload' ], + 'mutateAndGetPayload' => [ self::class, 'mutate_and_get_payload' ], ] ); } @@ -137,13 +136,13 @@ public static function get_output_fields() { return [ 'coupon' => [ 'type' => 'Coupon', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return new Coupon( $payload['id'] ); }, ], 'code' => [ 'type' => 'String', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['code']; }, ], diff --git a/includes/mutation/class-coupon-delete.php b/includes/mutation/class-coupon-delete.php index 9cf3a3785..988bf8426 100644 --- a/includes/mutation/class-coupon-delete.php +++ b/includes/mutation/class-coupon-delete.php @@ -20,7 +20,6 @@ * Class Coupon_Delete */ class Coupon_Delete { - /** * Registers mutation * @@ -32,7 +31,7 @@ public static function register_mutation() { [ 'inputFields' => self::get_input_fields(), 'outputFields' => self::get_output_fields(), - 'mutateAndGetPayload' => [ __CLASS__, 'mutate_and_get_payload' ], + 'mutateAndGetPayload' => [ self::class, 'mutate_and_get_payload' ], ] ); } @@ -66,7 +65,7 @@ public static function get_output_fields() { [ 'coupon' => [ 'type' => 'Coupon', - 'resolve' => static function( $payload ) { + 'resolve' => static 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 f492e1bc7..6670ce968 100644 --- a/includes/mutation/class-coupon-update.php +++ b/includes/mutation/class-coupon-update.php @@ -14,7 +14,6 @@ * Class Coupon_Update */ class Coupon_Update { - /** * Registers mutation * diff --git a/includes/mutation/class-customer-register.php b/includes/mutation/class-customer-register.php index 48fd33b08..2a28f1509 100644 --- a/includes/mutation/class-customer-register.php +++ b/includes/mutation/class-customer-register.php @@ -22,7 +22,6 @@ * Class - Customer_Register */ class Customer_Register { - /** * Registers mutation * @@ -102,7 +101,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Validate input. if ( empty( $input['email'] ) ) { throw new UserError( __( 'Please provide a valid email address.', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-customer-update.php b/includes/mutation/class-customer-update.php index 989399643..bec062a85 100644 --- a/includes/mutation/class-customer-update.php +++ b/includes/mutation/class-customer-update.php @@ -21,7 +21,6 @@ * Class - Customer_Update */ class Customer_Update { - /** * Registers mutation * @@ -93,7 +92,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { $session_only = empty( $input['id'] ); $payload = null; diff --git a/includes/mutation/class-order-create.php b/includes/mutation/class-order-create.php index f72db75e9..9136fe51e 100644 --- a/includes/mutation/class-order-create.php +++ b/includes/mutation/class-order-create.php @@ -21,7 +21,6 @@ * Class Order_Create */ class Order_Create { - /** * Registers mutation * @@ -121,13 +120,13 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, ], 'orderId' => [ 'type' => 'Int', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['id']; }, ], @@ -140,7 +139,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Check if authorized to create this order. if ( ! Order_Mutation::authorized( $input, $context, $info, 'create', null ) ) { throw new UserError( __( 'User does not have the capabilities necessary to create an order.', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-order-delete-items.php b/includes/mutation/class-order-delete-items.php index 7c3084772..582a8aff1 100644 --- a/includes/mutation/class-order-delete-items.php +++ b/includes/mutation/class-order-delete-items.php @@ -21,7 +21,6 @@ * Class Order_Delete_Items */ class Order_Delete_Items { - /** * Registers mutation * @@ -71,7 +70,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['order']; }, ], @@ -84,7 +83,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-order-delete.php b/includes/mutation/class-order-delete.php index 47b7c1118..24aa6b5bf 100644 --- a/includes/mutation/class-order-delete.php +++ b/includes/mutation/class-order-delete.php @@ -22,7 +22,6 @@ * Class Order_Delete */ class Order_Delete { - /** * Registers mutation * @@ -72,7 +71,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return $payload['order']; }, ], @@ -85,7 +84,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-order-update.php b/includes/mutation/class-order-update.php index 785008c3a..8fa16abde 100644 --- a/includes/mutation/class-order-update.php +++ b/includes/mutation/class-order-update.php @@ -22,7 +22,6 @@ * Class Order_Update */ class Order_Update { - /** * Registers mutation * @@ -73,7 +72,7 @@ public static function get_output_fields() { return [ 'order' => [ 'type' => 'Order', - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { return new Order( $payload['id'] ); }, ], @@ -86,7 +85,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Retrieve order ID. $order_id = null; if ( ! empty( $input['id'] ) ) { diff --git a/includes/mutation/class-payment-method-delete.php b/includes/mutation/class-payment-method-delete.php index c46fb82cd..d1f836d33 100644 --- a/includes/mutation/class-payment-method-delete.php +++ b/includes/mutation/class-payment-method-delete.php @@ -19,7 +19,6 @@ * Class Payment_Method_Delete */ class Payment_Method_Delete { - /** * Registers mutation * @@ -74,7 +73,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { global $wp; if ( ! is_user_logged_in() ) { throw new UserError( __( 'Must be authenticated to set a default payment method', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-payment-method-set-default.php b/includes/mutation/class-payment-method-set-default.php index 157c9ca96..895c7bb59 100644 --- a/includes/mutation/class-payment-method-set-default.php +++ b/includes/mutation/class-payment-method-set-default.php @@ -19,7 +19,6 @@ * Class Payment_Method_Set_Default */ class Payment_Method_Set_Default { - /** * Registers mutation * @@ -80,7 +79,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { global $wp; if ( ! is_user_logged_in() ) { throw new UserError( __( 'Must be authenticated to set a default payment method', 'wp-graphql-woocommerce' ) ); diff --git a/includes/mutation/class-review-delete-restore.php b/includes/mutation/class-review-delete-restore.php index b86837cfe..9678ce78e 100644 --- a/includes/mutation/class-review-delete-restore.php +++ b/includes/mutation/class-review-delete-restore.php @@ -20,7 +20,6 @@ * Class Review_Delete_Restore */ class Review_Delete_Restore { - /** * Registers mutation * @@ -87,7 +86,7 @@ public static function get_output_fields( $restore = false ) { 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the affected product review', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { if ( ! isset( $payload['rating'] ) ) { return null; } @@ -98,7 +97,7 @@ public static function get_output_fields( $restore = false ) { 'affectedId' => [ 'type' => 'Id', 'description' => __( 'The affected product review ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { $deleted = (object) $payload['commentObject']; return ! empty( $deleted->comment_ID ) ? Relay::toGlobalId( 'comment', (string) $deleted->comment_ID ) : null; @@ -107,7 +106,7 @@ public static function get_output_fields( $restore = false ) { 'review' => [ 'type' => 'Comment', 'description' => __( 'The affected product review', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload, $args, AppContext $context, ResolveInfo $info ) use ( $restore ) { + 'resolve' => static function ( $payload, $args, AppContext $context, ResolveInfo $info ) use ( $restore ) { if ( empty( $payload['commentObject'] ) ) { return null; } @@ -130,7 +129,7 @@ public static function get_output_fields( $restore = false ) { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Retrieve the product review rating for the payload. $id_parts = Relay::fromGlobalId( $input['id'] ); if ( empty( $id_parts['id'] ) ) { diff --git a/includes/mutation/class-review-update.php b/includes/mutation/class-review-update.php index c98223ba8..e66088eb7 100644 --- a/includes/mutation/class-review-update.php +++ b/includes/mutation/class-review-update.php @@ -20,7 +20,6 @@ * Class Review_Update */ class Review_Update { - /** * Registers mutation * @@ -69,7 +68,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Set comment type to "review". $input['type'] = 'review'; diff --git a/includes/mutation/class-review-write.php b/includes/mutation/class-review-write.php index 821ec4afe..7e7d0eca6 100644 --- a/includes/mutation/class-review-write.php +++ b/includes/mutation/class-review-write.php @@ -20,7 +20,6 @@ * Class Review_Write */ class Review_Write { - /** * Registers mutation * @@ -67,7 +66,7 @@ public static function get_output_fields() { 'rating' => [ 'type' => 'Float', 'description' => __( 'The product rating of the review that was created', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload ) { + 'resolve' => static function ( $payload ) { if ( ! isset( $payload['id'] ) || ! absint( $payload['id'] ) ) { return null; } @@ -77,7 +76,7 @@ public static function get_output_fields() { 'review' => [ 'type' => 'Comment', 'description' => __( 'The product review that was created', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $payload, $args, AppContext $context ) { + 'resolve' => static function ( $payload, $args, AppContext $context ) { if ( ! isset( $payload['id'] ) || ! absint( $payload['id'] ) ) { return null; } @@ -99,7 +98,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { // Set comment type to "review". $input['type'] = 'review'; diff --git a/includes/mutation/class-update-session.php b/includes/mutation/class-update-session.php index c73d6d7e0..cc744abd6 100644 --- a/includes/mutation/class-update-session.php +++ b/includes/mutation/class-update-session.php @@ -20,7 +20,6 @@ * Class - Update_Session */ class Update_Session { - /** * Registers mutation * @@ -95,7 +94,7 @@ public static function get_output_fields() { * @return callable */ public static function mutate_and_get_payload() { - return static function( $input, AppContext $context, ResolveInfo $info ) { + return static function ( $input, AppContext $context, ResolveInfo $info ) { Cart_Mutation::check_session_token(); // Guard against missing input. diff --git a/includes/type/enum/class-countries.php b/includes/type/enum/class-countries.php index b9332a6f5..c166e0253 100644 --- a/includes/type/enum/class-countries.php +++ b/includes/type/enum/class-countries.php @@ -22,7 +22,7 @@ public static function register() { $countries = $wc_countries->get_countries(); array_walk( $countries, - static function( &$value, $code ) { + static function ( &$value, $code ) { $value = [ 'value' => $code ]; } ); diff --git a/includes/type/enum/class-id-type-enums.php b/includes/type/enum/class-id-type-enums.php index a8e2d673f..1d2500252 100644 --- a/includes/type/enum/class-id-type-enums.php +++ b/includes/type/enum/class-id-type-enums.php @@ -12,7 +12,6 @@ * Class - Id_Type_Enums */ class Id_Type_Enums { - /** * Register the Enum used for setting the field to identify WC crud objects by * diff --git a/includes/type/input/class-cart-item-input.php b/includes/type/input/class-cart-item-input.php index c87a3959f..61a851108 100644 --- a/includes/type/input/class-cart-item-input.php +++ b/includes/type/input/class-cart-item-input.php @@ -12,7 +12,6 @@ * Class Cart_Item_Input */ class Cart_Item_Input { - /** * Registers type * diff --git a/includes/type/input/class-cart-item-quantity-input.php b/includes/type/input/class-cart-item-quantity-input.php index 0f10457bf..c1691b7e3 100644 --- a/includes/type/input/class-cart-item-quantity-input.php +++ b/includes/type/input/class-cart-item-quantity-input.php @@ -12,7 +12,6 @@ * Class Cart_Item_Quantity_Input */ class Cart_Item_Quantity_Input { - /** * Registers type * diff --git a/includes/type/input/class-create-account-input.php b/includes/type/input/class-create-account-input.php index a58f81698..cc743c428 100644 --- a/includes/type/input/class-create-account-input.php +++ b/includes/type/input/class-create-account-input.php @@ -12,7 +12,6 @@ * Class Create_Account_Input */ class Create_Account_Input { - /** * Registers type * diff --git a/includes/type/input/class-customer-address-input.php b/includes/type/input/class-customer-address-input.php index 2ec3b7d52..37d6ae6e3 100644 --- a/includes/type/input/class-customer-address-input.php +++ b/includes/type/input/class-customer-address-input.php @@ -12,7 +12,6 @@ * Class Customer_Address_Input */ class Customer_Address_Input { - /** * Registers type * diff --git a/includes/type/input/class-fee-line-input.php b/includes/type/input/class-fee-line-input.php index d4b2c0b93..848460585 100644 --- a/includes/type/input/class-fee-line-input.php +++ b/includes/type/input/class-fee-line-input.php @@ -12,7 +12,6 @@ * Class Fee_Line_Input */ class Fee_Line_Input { - /** * Registers type * diff --git a/includes/type/input/class-line-item-input.php b/includes/type/input/class-line-item-input.php index 90a79cf50..501a608ef 100644 --- a/includes/type/input/class-line-item-input.php +++ b/includes/type/input/class-line-item-input.php @@ -12,7 +12,6 @@ * Class Line_Item_Input */ class Line_Item_Input { - /** * Registers type * diff --git a/includes/type/input/class-meta-data-input.php b/includes/type/input/class-meta-data-input.php index d589c15d3..74be1c4ee 100644 --- a/includes/type/input/class-meta-data-input.php +++ b/includes/type/input/class-meta-data-input.php @@ -12,7 +12,6 @@ * Class Meta_Data_Input */ class Meta_Data_Input { - /** * Registers type * diff --git a/includes/type/input/class-orderby-inputs.php b/includes/type/input/class-orderby-inputs.php index 3819cbfee..61843b0ae 100644 --- a/includes/type/input/class-orderby-inputs.php +++ b/includes/type/input/class-orderby-inputs.php @@ -15,7 +15,6 @@ * Class Orderby_Inputs */ class Orderby_Inputs { - /** * Registers Orderby WPInputObject type to schema. * diff --git a/includes/type/input/class-product-attribute-input.php b/includes/type/input/class-product-attribute-input.php index be6b29ee6..2ef5e1a4d 100644 --- a/includes/type/input/class-product-attribute-input.php +++ b/includes/type/input/class-product-attribute-input.php @@ -12,7 +12,6 @@ * Class Product_Attribute_Input */ class Product_Attribute_Input { - /** * Registers type * diff --git a/includes/type/input/class-product-taxonomy-filter-input.php b/includes/type/input/class-product-taxonomy-filter-input.php index 9660b47c8..5b748d105 100644 --- a/includes/type/input/class-product-taxonomy-filter-input.php +++ b/includes/type/input/class-product-taxonomy-filter-input.php @@ -12,7 +12,6 @@ * Class Product_Taxonomy_Filter_Input */ class Product_Taxonomy_Filter_Input { - /** * Registers type * diff --git a/includes/type/input/class-product-taxonomy-input.php b/includes/type/input/class-product-taxonomy-input.php index 0ed5c6853..372700c20 100644 --- a/includes/type/input/class-product-taxonomy-input.php +++ b/includes/type/input/class-product-taxonomy-input.php @@ -12,7 +12,6 @@ * Class Product_Taxonomy_Input */ class Product_Taxonomy_Input { - /** * Registers type * diff --git a/includes/type/input/class-shipping-line-input.php b/includes/type/input/class-shipping-line-input.php index d9e30e59d..c33ca5c19 100644 --- a/includes/type/input/class-shipping-line-input.php +++ b/includes/type/input/class-shipping-line-input.php @@ -12,7 +12,6 @@ * Class Shipping_Line_Input */ class Shipping_Line_Input { - /** * Registers type * 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 88880c282..97a1bbd12 100644 --- a/includes/type/input/class-tax-rate-connection-orderby-input.php +++ b/includes/type/input/class-tax-rate-connection-orderby-input.php @@ -12,7 +12,6 @@ * Class Tax_Rate_Connection_Orderby_Input */ class Tax_Rate_Connection_Orderby_Input { - /** * Registers type * diff --git a/includes/type/interface/class-attribute.php b/includes/type/interface/class-attribute.php index 1db26a122..633bbe2ce 100644 --- a/includes/type/interface/class-attribute.php +++ b/includes/type/interface/class-attribute.php @@ -12,7 +12,6 @@ * Class Attribute */ class Attribute { - /** * Registers the "Product" interface. * @@ -40,7 +39,7 @@ public static function register_interface() { }, ], ], - 'resolveType' => static function( $value ) { + 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); if ( $value->is_taxonomy() ) { return $type_registry->get_type( 'SimpleAttribute' ); diff --git a/includes/type/interface/class-cart-error.php b/includes/type/interface/class-cart-error.php index 75121c947..59f59dfed 100644 --- a/includes/type/interface/class-cart-error.php +++ b/includes/type/interface/class-cart-error.php @@ -12,7 +12,6 @@ * Class Cart_Error */ class Cart_Error { - /** * Registers the "CartError" interface. * @@ -24,7 +23,7 @@ public static function register_interface() { [ 'description' => __( 'An error that occurred when updating the cart', 'wp-graphql-woocommerce' ), 'fields' => self::get_fields(), - 'resolveType' => static function( array $value ) { + 'resolveType' => static function ( array $value ) { $type_registry = \WPGraphQL::get_type_registry(); switch ( $value['type'] ) { case 'INVALID_CART_ITEM': diff --git a/includes/type/interface/class-payment-token.php b/includes/type/interface/class-payment-token.php index 7f4f41f38..f7ed1ebab 100644 --- a/includes/type/interface/class-payment-token.php +++ b/includes/type/interface/class-payment-token.php @@ -15,7 +15,6 @@ * Class Payment_Token */ class Payment_Token { - /** * Registers the "PaymentToken" interface. * @@ -28,7 +27,7 @@ public static function register_interface() { 'description' => __( 'Payment token object', 'wp-graphql-woocommerce' ), 'interfaces' => [ 'Node' ], 'fields' => self::get_fields(), - 'resolveType' => static function( $value ) { + 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); $type = $value->get_type(); switch ( $type ) { @@ -62,28 +61,28 @@ public static function get_fields( $other_fields = [] ) { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Token ID unique identifier', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? Relay::toGlobalId( 'token', $source->get_id() ) : null; }, ], 'tokenId' => [ 'type' => [ 'non_null' => 'Integer' ], 'description' => __( 'Token database ID.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_id() ) ? $source->get_id() : null; }, ], 'type' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Token type', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_type() ) ? $source->get_type() : null; }, ], 'gateway' => [ 'type' => 'PaymentGateway', 'description' => __( 'Token payment gateway', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $gateway_id = $source->get_gateway_id(); return null; }, @@ -91,7 +90,7 @@ public static function get_fields( $other_fields = [] ) { 'isDefault' => [ 'type' => 'Boolean', 'description' => __( 'Is token connected to user\'s preferred payment method', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->is_default() ) ? $source->is_default() : false; }, ], diff --git a/includes/type/interface/class-product-attribute.php b/includes/type/interface/class-product-attribute.php index ecda051f3..361dfae78 100644 --- a/includes/type/interface/class-product-attribute.php +++ b/includes/type/interface/class-product-attribute.php @@ -12,7 +12,6 @@ * Class Product_Attribute */ class Product_Attribute { - /** * Registers the "Product" interface. * @@ -25,7 +24,7 @@ public static function register_interface() { 'description' => __( 'Product attribute object', 'wp-graphql-woocommerce' ), 'interfaces' => [ 'Node' ], 'fields' => self::get_fields(), - 'resolveType' => static function( $value ) { + 'resolveType' => static function ( $value ) { $type_registry = \WPGraphQL::get_type_registry(); if ( $value->is_taxonomy() ) { return $type_registry->get_type( 'GlobalProductAttribute' ); diff --git a/includes/type/interface/class-product.php b/includes/type/interface/class-product.php index 60881ef74..a3cf48409 100644 --- a/includes/type/interface/class-product.php +++ b/includes/type/interface/class-product.php @@ -19,7 +19,6 @@ * Class - Product */ class Product { - /** * Registers the "Product" interface. * @@ -121,7 +120,7 @@ public static function get_fields() { 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->descriptionRaw; @@ -138,7 +137,7 @@ public static function get_fields() { 'description' => __( 'Format of the field output', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shortDescriptionRaw; @@ -186,7 +185,7 @@ public static function get_fields() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Main image', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { // @codingStandardsIgnoreLine. if ( empty( $source->image_id ) || ! absint( $source->image_id ) ) { return null; diff --git a/includes/type/object/class-cart-error-types.php b/includes/type/object/class-cart-error-types.php index b12c9f275..e47b28cd5 100644 --- a/includes/type/object/class-cart-error-types.php +++ b/includes/type/object/class-cart-error-types.php @@ -12,7 +12,6 @@ * Class Cart_Error_Types */ class Cart_Error_Types { - /** * Registers types to the GraphQL schema. * @@ -28,35 +27,35 @@ public static function register() { 'productId' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Cart item product database ID or global ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['productId'] ) ? $error['productId'] : null; }, ], 'quantity' => [ 'type' => 'Int', 'description' => __( 'Cart item quantity', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['quantity'] ) ? $error['quantity'] : null; }, ], 'variationId' => [ 'type' => 'Int', 'description' => __( 'Cart item product variation database ID or global ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['variationId'] ) ? $error['variationId'] : null; }, ], 'variation' => [ 'type' => [ 'list_of' => 'ProductAttributeOutput' ], 'description' => __( 'Cart item product variation attributes', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['variation'] ) ? $error['variation'] : null; }, ], 'extraData' => [ 'type' => 'String', 'description' => __( 'JSON string representation of extra cart item data', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['extraData'] ) ? $error['extraData'] : null; }, ], @@ -73,7 +72,7 @@ public static function register() { 'code' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code of the coupon the failed to be applied', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['code'] ) ? $error['code'] : null; }, ], @@ -90,14 +89,14 @@ public static function register() { 'package' => [ 'type' => [ 'non_null' => 'Integer' ], 'description' => __( 'Index of package for desired shipping method', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return isset( $error['package'] ) && is_int( $error['package'] ) ? $error['package'] : null; }, ], 'chosenMethod' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'ID of chosen shipping rate', 'wp-graphql-woocommerce' ), - 'resolve' => static function( array $error ) { + 'resolve' => static function ( array $error ) { return ! empty( $error['chosen_method'] ) ? $error['chosen_method'] : null; }, ], diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index 76b1ecf5b..7c734027e 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -21,7 +21,6 @@ * Class - Cart_Type */ class Cart_Type { - /** * Register Cart-related types and queries to the WPGraphQL schema * @@ -54,7 +53,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_subtotal() ) ? $source->get_subtotal() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -73,7 +72,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_subtotal_tax() ) ? $source->get_subtotal_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -92,7 +91,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_discount_total() ) ? $source->get_discount_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -111,7 +110,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_discount_tax() ) ? $source->get_discount_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -124,7 +123,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'availableShippingMethods' => [ 'type' => [ 'list_of' => 'ShippingPackage' ], 'description' => __( 'Available shipping methods for this order.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $packages = []; $available_packages = $source->needs_shipping() @@ -142,7 +141,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'chosenShippingMethods' => [ 'type' => [ 'list_of' => 'String' ], 'description' => __( 'Shipping method chosen for this order.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $chosen_shipping_methods = []; $available_packages = $source->needs_shipping() @@ -167,7 +166,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_shipping_total() ) ? $source->get_shipping_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -186,7 +185,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_shipping_tax() ) ? $source->get_shipping_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -205,7 +204,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { if ( $source->display_prices_including_tax() ) { $cart_subtotal = $source->get_subtotal() + $source->get_subtotal_tax(); } else { @@ -232,7 +231,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_cart_contents_tax() ) ? $source->get_cart_contents_tax() : 0; @@ -253,7 +252,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_fee_total() ) ? $source->get_fee_total() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -272,7 +271,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_fee_tax() ) ? $source->get_fee_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -291,7 +290,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $source->calculate_totals(); $price = isset( $source->get_totals()['total'] ) ? apply_filters( 'graphql_woocommerce_cart_get_total', $source->get_totals()['total'] ) @@ -313,7 +312,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = ! is_null( $source->get_total_tax() ) ? $source->get_total_tax() : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -326,7 +325,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'totalTaxes' => [ 'type' => [ 'list_of' => 'CartTax' ], 'description' => __( 'Cart total taxes itemized', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $taxes = $source->get_tax_totals(); return ! empty( $taxes ) ? array_values( $taxes ) : null; }, @@ -334,14 +333,14 @@ public static function get_cart_fields( $other_fields = [] ) { 'isEmpty' => [ 'type' => 'Boolean', 'description' => __( 'Is cart empty', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->is_empty() ) ? $source->is_empty() : null; }, ], 'displayPricesIncludeTax' => [ 'type' => 'Boolean', 'description' => __( 'Do display prices include taxes', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->display_prices_including_tax() ) ? $source->display_prices_including_tax() : null; @@ -350,7 +349,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'needsShippingAddress' => [ 'type' => 'Boolean', 'description' => __( 'Is customer shipping address needed', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->needs_shipping_address() ) ? $source->needs_shipping_address() : null; @@ -359,7 +358,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'fees' => [ 'type' => [ 'list_of' => 'CartFee' ], 'description' => __( 'Additional fees on the cart.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $fees = $source->get_fees(); return ! empty( $fees ) ? array_values( $fees ) : null; }, @@ -367,7 +366,7 @@ public static function get_cart_fields( $other_fields = [] ) { 'appliedCoupons' => [ 'type' => [ 'list_of' => 'AppliedCoupon' ], 'description' => __( 'Coupons applied to the cart', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $applied_coupons = $source->get_applied_coupons(); return ! empty( $applied_coupons ) ? $applied_coupons : null; @@ -399,7 +398,7 @@ public static function get_cart_connections( $other_connections = [] ) { 'itemCount' => [ 'type' => 'Int', 'description' => __( 'Total number of items in the cart.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -415,7 +414,7 @@ public static function get_cart_connections( $other_connections = [] ) { 'productCount' => [ 'type' => 'Int', 'description' => __( 'Total number of different products in the cart', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( empty( $source['edges'] ) ) { return 0; } @@ -480,14 +479,14 @@ public static function register_cart_item() { 'key' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'CartItem ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['key'] ) ? $source['key'] : null; }, ], 'quantity' => [ 'type' => 'Int', 'description' => __( 'Quantity of the product', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return isset( $source['quantity'] ) ? absint( $source['quantity'] ) : null; }, ], @@ -500,7 +499,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_subtotal'] ) ? floatval( $source['line_subtotal'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -519,7 +518,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_subtotal_tax'] ) ? floatval( $source['line_subtotal_tax'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -538,7 +537,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : 0; $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; $price = $price_without_tax + $tax; @@ -559,7 +558,7 @@ public static function register_cart_item() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $price = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : 0; if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -582,7 +581,7 @@ public static function register_cart_item() { 'description' => __( 'Retrieve multiple metas by key', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { // Check if "key" argument set and assigns to target "keys" array. if ( ! empty( $args['key'] ) && ! empty( $source[ $args['key'] ] ) ) { $keys = [ $args['key'] ]; @@ -639,7 +638,7 @@ public static function register_cart_item() { 'simpleVariations' => [ 'type' => [ 'list_of' => 'SimpleAttribute' ], 'description' => __( 'Simple variation attribute data', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $attributes = []; $variation = $source['node']; @@ -670,7 +669,7 @@ public static function register_cart_item() { 'attributes' => [ 'type' => [ 'list_of' => 'VariationAttribute' ], 'description' => __( 'Attributes of the variation.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $attributes = []; $variation = $source['node']; @@ -721,42 +720,42 @@ public static function register_cart_fee() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Fee ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, ], 'name' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Fee name', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->name ) ? $source->name : null; }, ], 'taxClass' => [ 'type' => 'TaxClassEnum', 'description' => __( 'Fee tax class', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->tax_class ) ? $source->tax_class : null; }, ], 'taxable' => [ 'type' => 'Boolean', 'description' => __( 'Is fee taxable?', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->taxable ) ? $source->taxable : null; }, ], 'amount' => [ 'type' => 'Float', 'description' => __( 'Fee amount', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->amount ) ? $source->amount : 0; }, ], 'total' => [ 'type' => 'Float', 'description' => __( 'Fee total', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! is_null( $source->total ) ? $source->total : 0; }, ], @@ -764,6 +763,7 @@ public static function register_cart_fee() { ] ); } + /** * Registers CartTax type * @@ -778,21 +778,21 @@ public static function register_cart_tax() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'Tax Rate ID', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->tax_rate_id ) ? $source->tax_rate_id : null; }, ], 'label' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Tax label', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->label ) ? $source->label : null; }, ], 'isCompound' => [ 'type' => 'Boolean', 'description' => __( 'Is tax compound?', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->is_compound ) ? $source->is_compound : null; }, ], @@ -805,7 +805,7 @@ public static function register_cart_tax() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $amount = ! empty( $source->amount ) ? $source->amount : null; if ( ! $amount ) { @@ -838,7 +838,7 @@ public static function register_applied_coupon() { 'code' => [ 'type' => [ 'non_null' => 'String' ], 'description' => __( 'Coupon code', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return $source; }, ], @@ -855,7 +855,7 @@ public static function register_applied_coupon() { ], ], 'description' => __( 'Discount applied with this coupon', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $ex_tax = ! empty( $args['excludeTax'] ) ? $args['excludeTax'] : true; $amount = Factory::resolve_cart()->get_coupon_discount_amount( $source, $ex_tax ); @@ -875,7 +875,7 @@ public static function register_applied_coupon() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $tax = Factory::resolve_cart()->get_coupon_discount_tax_amount( $source ); if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { @@ -888,7 +888,7 @@ public static function register_applied_coupon() { 'description' => [ 'type' => 'String', 'description' => __( 'Description of applied coupon', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $coupon = new \WC_Coupon( $source ); return $coupon->get_description(); }, diff --git a/includes/type/object/class-country-state-type.php b/includes/type/object/class-country-state-type.php index f38fc3e9c..a2c536f2f 100644 --- a/includes/type/object/class-country-state-type.php +++ b/includes/type/object/class-country-state-type.php @@ -14,7 +14,6 @@ * Class Country_State_Type */ class Country_State_Type { - /** * Registers type * diff --git a/includes/type/object/class-coupon-type.php b/includes/type/object/class-coupon-type.php index 298f3c7e4..d6e9b3040 100644 --- a/includes/type/object/class-coupon-type.php +++ b/includes/type/object/class-coupon-type.php @@ -14,7 +14,6 @@ * Class Coupon_Type */ class Coupon_Type { - /** * Register Coupon type and queries to the WPGraphQL schema * diff --git a/includes/type/object/class-customer-address-type.php b/includes/type/object/class-customer-address-type.php index 7314428e9..c8b2e1be6 100644 --- a/includes/type/object/class-customer-address-type.php +++ b/includes/type/object/class-customer-address-type.php @@ -14,7 +14,6 @@ * Class Customer_Address_Type */ class Customer_Address_Type { - /** * Registers Customer WPObject type * @@ -29,77 +28,77 @@ public static function register() { 'firstName' => [ 'type' => 'String', 'description' => __( 'First name', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['first_name'] ) ? $address['first_name'] : null; }, ], 'lastName' => [ 'type' => 'String', 'description' => __( 'Last name', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['last_name'] ) ? $address['last_name'] : null; }, ], 'company' => [ 'type' => 'String', 'description' => __( 'Company', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['company'] ) ? $address['company'] : null; }, ], 'address1' => [ 'type' => 'String', 'description' => __( 'Address 1', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['address_1'] ) ? $address['address_1'] : null; }, ], 'address2' => [ 'type' => 'String', 'description' => __( 'Address 2', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['address_2'] ) ? $address['address_2'] : null; }, ], 'city' => [ 'type' => 'String', 'description' => __( 'City', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['city'] ) ? $address['city'] : null; }, ], 'state' => [ 'type' => 'String', 'description' => __( 'State', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['state'] ) ? $address['state'] : null; }, ], 'postcode' => [ 'type' => 'String', 'description' => __( 'Zip Postal Code', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['postcode'] ) ? $address['postcode'] : null; }, ], 'country' => [ 'type' => 'CountriesEnum', 'description' => __( 'Country', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['country'] ) ? $address['country'] : null; }, ], 'email' => [ 'type' => 'String', 'description' => __( 'E-mail', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['email'] ) ? $address['email'] : null; }, ], 'phone' => [ 'type' => 'String', 'description' => __( 'Phone', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $address ) { + 'resolve' => static function ( $address ) { return ! empty( $address['phone'] ) ? $address['phone'] : null; }, ], diff --git a/includes/type/object/class-customer-type.php b/includes/type/object/class-customer-type.php index a208bede6..9b456ebc0 100644 --- a/includes/type/object/class-customer-type.php +++ b/includes/type/object/class-customer-type.php @@ -20,7 +20,6 @@ * Class Customer_Type */ class Customer_Type { - /** * Returns the "Customer" type fields. * @@ -38,7 +37,7 @@ public static function get_fields( $other_fields = [] ) { 'databaseId' => [ 'type' => 'Int', 'description' => __( 'The ID of the customer in the database', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $database_id = absint( $source->ID ); return ! empty( $database_id ) ? $database_id : null; }, @@ -58,7 +57,7 @@ public static function get_fields( $other_fields = [] ) { 'lastOrder' => [ 'type' => 'Order', 'description' => __( 'Gets the customers last order.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->last_order_id, $context ); }, ], @@ -224,7 +223,7 @@ public static function register() { 'availablePaymentMethods' => [ 'type' => [ 'list_of' => 'PaymentToken' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { return array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ); } @@ -235,7 +234,7 @@ public static function register() { 'availablePaymentMethodsCC' => [ 'type' => [ 'list_of' => 'PaymentTokenCC' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { return array_filter( array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ), @@ -251,7 +250,7 @@ static function ( $token ) { 'availablePaymentMethodsEC' => [ 'type' => [ 'list_of' => 'PaymentTokenECheck' ], 'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( get_current_user_id() === $source->ID ) { return array_filter( array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ), @@ -283,7 +282,7 @@ public static function register_session_handler_fields() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( \get_current_user_id() === $source->ID || 'guest' === $source->id ) { /** * Session handler. @@ -308,7 +307,7 @@ public static function register_session_handler_fields() { [ 'type' => 'String', 'description' => __( 'A JWT token that can be used in future requests to for WooCommerce session identification', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( \get_current_user_id() === $source->userId ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase /** * Session handler @@ -326,7 +325,6 @@ public static function register_session_handler_fields() { ); } - /** * Registers selected authorizing_url_fields * @@ -341,7 +339,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'cartUrl' => [ 'type' => 'String', 'description' => __( 'A nonced link to the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -367,7 +365,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'cartNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the cart page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -391,7 +389,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'checkoutUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the checkout page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -417,7 +415,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'checkoutNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the checkout page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { // Get current customer and user ID. $customer_id = $source->ID; $current_user_id = get_current_user_id(); @@ -441,7 +439,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'accountUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the account page for session user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -471,7 +469,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'accountNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the account page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -499,7 +497,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'addPaymentMethodUrl' => [ 'type' => 'String', 'description' => __( 'A nonce link to the add payment method page for the authenticated user. Expires in 24 hours.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( ! is_user_logged_in() ) { return null; } @@ -529,7 +527,7 @@ public static function register_authorizing_url_fields( $fields_to_register ) { 'addPaymentMethodNonce' => [ 'type' => 'String', 'description' => __( 'A nonce for the add payment method page. By default, it expires in 1 hour.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { if ( ! is_user_logged_in() ) { return null; } diff --git a/includes/type/object/class-downloadable-item-type.php b/includes/type/object/class-downloadable-item-type.php index 8e1d4ac92..203167646 100644 --- a/includes/type/object/class-downloadable-item-type.php +++ b/includes/type/object/class-downloadable-item-type.php @@ -19,7 +19,6 @@ * Class Downloadable_Item_Type */ class Downloadable_Item_Type { - /** * Registers type * diff --git a/includes/type/object/class-meta-data-type.php b/includes/type/object/class-meta-data-type.php index 96d654c2a..a41074951 100644 --- a/includes/type/object/class-meta-data-type.php +++ b/includes/type/object/class-meta-data-type.php @@ -14,7 +14,6 @@ * Class Meta_Data_Type */ class Meta_Data_Type { - /** * Register Order type and queries to the WPGraphQL schema * @@ -83,7 +82,7 @@ public static function get_metadata_field_definition() { 'description' => __( 'Retrieve meta with matching keys', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { // Set unique flag. $single = empty( $args['multiple'] ); @@ -93,7 +92,7 @@ public static function get_metadata_field_definition() { if ( ! is_array( $data ) ) { $data = array_filter( $source->get_meta_data(), - static function( $meta ) use ( $data ) { + static function ( $meta ) use ( $data ) { return $meta->value === $data; } ); @@ -105,7 +104,7 @@ static function( $meta ) use ( $data ) { $found = []; $data = array_filter( $source->get_meta_data(), - static function( $meta ) use ( $keys, $single, &$found ) { + static function ( $meta ) use ( $keys, $single, &$found ) { if ( in_array( $meta->key, $keys, true ) ) { if ( $single ) { if ( ! in_array( $meta->key, $found, true ) ) { @@ -123,7 +122,7 @@ static function( $meta ) use ( $keys, $single, &$found ) { $found = []; $data = array_filter( $source->get_meta_data(), - static function( $meta ) use ( $single, &$found ) { + static function ( $meta ) use ( $single, &$found ) { if ( $single ) { if ( ! in_array( $meta->key, $found, true ) ) { $found[] = $meta->key; diff --git a/includes/type/object/class-order-item-type.php b/includes/type/object/class-order-item-type.php index b1e478baa..db55989b6 100644 --- a/includes/type/object/class-order-item-type.php +++ b/includes/type/object/class-order-item-type.php @@ -18,7 +18,6 @@ * Class Order_Item_Type */ class Order_Item_Type { - /** * Register order item type * @@ -46,7 +45,7 @@ public static function register() { 'coupon' => [ 'type' => 'Coupon', 'description' => __( 'Line\'s Coupon', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_crud_object( $source->coupon_id, $context ); }, ], @@ -115,7 +114,7 @@ public static function register() { 'shippingMethod' => [ 'type' => 'ShippingMethod', 'description' => __( 'Shipping Line\'s shipping method', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return Factory::resolve_shipping_method( $source->method_id ); }, ], @@ -149,7 +148,7 @@ public static function register() { 'taxRate' => [ 'type' => 'TaxRate', 'description' => __( 'Tax line\'s tax rate', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { return Factory::resolve_tax_rate( $source->rate_id, $context ); }, ], @@ -263,35 +262,35 @@ public static function register() { 'taxLineId' => [ 'type' => [ 'non_null' => 'Int' ], 'description' => __( 'Order item ID for tax line connected to this statement', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['ID'] ) ? $source['ID'] : null; }, ], 'subtotal' => [ 'type' => 'Float', 'description' => __( 'Subtotal', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['subtotal'] ) ? $source['subtotal'] : null; }, ], 'total' => [ 'type' => 'Float', 'description' => __( 'Total', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['total'] ) ? $source['total'] : null; }, ], 'amount' => [ 'type' => 'Float', 'description' => __( 'Amount taxed', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['amount'] ) ? $source['amount'] : null; }, ], 'taxLine' => [ 'type' => 'TaxLine', 'description' => __( 'Tax line connected to this statement', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $item = \WC_Order_Factory::get_order_item( $source['ID'] ); // Return early if the item is not found. if ( false === $item ) { diff --git a/includes/type/object/class-order-type.php b/includes/type/object/class-order-type.php index 969579385..0d9d144cc 100644 --- a/includes/type/object/class-order-type.php +++ b/includes/type/object/class-order-type.php @@ -20,7 +20,6 @@ * Class Order_Type */ class Order_Type { - /** * Register Order type and queries to the WPGraphQL schema * @@ -129,7 +128,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->discountTotalRaw; @@ -148,7 +147,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->discountTaxRaw; @@ -167,7 +166,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shippingTotalRaw; @@ -186,7 +185,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->shippingTaxRaw; @@ -205,7 +204,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->cartTaxRaw; @@ -224,7 +223,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->totalRaw; @@ -242,7 +241,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->totalTaxRaw; @@ -261,7 +260,7 @@ public static function get_fields( $other_fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->subtotalRaw; @@ -309,14 +308,14 @@ public static function get_fields( $other_fields = [] ) { 'parent' => [ 'type' => 'Order', 'description' => __( 'Parent order', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $order, array $args, AppContext $context ) { + 'resolve' => static function ( $order, array $args, AppContext $context ) { return Factory::resolve_crud_object( $order->parent_id, $context ); }, ], 'customer' => [ 'type' => 'Customer', 'description' => __( 'Order customer', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $order, array $args, AppContext $context ) { + 'resolve' => static function ( $order, array $args, AppContext $context ) { if ( empty( $order->customer_id ) ) { // Guest orders don't have an attached customer. return null; @@ -371,27 +370,27 @@ public static function get_connections( $other_connections = [] ) { 'taxLines' => [ 'toType' => 'TaxLine', 'connectionArgs' => [], - 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + 'resolve' => [ self::class, 'resolve_item_connection' ], ], 'feeLines' => [ 'toType' => 'FeeLine', 'connectionArgs' => [], - 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + 'resolve' => [ self::class, 'resolve_item_connection' ], ], 'shippingLines' => [ 'toType' => 'ShippingLine', 'connectionArgs' => [], - 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + 'resolve' => [ self::class, 'resolve_item_connection' ], ], 'couponLines' => [ 'toType' => 'CouponLine', 'connectionArgs' => [], - 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + 'resolve' => [ self::class, 'resolve_item_connection' ], ], 'lineItems' => [ 'toType' => 'LineItem', 'connectionArgs' => [], - 'resolve' => [ __CLASS__, 'resolve_item_connection' ], + 'resolve' => [ self::class, 'resolve_item_connection' ], ], 'downloadableItems' => [ 'toType' => 'DownloadableItem', diff --git a/includes/type/object/class-payment-gateway-type.php b/includes/type/object/class-payment-gateway-type.php index eddf6ff9e..2b64ffd6e 100644 --- a/includes/type/object/class-payment-gateway-type.php +++ b/includes/type/object/class-payment-gateway-type.php @@ -14,7 +14,6 @@ * Class Payment_Gateway_Type */ class Payment_Gateway_Type { - /** * Registers type * @@ -30,28 +29,28 @@ public static function register() { 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->id ) ? $source->id : null; }, ], 'title' => [ 'type' => 'String', 'description' => __( 'gateway\'s title', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->title ) ? $source->title : null; }, ], 'description' => [ 'type' => 'String', 'description' => __( 'gateway\'s description', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->description ) ? $source->description : null; }, ], 'icon' => [ 'type' => 'String', 'description' => __( 'gateway\'s icon', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->icon ) ? $source->icon : null; }, ], diff --git a/includes/type/object/class-payment-token-types.php b/includes/type/object/class-payment-token-types.php index 86f5e7682..cd961a401 100644 --- a/includes/type/object/class-payment-token-types.php +++ b/includes/type/object/class-payment-token-types.php @@ -16,7 +16,6 @@ * Class Payment_Token_Types */ class Payment_Token_Types { - /** * Registers types * @@ -52,12 +51,13 @@ public static function get_e_check_fields() { 'last4' => [ 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored account number', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, ], ]; } + /** * Returns field definitions for PaymentTokenCC type. * @@ -68,28 +68,28 @@ public static function get_credit_card_fields() { 'cardType' => [ 'type' => 'String', 'description' => __( 'Card type (visa, mastercard, etc)', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_card_type() ) ? $source->get_card_type() : null; }, ], 'expiryYear' => [ 'type' => 'String', 'description' => __( 'Card\'s expiration year.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_expiry_year() ) ? $source->get_expiry_year() : null; }, ], 'expiryMonth' => [ 'type' => 'String', 'description' => __( 'Card\'s expiration month', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_expiry_month() ) ? $source->get_expiry_month() : null; }, ], 'last4' => [ 'type' => 'Integer', 'description' => __( 'Last 4 digits of the stored credit card number', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source->get_last4() ) ? $source->get_last4() : null; }, ], diff --git a/includes/type/object/class-product-attribute-types.php b/includes/type/object/class-product-attribute-types.php index d14f65401..47a8fdeb1 100644 --- a/includes/type/object/class-product-attribute-types.php +++ b/includes/type/object/class-product-attribute-types.php @@ -14,7 +14,6 @@ * Class Product_Attribute_Types */ class Product_Attribute_Types { - /** * Registers ProductAttribute types * diff --git a/includes/type/object/class-product-category-type.php b/includes/type/object/class-product-category-type.php index 1e93584f7..71071e82b 100644 --- a/includes/type/object/class-product-category-type.php +++ b/includes/type/object/class-product-category-type.php @@ -16,7 +16,6 @@ * Class - Product_Category_Type */ class Product_Category_Type { - /** * Registers fields to ProductCategory. * @@ -29,7 +28,7 @@ public static function register_fields() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product category image', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $thumbnail_id = get_term_meta( $source->term_id, 'thumbnail_id', true ); return ! empty( $thumbnail_id ) ? $context->get_loader( 'post' )->load_deferred( $thumbnail_id ) @@ -39,7 +38,7 @@ public static function register_fields() { 'display' => [ 'type' => 'ProductCategoryDisplay', 'description' => __( 'Product category display type', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $display = get_term_meta( $source->term_id, 'display_type', true ); return ! empty( $display ) ? $display : 'default'; }, @@ -47,7 +46,7 @@ public static function register_fields() { 'menuOrder' => [ 'type' => 'Integer', 'description' => __( 'Product category menu order', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $order = get_term_meta( $source->term_id, 'order', true ); return ! empty( $order ) ? $order : 0; }, diff --git a/includes/type/object/class-product-download-type.php b/includes/type/object/class-product-download-type.php index 53f2e686c..bdd593a72 100644 --- a/includes/type/object/class-product-download-type.php +++ b/includes/type/object/class-product-download-type.php @@ -14,7 +14,6 @@ * Class Product_Download_Type */ class Product_Download_Type { - /** * Register ProductDownload type * diff --git a/includes/type/object/class-product-types.php b/includes/type/object/class-product-types.php index 46d5e51c5..a87ee6ab5 100644 --- a/includes/type/object/class-product-types.php +++ b/includes/type/object/class-product-types.php @@ -19,7 +19,6 @@ * Class Product_Types */ class Product_Types { - /** * Registers product types to the WPGraphQL schema * @@ -154,7 +153,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->priceRaw; @@ -172,7 +171,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->regularPriceRaw; @@ -191,7 +190,7 @@ public static function get_pricing_and_tax_fields( $fields = [] ) { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->salePriceRaw; @@ -346,7 +345,7 @@ private static function register_group_product_type() { 'price' => [ 'type' => 'String', 'description' => __( 'Products\' price range', 'wp-graphql-woocommerce' ), - 'resolve' => static function( Model $source ) { + 'resolve' => static function ( Model $source ) { $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); $child_prices = []; $children = array_filter( array_map( 'wc_get_product', $source->grouped_ids ) ); diff --git a/includes/type/object/class-product-variation-type.php b/includes/type/object/class-product-variation-type.php index ba1a0198b..04b1e5a5f 100644 --- a/includes/type/object/class-product-variation-type.php +++ b/includes/type/object/class-product-variation-type.php @@ -16,7 +16,6 @@ * Class Product_Variation_Type */ class Product_Variation_Type { - /** * Register ProductVariation type to the WPGraphQL schema * @@ -71,7 +70,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->priceRaw; @@ -89,7 +88,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->regularPriceRaw; @@ -108,7 +107,7 @@ public static function register() { 'description' => __( 'Format of the price', 'wp-graphql-woocommerce' ), ], ], - 'resolve' => static function( $source, $args ) { + 'resolve' => static function ( $source, $args ) { if ( isset( $args['format'] ) && 'raw' === $args['format'] ) { // @codingStandardsIgnoreLine. return $source->salePriceRaw; @@ -229,7 +228,7 @@ public static function register() { 'image' => [ 'type' => 'MediaItem', 'description' => __( 'Product variation main image', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { return ! empty( $source->image_id ) ? $context->get_loader( 'post' )->load_deferred( $source->image_id ) : null; diff --git a/includes/type/object/class-refund-type.php b/includes/type/object/class-refund-type.php index 215df11a2..2388bbdb3 100644 --- a/includes/type/object/class-refund-type.php +++ b/includes/type/object/class-refund-type.php @@ -16,7 +16,6 @@ * Class Refund_Type */ class Refund_Type { - /** * Register Refund type and queries to the WPGraphQL schema. * @@ -52,7 +51,7 @@ public static function register() { 'refundedBy' => [ 'type' => 'User', 'description' => __( 'User who completed the refund', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $user_id = absint( $source->refunded_by_id ); if ( 0 !== $user_id ) { return $context->get_loader( 'user' )->load( $user_id ); diff --git a/includes/type/object/class-root-query.php b/includes/type/object/class-root-query.php index 2691dc2fc..f62a6b972 100644 --- a/includes/type/object/class-root-query.php +++ b/includes/type/object/class-root-query.php @@ -38,7 +38,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $_, $args ) { + 'resolve' => static function ( $_, $args ) { $token_invalid = apply_filters( 'graphql_woocommerce_session_token_errors', null ); if ( $token_invalid ) { throw new UserError( $token_invalid ); @@ -60,7 +60,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args, AppContext $context ) { + 'resolve' => static function ( $source, array $args, AppContext $context ) { $item = Factory::resolve_cart()->get_cart_item( $args['key'] ); if ( empty( $item ) || empty( $item['key'] ) ) { throw new UserError( __( 'Failed to retrieve cart item.', 'wp-graphql-woocommerce' ) ); @@ -77,7 +77,7 @@ public static function register_fields() { ], ], 'description' => __( 'The cart object', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source, array $args ) { + 'resolve' => static function ( $source, array $args ) { $fees = Factory::resolve_cart()->get_fees(); $fee_id = $args['id']; @@ -464,7 +464,7 @@ public static function register_fields() { 'allowedCountries' => [ 'type' => [ 'list_of' => 'CountriesEnum' ], 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), - 'resolve' => static function() { + 'resolve' => static function () { $wc_countries = new \WC_Countries(); $countries = $wc_countries->get_allowed_countries(); @@ -480,7 +480,7 @@ public static function register_fields() { ], ], 'description' => __( 'Countries that the store sells to', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $_, $args ) { + 'resolve' => static function ( $_, $args ) { $country = $args['country']; $wc_countries = new \WC_Countries(); $states = $wc_countries->get_shipping_country_states(); diff --git a/includes/type/object/class-shipping-method-type.php b/includes/type/object/class-shipping-method-type.php index 6e529d983..f86df1841 100644 --- a/includes/type/object/class-shipping-method-type.php +++ b/includes/type/object/class-shipping-method-type.php @@ -14,7 +14,6 @@ * Class Shipping_Method_Type */ class Shipping_Method_Type { - /** * Registers shipping method type * diff --git a/includes/type/object/class-shipping-package-type.php b/includes/type/object/class-shipping-package-type.php index 09c91e57b..76ff18c95 100644 --- a/includes/type/object/class-shipping-package-type.php +++ b/includes/type/object/class-shipping-package-type.php @@ -14,7 +14,6 @@ * Class Shipping_Package_Type */ class Shipping_Package_Type { - /** * Registers type. * @@ -29,7 +28,7 @@ public static function register() { 'packageDetails' => [ 'type' => 'String', 'description' => __( 'Shipping package details', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { $product_names = []; foreach ( $source['contents'] as $item_id => $values ) { $product_names[ $item_id ] = html_entity_decode( $values['data']->get_name() . ' ×' . $values['quantity'] ); @@ -44,14 +43,14 @@ public static function register() { 'rates' => [ 'type' => [ 'list_of' => 'ShippingRate' ], 'description' => __( 'Shipping package rates', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { return ! empty( $source['rates'] ) ? $source['rates'] : null; }, ], 'supportsShippingCalculator' => [ 'type' => 'Boolean', 'description' => __( 'This shipping package supports the shipping calculator.', 'wp-graphql-woocommerce' ), - 'resolve' => static function( $source ) { + 'resolve' => static function ( $source ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound return apply_filters( 'woocommerce_shipping_show_shipping_calculator', true, $source['index'], $source ); }, diff --git a/includes/type/object/class-shipping-rate-type.php b/includes/type/object/class-shipping-rate-type.php index f50c30c70..e9e00edb1 100644 --- a/includes/type/object/class-shipping-rate-type.php +++ b/includes/type/object/class-shipping-rate-type.php @@ -14,7 +14,6 @@ * Class Shipping_Rate_Type */ class Shipping_Rate_Type { - /** * Registers type * diff --git a/includes/type/object/class-simple-attribute-type.php b/includes/type/object/class-simple-attribute-type.php index 7cbe3a000..ceb4d71c4 100644 --- a/includes/type/object/class-simple-attribute-type.php +++ b/includes/type/object/class-simple-attribute-type.php @@ -14,7 +14,6 @@ * Class Simple_Attribute_Type */ class Simple_Attribute_Type { - /** * Register SimpleAttribute type to the WPGraphQL schema * diff --git a/includes/type/object/class-tax-rate-type.php b/includes/type/object/class-tax-rate-type.php index 1c44aeecd..7c7250740 100644 --- a/includes/type/object/class-tax-rate-type.php +++ b/includes/type/object/class-tax-rate-type.php @@ -14,7 +14,6 @@ * Class Tax_Rate_Type */ class Tax_Rate_Type { - /** * Registers tax rate type * diff --git a/includes/type/object/class-variation-attribute-type.php b/includes/type/object/class-variation-attribute-type.php index 3b8e0c974..2f1cf7c8f 100644 --- a/includes/type/object/class-variation-attribute-type.php +++ b/includes/type/object/class-variation-attribute-type.php @@ -14,7 +14,6 @@ * Class Variation_Attribute_Type */ class Variation_Attribute_Type { - /** * Register VariationAttribute type to the WPGraphQL schema * diff --git a/includes/utils/class-protected-router.php b/includes/utils/class-protected-router.php index 3a4df5d4e..a0aa48a1e 100644 --- a/includes/utils/class-protected-router.php +++ b/includes/utils/class-protected-router.php @@ -14,7 +14,6 @@ * Class Protected_Router */ class Protected_Router { - /** * Stores the instance of the Protected_Router class * diff --git a/includes/utils/class-ql-session-handler.php b/includes/utils/class-ql-session-handler.php index d5d1235ff..3f18a8a6f 100644 --- a/includes/utils/class-ql-session-handler.php +++ b/includes/utils/class-ql-session-handler.php @@ -8,9 +8,9 @@ namespace WPGraphQL\WooCommerce\Utils; -use WC_Session_Handler; use Firebase\JWT\JWT; use Firebase\JWT\Key; +use WC_Session_Handler; /** * Class - QL_Session_Handler @@ -20,7 +20,6 @@ * @property int|string $_customer_id */ class QL_Session_Handler extends WC_Session_Handler { - /** * Stores the name of the HTTP header used to pass the session token. * @@ -163,7 +162,7 @@ public function init_session_token() { if ( is_wp_error( $token ) ) { add_filter( 'graphql_woocommerce_session_token_errors', - static function( $errors ) use ( $token ) { + static function ( $errors ) use ( $token ) { $errors = $token->get_error_message(); return $errors; } @@ -349,7 +348,7 @@ public function set_customer_session_token( $set ) { */ add_filter( 'graphql_response_headers_to_send', - function( $headers ) { + function ( $headers ) { $token = $this->build_token(); if ( $token ) { $headers[ $this->_token ] = $token; @@ -501,5 +500,4 @@ public function get_client_session_id() { // Return new client session ID. return $client_session_id; } - } diff --git a/includes/utils/class-session-transaction-manager.php b/includes/utils/class-session-transaction-manager.php index 15d41d984..1b8dce4a2 100644 --- a/includes/utils/class-session-transaction-manager.php +++ b/includes/utils/class-session-transaction-manager.php @@ -14,7 +14,6 @@ * Class - Session_Transaction_Manager */ class Session_Transaction_Manager { - /** * The request's transaction ID. * @@ -29,7 +28,6 @@ class Session_Transaction_Manager { */ private $session_handler = null; - /** * Singleton instance of class. * @@ -53,7 +51,6 @@ public static function get( &$session_handler ) { return self::$instance; } - /** * Session_Transaction_Manager constructor * diff --git a/phpcs.xml.dist b/phpcs.xml.dist index edd855dd6..6ba58b3a0 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,29 +1,71 @@ - - - Generally-applicable sniffs for WordPress plugins. + + Sniffs for the WPGraphQL ecosystem - WooGraphQL - + + ./wp-graphql-woocommerce.php + ./access-functions.php + ./includes/ + /vendor/ + /vendor-prefixed/ + /node_modules/ + /phpstan/ + local/* + **/tests/** + /tests/_support/Helper/crud-helpers + + - - + + + + + + - + + + + + + + + - - - - + - - - - - + + - + + + + + + + + + + + + + + + + + + + + + @@ -36,50 +78,4 @@ - - - - - - - - - - - - - - - /tests/ - - - - - /tests/ - - - /tests/ - - - /tests/ - - - /tests/ - - - /tests/ - - - /tests/ - - - - wp-graphql-woocommerce.php - access-functions.php - includes/ - /phpstan/ - /vendor/ - /node_modules/ - local/* - /tests/_support/Helper/crud-helpers diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index e2f14a5c1..f6b260255 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -127,7 +127,7 @@ function init() { foreach ( $not_ready as $dep ) { add_action( 'admin_notices', - static function() use ( $dep ) { + static function () use ( $dep ) { ?>