Skip to content

Commit 7048671

Browse files
committed
chore: Linter compliances met
1 parent 6f860d4 commit 7048671

15 files changed

+73
-63
lines changed

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-core-schema-filters.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use GraphQL\Error\UserError;
1212
use WPGraphQL\WooCommerce\Data\Factory;
1313
use WPGraphQL\WooCommerce\Data\Loader\WC_CPT_Loader;
14-
use WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader;
1514
use WPGraphQL\WooCommerce\Data\Loader\WC_Cart_Item_Loader;
15+
use WPGraphQL\WooCommerce\Data\Loader\WC_Customer_Loader;
1616
use WPGraphQL\WooCommerce\Data\Loader\WC_Downloadable_Item_Loader;
1717
use WPGraphQL\WooCommerce\Data\Loader\WC_Order_Item_Loader;
1818
use WPGraphQL\WooCommerce\Data\Loader\WC_Shipping_Method_Loader;
@@ -39,7 +39,7 @@ public static function add_filters() {
3939
add_filter( 'register_taxonomy_args', [ self::class, 'register_taxonomy_args' ], 10, 2 );
4040

4141
// Add data-loaders to AppContext.
42-
add_filter( 'graphql_data_loader_classes', [ self::class, 'graphql_data_loader_classes' ], 10, 2 );
42+
add_filter( 'graphql_data_loader_classes', [ self::class, 'graphql_data_loader_classes' ], 10 );
4343

4444
// Add node resolvers.
4545
add_filter(
@@ -272,8 +272,7 @@ public static function register_taxonomy_args( $args, $taxonomy ) {
272272
/**
273273
* Registers data-loaders to be used when resolving WooCommerce-related GraphQL types
274274
*
275-
* @param array $loaders - assigned loaders.
276-
* @param \WPGraphQL\AppContext $context - AppContext instance.
275+
* @param array $loaders Assigned loaders.
277276
*
278277
* @return array
279278
*/
@@ -409,6 +408,7 @@ public static function resolve_product_type( $value ) {
409408
} elseif ( $value instanceof \WPGraphQL\Model\Post && ( 'product' !== $value->post_type && 'product_variation' !== $value->post_type ) ) {
410409
throw new UserError(
411410
sprintf(
411+
/* translators: %s: Post type slug */
412412
__( 'The "%s" post type is not a valid product type.', 'wp-graphql-woocommerce' ),
413413
$value->post_type
414414
)
@@ -417,7 +417,7 @@ public static function resolve_product_type( $value ) {
417417
$product_model = $value;
418418
}
419419

420-
$product_type = $product_model->get_type();
420+
$product_type = $product_model->get_type();
421421
if ( isset( $possible_types[ $product_type ] ) ) {
422422
return $type_registry->get_type( $possible_types[ $product_type ] );
423423
} elseif ( $product_model instanceof \WPGraphQL\WooCommerce\Model\Product_Variation ) {
@@ -482,8 +482,8 @@ public static function make_order_notes_visible( $is_private, $model_name, $data
482482
if ( $data instanceof \WP_Comment && 'order_note' === $data->comment_type ) {
483483
// Get the parent order.
484484
$order_id = absint( $data->comment_post_ID );
485-
$order = wc_get_order( $order_id );
486-
485+
$order = wc_get_order( $order_id );
486+
487487
if ( ! $order ) {
488488
return true; // Keep it private if order not found.
489489
}
@@ -494,9 +494,14 @@ public static function make_order_notes_visible( $is_private, $model_name, $data
494494
}
495495

496496
// Allow customers to see customer notes on their own orders.
497-
$is_customer_note = get_comment_meta( $data->comment_ID, 'is_customer_note', true );
498-
if ( $is_customer_note && get_current_user_id() === $order->get_customer_id() ) {
499-
return false; // Not private.
497+
$comment_id = absint( $data->comment_ID );
498+
$is_customer_note = get_comment_meta( $comment_id, 'is_customer_note', true );
499+
if ( $is_customer_note && ! is_bool( $order ) && is_a( $order, \WC_Order::class ) ) {
500+
if ( get_current_user_id() === $order->get_customer_id() ) return false; // Not private.
501+
} elseif ( $is_customer_note && ! is_bool( $order ) && is_a( $order, \WC_Order_Refund::class ) ) {
502+
/** @var \WC_Order|false $parent */
503+
$parent = wc_get_order( $order->get_parent_id() );
504+
if ( $parent && get_current_user_id() === $parent->get_customer_id() ) return false; // Not private.
500505
}
501506

502507
// Otherwise keep it private.
@@ -509,11 +514,11 @@ public static function make_order_notes_visible( $is_private, $model_name, $data
509514
/**
510515
* Filter to set order notes visibility to public for authorized users.
511516
*
512-
* @param string $visibility The visibility of the object.
513-
* @param string $model_name The name of the model being checked.
514-
* @param mixed $data The data being checked.
515-
* @param int|null $owner The owner of the object.
516-
* @param \WP_User $current_user The current user.
517+
* @param string $visibility The visibility of the object.
518+
* @param string $model_name The name of the model being checked.
519+
* @param mixed $data The data being checked.
520+
* @param int|null $owner The owner of the object.
521+
* @param \WP_User $current_user The current user.
517522
*
518523
* @return string
519524
*/
@@ -526,10 +531,14 @@ public static function set_order_notes_visibility( $visibility, $model_name, $da
526531
// Check if this is an order note and if user owns the order.
527532
if ( $data instanceof \WP_Comment && 'order_note' === $data->comment_type ) {
528533
$order = wc_get_order( $data->comment_post_ID );
529-
534+
530535
// If user is the order owner, make it public.
531-
if ( $order && get_current_user_id() === $order->get_customer_id() ) {
532-
return 'public';
536+
if ( $order && ! is_bool( $order ) && is_a( $order, \WC_Order::class ) ) {
537+
return get_current_user_id() === $order->get_customer_id() ? 'public' : $visibility;
538+
} else if ( $order && ! is_bool( $order ) && is_a( $order, \WC_Order_Refund::class ) ) {
539+
/** @var \WC_Order|false $parent */
540+
$parent = wc_get_order( $order->get_parent_id() );
541+
return $parent && get_current_user_id() === $parent->get_customer_id() ? 'public' : $visibility;
533542
}
534543
}
535544

includes/data/connection/class-product-connection-resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public function sanitize_input_fields( array $where_args ) {
491491
$term_taxonomy_ids = [];
492492
foreach ( $terms as $term_slug ) {
493493
$term = get_term_by( 'slug', $term_slug, $taxonomy );
494-
if ( ! $term || is_wp_error( $term ) ) {
494+
if ( ! $term ) {
495495
continue;
496496
}
497497
$term_taxonomy_ids[] = $term->term_taxonomy_id;

includes/data/loader/class-wc-cart-item-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Cart_Item_Loader
1515
*/
1616
class WC_Cart_Item_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Cart_Item_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'CART_ITEM' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'CART_ITEM' );
24+
}
25+
}

includes/data/loader/class-wc-downloadable-item-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Downloadable_Item_Loader
1515
*/
1616
class WC_Downloadable_Item_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Downloadable_Item_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'DOWNLOADABLE_ITEM' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'DOWNLOADABLE_ITEM' );
24+
}
25+
}

includes/data/loader/class-wc-order-item-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Order_Item_Loader
1515
*/
1616
class WC_Order_Item_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Order_Item_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'ORDER_ITEM' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'ORDER_ITEM' );
24+
}
25+
}

includes/data/loader/class-wc-shipping-method-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Shipping_Method_Loader
1515
*/
1616
class WC_Shipping_Method_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Shipping_Method_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'SHIPPING_METHOD' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'SHIPPING_METHOD' );
24+
}
25+
}

includes/data/loader/class-wc-shipping-zone-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Shipping_Zone_Loader
1515
*/
1616
class WC_Shipping_Zone_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Shipping_Zone_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'SHIPPING_ZONE' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'SHIPPING_ZONE' );
24+
}
25+
}

includes/data/loader/class-wc-tax-class-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Tax_Class_Loader
1515
*/
1616
class WC_Tax_Class_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Tax_Class_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'TAX_CLASS' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'TAX_CLASS' );
24+
}
25+
}

includes/data/loader/class-wc-tax-rate-loader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* Class WC_Tax_Rate_Loader
1515
*/
1616
class WC_Tax_Rate_Loader extends WC_Db_Loader {
17-
/**
17+
/**
1818
* WC_Tax_Rate_Loader constructor
1919
*
2020
* @param \WPGraphQL\AppContext $context AppContext instance.
2121
*/
22-
public function __construct( $context ) {
23-
parent::__construct( $context, 'TAX_RATE' );
24-
}
25-
}
22+
public function __construct( $context ) {
23+
parent::__construct( $context, 'TAX_RATE' );
24+
}
25+
}

0 commit comments

Comments
 (0)