Skip to content

Commit 47c5552

Browse files
committed
chore: linter compliances met
1 parent 7c10a3d commit 47c5552

File tree

8 files changed

+48
-22
lines changed

8 files changed

+48
-22
lines changed

includes/data/mutation/class-order-mutation.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class Order_Mutation {
2323
* @param \WPGraphQL\AppContext $context AppContext instance.
2424
* @param \GraphQL\Type\Definition\ResolveInfo $info ResolveInfo instance.
2525
* @param string $mutation Mutation being executed.
26-
* @param integer|null $order_id Order ID.
27-
*
26+
* @param integer|null|false $order_id Order ID.
27+
* @throws \GraphQL\Error\UserError Error locating order.
28+
*
2829
* @return boolean
2930
*/
3031
public static function authorized( $input, $context, $info, $mutation = 'create', $order_id = null ) {
@@ -35,21 +36,35 @@ public static function authorized( $input, $context, $info, $mutation = 'create'
3536
*/
3637
$post_type_object = get_post_type_object( 'shop_order' );
3738

38-
if ( $order_id === null ) {
39+
if ( ! $order_id ) {
3940
return apply_filters(
4041
"graphql_woocommerce_authorized_to_{$mutation}_orders",
41-
current_user_can($post_type_object->cap->edit_posts),
42+
current_user_can( $post_type_object->cap->edit_posts ),
4243
$order_id,
4344
$input,
4445
$context,
4546
$info
4647
);
4748
}
4849

49-
$order = \wc_get_order( $order_id );
50+
/** @var false|\WC_Order $order */
51+
$order = \wc_get_order( $order_id );
52+
if ( false === $order ) {
53+
throw new UserError(
54+
sprintf(
55+
/* translators: %d: Order ID */
56+
__( 'Failed to find order with ID of %d.', 'wp-graphql-woocommerce' ),
57+
$order_id
58+
)
59+
);
60+
}
61+
5062
$post_type = get_post_type( $order_id );
63+
if ( false === $post_type ) {
64+
throw new UserError( __( 'Failed to identify the post type of the order.', 'wp-graphql-woocommerce' ) );
65+
}
5166

52-
// Return true if user is owner or admin
67+
// Return true if user is owner or admin.
5368
$is_owner = 0 !== get_current_user_id() && $order->get_customer_id() === get_current_user_id();
5469
$is_admin = \wc_rest_check_post_permissions( $post_type, 'edit', $order_id );
5570
return $is_owner || $is_admin;

includes/mutation/class-coupon-create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use GraphQL\Error\UserError;
1414
use GraphQL\Type\Definition\ResolveInfo;
1515
use WPGraphQL\AppContext;
16+
use WPGraphQL\Utils\Utils;
1617
use WPGraphQL\WooCommerce\Data\Mutation\Coupon_Mutation;
1718
use WPGraphQL\WooCommerce\Model\Coupon;
18-
use WPGraphQL\Utils\Utils;
1919

2020
/**
2121
* Class Coupon_Create
@@ -163,7 +163,7 @@ public static function get_output_fields() {
163163
*/
164164
public static function mutate_and_get_payload( $input, AppContext $context, ResolveInfo $info ) {
165165
// Retrieve order ID.
166-
if ( ! empty ( $input['id'] ) ) {
166+
if ( ! empty( $input['id'] ) ) {
167167
$coupon_id = Utils::get_database_id_from_id( $input['id'] );
168168
} else {
169169
$coupon_id = 0;

includes/mutation/class-coupon-delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use GraphQL\Error\UserError;
1414
use GraphQL\Type\Definition\ResolveInfo;
1515
use WPGraphQL\AppContext;
16-
use WPGraphQL\WooCommerce\Model\Coupon;
1716
use WPGraphQL\Utils\Utils;
17+
use WPGraphQL\WooCommerce\Model\Coupon;
1818

1919
/**
2020
* Class Coupon_Delete

includes/mutation/class-order-delete-items.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use GraphQL\Error\UserError;
1414
use GraphQL\Type\Definition\ResolveInfo;
1515
use WPGraphQL\AppContext;
16+
use WPGraphQL\Utils\Utils;
1617
use WPGraphQL\WooCommerce\Data\Mutation\Order_Mutation;
1718
use WPGraphQL\WooCommerce\Model\Order;
18-
use WPGraphQL\Utils\Utils;
1919

2020
/**
2121
* Class Order_Delete_Items
@@ -45,11 +45,11 @@ public static function register_mutation() {
4545
public static function get_input_fields() {
4646
return array_merge(
4747
[
48-
'id' => [
48+
'id' => [
4949
'type' => 'ID',
5050
'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ),
5151
],
52-
'orderId' => [
52+
'orderId' => [
5353
'type' => 'Int',
5454
'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ),
5555
'deprecationReason' => __( 'Use "id" field instead.', 'wp-graphql-woocommerce' ),
@@ -95,6 +95,10 @@ public static function mutate_and_get_payload() {
9595
throw new UserError( __( 'Order ID provided is missing or invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
9696
}
9797

98+
if ( ! $order_id ) {
99+
throw new UserError( __( 'Order ID provided is invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
100+
}
101+
98102
// Check if authorized to delete items on this order.
99103
if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete-items', $order_id ) ) {
100104
throw new UserError( __( 'User does not have the capabilities necessary to delete order items.', 'wp-graphql-woocommerce' ) );

includes/mutation/class-order-delete.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use GraphQL\Type\Definition\ResolveInfo;
1515
use WC_Order_Factory;
1616
use WPGraphQL\AppContext;
17+
use WPGraphQL\Utils\Utils;
1718
use WPGraphQL\WooCommerce\Data\Mutation\Order_Mutation;
1819
use WPGraphQL\WooCommerce\Model\Order;
19-
use WPGraphQL\Utils\Utils;
2020

2121
/**
2222
* Class Order_Delete
@@ -87,7 +87,7 @@ public static function get_output_fields() {
8787
public static function mutate_and_get_payload() {
8888
return static function ( $input, AppContext $context, ResolveInfo $info ) {
8989
// Retrieve order ID.
90-
$order_id = null;
90+
$order_id = false;
9191
if ( ! empty( $input['id'] ) ) {
9292
$order_id = Utils::get_database_id_from_id( $input['id'] );
9393
} elseif ( ! empty( $input['orderId'] ) ) {
@@ -96,6 +96,10 @@ public static function mutate_and_get_payload() {
9696
throw new UserError( __( 'Order ID provided is missing or invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
9797
}
9898

99+
if ( ! $order_id ) {
100+
throw new UserError( __( 'Order ID provided is invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
101+
}
102+
99103
// Check if authorized to delete this order.
100104
if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete', $order_id ) ) {
101105
throw new UserError( __( 'User does not have the capabilities necessary to delete an order.', 'wp-graphql-woocommerce' ) );

includes/mutation/class-order-update.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use GraphQL\Type\Definition\ResolveInfo;
1515
use WC_Order_Factory;
1616
use WPGraphQL\AppContext;
17+
use WPGraphQL\Utils\Utils;
1718
use WPGraphQL\WooCommerce\Data\Mutation\Order_Mutation;
1819
use WPGraphQL\WooCommerce\Model\Order;
19-
use WPGraphQL\Utils\Utils;
2020

2121
/**
2222
* Class Order_Update
@@ -51,7 +51,7 @@ public static function get_input_fields() {
5151
'type' => 'ID',
5252
'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ),
5353
],
54-
'orderId' => [
54+
'orderId' => [
5555
'type' => 'Int',
5656
'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ),
5757
'deprecationReason' => __( 'Use "id" field instead.', 'wp-graphql-woocommerce' ),
@@ -96,7 +96,11 @@ public static function mutate_and_get_payload() {
9696
} else {
9797
throw new UserError( __( 'Order ID provided is missing or invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
9898
}
99-
99+
100+
if ( ! $order_id ) {
101+
throw new UserError( __( 'Order ID provided is invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
102+
}
103+
100104
// Check if authorized to update this order.
101105
if ( ! Order_Mutation::authorized( $input, $context, $info, 'update', $order_id ) ) {
102106
throw new UserError( __( 'User does not have the capabilities necessary to update an order.', 'wp-graphql-woocommerce' ) );

includes/mutation/class-review-update.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use GraphQL\Error\UserError;
1414
use GraphQL\Type\Definition\ResolveInfo;
15-
use GraphQLRelay\Relay;
1615
use WPGraphQL\AppContext;
1716
use WPGraphQL\Mutation\CommentUpdate;
1817
use WPGraphQL\Utils\Utils;
@@ -80,8 +79,8 @@ public static function mutate_and_get_payload() {
8079
'clientMutationId' => 1,
8180
];
8281

83-
$payload = [];
84-
$id = Utils::get_database_id_from_id( $input['id'] );
82+
$payload = [];
83+
$id = Utils::get_database_id_from_id( $input['id'] );
8584
if ( ! $id ) {
8685
throw new UserError( __( 'Provided review ID missing or invalid ', 'wp-graphql-woocommerce' ) );
8786
}

includes/mutation/class-tax-rate-create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static function get_output_fields() {
118118
* @return array
119119
*/
120120
public static function mutate_and_get_payload( $input, AppContext $context, ResolveInfo $info ) {
121-
$id = ! empty( $input['id'] ) ? Utils::get_database_id_from_id( $input['id'] ) : null;
121+
$id = ! empty( $input['id'] ) ? Utils::get_database_id_from_id( $input['id'] ) : null;
122122
if ( false === $id ) {
123123
throw new UserError( __( 'Invalid ID provided.', 'wp-graphql-woocommerce' ) );
124124
}
@@ -221,7 +221,7 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso
221221
/**
222222
* Filter tax rate object before responding.
223223
*
224-
* @param object $tax_rate_id The shipping method object.
224+
* @param int $tax_rate_id The shipping method object.
225225
* @param array $input Request input.
226226
*/
227227
do_action( "graphql_woocommerce_tax_rate_{$action}", $id, $input );

0 commit comments

Comments
 (0)