Skip to content

Commit

Permalink
fix: clean up unnecessary variables and ternaries
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Jul 11, 2023
1 parent 6a57a81 commit 36ad4ba
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 40 deletions.
6 changes: 3 additions & 3 deletions includes/admin/class-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function get_fields() {
. ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
'type' => 'checkbox',
'value' => defined( 'NO_QL_SESSION_HANDLER' ) ? 'on' : woographql_setting( 'disable_ql_session_handler', 'off' ),
'disabled' => defined( 'NO_QL_SESSION_HANDLER' ) ? true : false,
'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
],
[
'name' => 'enable_unsupported_product_type',
Expand All @@ -101,8 +101,8 @@ public static function get_fields() {
]
),
'value' => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ),
'disabled' => $enable_auth_urls_hardcoded ? true : false,
'sanitize_callback' => function( $value ) {
'disabled' => $enable_auth_urls_hardcoded,
'sanitize_callback' => static function( $value ) {
if ( empty( $value ) ) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public static function bypass_get_args_sanitization( $args, $connection_resolver
* @return PostObjectConnectionResolver
*/
public static function set_ordering_query_args( $resolver, $args ) {
$backward = isset( $args['last'] ) ? true : false;
$backward = isset( $args['last'] );

if ( ! empty( $args['where']['orderby'] ) ) {
$default_fields = [
Expand Down
2 changes: 1 addition & 1 deletion includes/connection/class-wc-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function register_connections() {
$wc_post_types = WP_GraphQL_WooCommerce::get_post_types();

// Loop through the allowed_taxonomies to register appropriate connections.
foreach ( $allowed_taxonomies as $taxonomy => $tax_object ) {
foreach ( $allowed_taxonomies as $tax_object ) {
foreach ( $wc_post_types as $post_type ) {
if ( 'product' === $post_type ) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public function get_query() {
* {@inheritDoc}
*/
public function get_ids_from_query() {
$ids = ! empty( $this->query ) ? $this->query : [];

return $ids;
return ! empty( $this->query ) ? $this->query : [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ public function get_query() {
* @return array
*/
public function get_ids_from_query() {
$ids = ! empty( $this->query ) ? $this->query : [];

return $ids;
return ! empty( $this->query ) ? $this->query : [];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function get_query() {
}//end switch

$items = [];
foreach ( $this->source->get_items( $type ) as $id => $item ) {
foreach ( $this->source->get_items( $type ) as $item ) {
$items[] = $item;
}

Expand Down
3 changes: 1 addition & 2 deletions includes/data/mutation/class-order-mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ protected static function get_order_item_keys( $type ) {
* @param array $item_keys Order item keys.
* @param string $type Order item type slug.
*/
$item_keys = apply_filters( 'woographql_get_order_item_keys', [], $type );
return $item_keys;
return apply_filters( 'woographql_get_order_item_keys', [], $type );
}//end switch
}

Expand Down
6 changes: 3 additions & 3 deletions includes/model/class-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ protected function owner_matches_current_user() {
}

// If customer ID matches current user, return true.
return absint( $customer_id ) === absint( $this->current_user->ID ) ? true : false;
return absint( $customer_id ) === absint( $this->current_user->ID );
}

/**
Expand Down Expand Up @@ -328,7 +328,7 @@ public function guest_order_customer_matches_current_user() {
}

// If customer email matches current user, return true.
return $customer_email === $session_customer->get_billing_email() ? true : false;
return $customer_email === $session_customer->get_billing_email();
}

/**
Expand All @@ -337,7 +337,7 @@ public function guest_order_customer_matches_current_user() {
* @return bool
*/
public function is_private() {
return wc_is_order_status( 'wc-' . $this->data->get_status() ) ? false : true;
return ! wc_is_order_status( 'wc-' . $this->data->get_status() );
}

/**
Expand Down
4 changes: 1 addition & 3 deletions includes/mutation/class-cart-add-fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function register_mutation() {
* @return array
*/
public static function get_input_fields() {
$input_fields = [
return [
'name' => [
'type' => [ 'non_null' => 'String' ],
'description' => __( 'Unique name for the fee.', 'wp-graphql-woocommerce' ),
Expand All @@ -60,8 +60,6 @@ public static function get_input_fields() {
'description' => __( 'The tax class for the fee if taxable.', 'wp-graphql-woocommerce' ),
],
];

return $input_fields;
}

/**
Expand Down
6 changes: 2 additions & 4 deletions includes/mutation/class-cart-add-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ public static function get_output_fields() {
return [
'cartItem' => [
'type' => 'CartItem',
'resolve' => function ( $payload ) {
$item = \WC()->cart->get_cart_item( $payload['key'] );

return $item;
'resolve' => static function ( $payload ) {
return \WC()->cart->get_cart_item( $payload['key'] );
},
],
'cart' => Cart_Mutation::get_cart_field( true ),
Expand Down
4 changes: 1 addition & 3 deletions includes/mutation/class-order-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function register_mutation() {
* @return array
*/
public static function get_input_fields() {
$input_fields = [
return [
'parentId' => [
'type' => 'Int',
'description' => __( 'Parent order ID.', 'wp-graphql-woocommerce' ),
Expand Down Expand Up @@ -111,8 +111,6 @@ public static function get_input_fields() {
'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ),
],
];

return $input_fields;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/mutation/class-order-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public static function mutate_and_get_payload() {
// Actions for after the order is saved.
if ( true === $input['isPaid'] ) {
$order->payment_complete(
! empty( $input['transactionId'] ) ?
$input['transactionId']
! empty( $input['transactionId'] )
? $input['transactionId']
: ''
);
}
Expand Down
6 changes: 2 additions & 4 deletions includes/type/object/class-customer-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ public static function register() {
'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ),
'resolve' => function( $source ) {
if ( get_current_user_id() === $source->ID ) {
$tokens = array_filter(
return array_filter(
array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ),
function ( $token ) {
return 'CC' === $token->get_type();
}
);
return $tokens;
}

throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) );
Expand All @@ -256,13 +255,12 @@ function ( $token ) {
'description' => __( 'Customer\'s stored payment tokens.', 'wp-graphql-woocommerce' ),
'resolve' => function( $source ) {
if ( get_current_user_id() === $source->ID ) {
$tokens = array_filter(
return array_filter(
array_values( \WC_Payment_Tokens::get_customer_tokens( $source->ID ) ),
function ( $token ) {
return 'eCheck' === $token->get_type();
}
);
return $tokens;
}

throw new UserError( __( 'Not authorized to view this user\'s payment methods.', 'wp-graphql-woocommerce' ) );
Expand Down
2 changes: 1 addition & 1 deletion includes/type/object/class-meta-data-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function get_metadata_field_definition() {
],
'resolve' => function( $source, array $args ) {
// Set unique flag.
$single = ! empty( $args['multiple'] ) ? false : true;
$single = empty( $args['multiple'] );

// Check "key" argument and format meta_data objects.
if ( ! empty( $args['key'] ) && $source->meta_exists( $args['key'] ) ) {
Expand Down
4 changes: 1 addition & 3 deletions includes/type/object/class-root-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ public static function register_fields() {
throw new UserError( sprintf( __( 'No product exists with the %1$s: %2$s', 'wp-graphql-woocommerce' ), $id_type, $product_id ) );
}

$product = Factory::resolve_crud_object( $product_id, $context );

return $product;
return Factory::resolve_crud_object( $product_id, $context );
},
]
);
Expand Down
4 changes: 1 addition & 3 deletions includes/utils/class-transfer-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ public function get_client_session_id() {
return $client_session_id;
}

$client_session_id = '';

return $client_session_id;
return '';
}
}

0 comments on commit 36ad4ba

Please sign in to comment.