Skip to content

Commit

Permalink
chore: Linter and compliance met
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 17, 2024
1 parent d5f21de commit d503527
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function get_query() {
/** @var \WC_Shipping_Zone $rest_of_the_world */
$rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 );


$zones = \WC_Shipping_Zones::get_zones();
array_unshift( $zones, $rest_of_the_world->get_data() );

Expand Down
22 changes: 11 additions & 11 deletions includes/data/mutation/class-settings-mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static function validate_setting_text_field( $value, $setting ) {
*
* @param string $value Value.
* @param array $setting Setting.
*
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
*
* @return string
*/
public static function validate_setting_select_field( $value, $setting ) {
Expand All @@ -49,9 +49,9 @@ public static function validate_setting_select_field( $value, $setting ) {
*
* @param array $values Values.
* @param array $setting Setting.
*
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
*
* @return array
*/
public static function validate_setting_multiselect_field( $values, $setting ) {
Expand All @@ -78,9 +78,9 @@ public static function validate_setting_multiselect_field( $values, $setting ) {
*
* @param array $values Values.
* @param array $setting Setting.
*
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
*
* @return string
*/
public static function validate_setting_image_width_field( $values, $setting ) {
Expand All @@ -106,9 +106,9 @@ public static function validate_setting_image_width_field( $values, $setting ) {
*
* @param string $value Value.
* @param array $setting Setting.
*
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
*
* @return string
*/
public static function validate_setting_radio_field( $value, $setting ) {
Expand All @@ -120,9 +120,9 @@ public static function validate_setting_radio_field( $value, $setting ) {
*
* @param string $value Value.
* @param array $setting Setting.
*
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
*
* @return string
*/
public function validate_setting_checkbox_field( $value, $setting ) {
Expand All @@ -141,7 +141,7 @@ public function validate_setting_checkbox_field( $value, $setting ) {
*
* @param string $value Value.
* @param array $setting Setting.
*
*
* @return string
*/
public static function validate_setting_textarea_field( $value, $setting ) {
Expand Down
10 changes: 5 additions & 5 deletions includes/data/mutation/class-shipping-mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Shipping_Mutation {
* Maps the settings input for insertion.
*
* @param array<array<string, string>> $settings_input Settings input.
*
*
* @return array<string, string>
*/
private static function flatten_settings_input( $settings_input ) {
Expand All @@ -33,7 +33,7 @@ private static function flatten_settings_input( $settings_input ) {
* @param int $instance_id Instance ID.
* @param \WC_Shipping_Method $method Shipping method data.
* @param array $settings_input Settings input.
*
*
* @return \WC_Shipping_Method
*/
public static function set_shipping_zone_method_settings( $instance_id, $method, $settings_input ) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public static function set_shipping_zone_method_settings( $instance_id, $method,
* @param int $instance_id Instance ID.
* @param \WC_Shipping_Method $method Shipping method data.
* @param int $order Order.
*
*
* @return \WC_Shipping_Method
*/
public static function set_shipping_zone_method_order( $instance_id, $method, $order ) {
Expand All @@ -80,7 +80,7 @@ public static function set_shipping_zone_method_order( $instance_id, $method, $o
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
"{$wpdb->prefix}woocommerce_shipping_zone_methods",
[ 'method_order' => $order ],
[ 'instance_id' => $instance_id ]
[ 'instance_id' => $instance_id ]
);
$method->method_order = $order;

Expand All @@ -94,7 +94,7 @@ public static function set_shipping_zone_method_order( $instance_id, $method, $o
* @param int $instance_id Instance ID.
* @param \WC_Shipping_Method $method Shipping method data.
* @param bool $enabled Enabled status.
*
*
* @return \WC_Shipping_Method
*/
public static function set_shipping_zone_method_enabled( $zone_id, $instance_id, $method, $enabled ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/model/class-shipping-zone.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Model - Shipping_Zone
*
*
* This model represents a Shipping Zone.
*
*
* @package WPGraphQL\WooCommerce\Model
* @since TBD
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-shipping-zone-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function mutate_and_get_payload() {

$zone = new \WC_Shipping_Zone( null );
$zone->set_zone_name( $input['name'] );

if ( ! empty( $input['order'] ) ) {
$zone->set_zone_order( $input['order'] );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-shipping-zone-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function mutate_and_get_payload() {
if ( ! \wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
throw new UserError( __( 'Sorry, you are not allowed to delete shipping zones', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
}

$zone_id = $input['id'];
/** @var \WC_Shipping_Zone|false $zone */
$zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id );
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-shipping-zone-method-add.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function get_output_fields() {
'resolve' => static function ( $payload, array $args, AppContext $context ) {
return [
// Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value.
'node' => new Shipping_Method( $payload['method'] ),
'node' => new Shipping_Method( $payload['method'] ),
'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ),
];
},
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-shipping-zone-method-remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function get_output_fields() {
'resolve' => static function ( $payload, array $args, AppContext $context ) {
return [
// Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value.
'node' => new Shipping_Method( $payload['method'] ),
'node' => new Shipping_Method( $payload['method'] ),
'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ),
];
},
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-shipping-zone-method-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function get_output_fields() {
'resolve' => static function ( $payload, array $args, AppContext $context ) {
return [
// Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value.
'node' => new Shipping_Method( $payload['method'] ),
'node' => new Shipping_Method( $payload['method'] ),
'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ),
];
},
Expand Down
6 changes: 3 additions & 3 deletions includes/mutation/class-tax-class-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function get_output_fields() {
public static function mutate_and_get_payload() {
return static function ( $input, AppContext $context, ResolveInfo $info ) {
if ( ! \wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
throw new UserError( __( "Sorry, you are not allowed to create tax classes.", 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
throw new UserError( __( 'Sorry, you are not allowed to create tax classes.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
}
$name = $input['name'];
$slug = ! empty( $input['slug'] ) ? $input['slug'] : '';
Expand All @@ -90,8 +90,8 @@ public static function mutate_and_get_payload() {
/**
* Filter tax class object before responding.
*
* @param object $tax_class The shipping method object.
* @param array $input Request input.
* @param array $tax_class The shipping method object.
* @param array $input Request input.
*/
$tax_class = apply_filters( 'graphql_woocommerce_tax_class_create', $tax_class, $input );

Expand Down
11 changes: 6 additions & 5 deletions includes/mutation/class-tax-class-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public static function get_output_fields() {
public static function mutate_and_get_payload() {
return static function ( $input, AppContext $context, ResolveInfo $info ) {
if ( ! \wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
throw new UserError( __( "Sorry, you are not allowed to delete tax classes.", 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
throw new UserError( __( 'Sorry, you are not allowed to delete tax classes.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
}
$slug = $input['slug'];
/** @var array|false $tax_class */
$tax_class = \WC_Tax::get_tax_class_by( 'slug', $slug );
if ( ! $tax_class ) {
throw new UserError( __( 'Invalid tax class slug.', 'wp-graphql-woocommerce' ) );
Expand All @@ -83,8 +84,8 @@ public static function mutate_and_get_payload() {
/**
* Action hook before deleting tax class.
*
* @param object $tax_class The tax class object.
* @param array $input Request input.
* @param array $tax_class The tax class object.
* @param array $input Request input.
*/
do_action( 'graphql_woocommerce_before_tax_class_delete', $tax_class, $input );

Expand All @@ -96,8 +97,8 @@ public static function mutate_and_get_payload() {
/**
* Filter tax class object before responding.
*
* @param object $tax_class The shipping method object.
* @param array $input Request input.
* @param array $tax_class The shipping method object.
* @param array $input Request input.
*/
$tax_class = apply_filters( 'graphql_woocommerce_tax_class_delete', $tax_class, $input );

Expand Down
15 changes: 11 additions & 4 deletions includes/mutation/class-tax-rate-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace WPGraphQL\WooCommerce\Mutation;

use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use WPGraphQL\AppContext;

Expand Down Expand Up @@ -120,12 +121,19 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso
$action = ! $id ? 'create' : 'update';
$permission = ! $id ? 'create' : 'edit';
if ( ! \wc_rest_check_manager_permissions( 'settings', $permission ) ) {
throw new UserError( __( "Sorry, you are not allowed to {$permission} tax rates.", 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
throw new UserError(
sprintf(
/* translators: %s: permission */
__( 'Sorry, you are not allowed to %s tax rates.', 'wp-graphql-woocommerce' ),
$permission
),
\rest_authorization_required_code()
);
}

$current = null;
if ( ! empty( $id ) ) {
/**
/**
* @var object{
* tax_rate_id: int,
* tax_rate_class: string,
Expand Down Expand Up @@ -206,7 +214,6 @@ public static function mutate_and_get_payload( $input, AppContext $context, Reso
\WC_Tax::_update_tax_rate_postcodes( $id, join( ';', $input['postcodes'] ) );
}


/**
* Filter tax rate object before responding.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/mutation/class-tax-rate-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function mutate_and_get_payload() {
* @param object $tax_rate The shipping method object.
* @param array $input Request input.
*/
$tax = apply_filters( "graphql_woocommerce_tax_rate_delete", $tax, $input );
$tax = apply_filters( 'graphql_woocommerce_tax_rate_delete', $tax, $input );

return [
'taxRate' => $tax,
Expand Down
4 changes: 2 additions & 2 deletions includes/type/object/class-root-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public static function register_fields() {
if ( ! \wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) {
throw new UserError( __( 'Sorry, you cannot view shipping methods.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
}

$id = isset( $args['id'] ) ? $args['id'] : null;
$id_type = isset( $args['idType'] ) ? $args['idType'] : 'global_id';

Expand Down Expand Up @@ -455,7 +455,7 @@ public static function register_fields() {
if ( ! \wc_shipping_enabled() ) {
throw new UserError( __( 'Shipping is disabled.', 'wp-graphql-woocommerce' ), 404 );
}

if ( ! \wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
throw new UserError( __( 'Permission denied.', 'wp-graphql-woocommerce' ), \rest_authorization_required_code() );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/type/object/class-shipping-zone-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function register() {
$default_value = ! empty( $field['default'] ) ? $field['default'] : null;
$value = ! empty( $instance_settings[ $key ] ) ? $instance_settings[ $key ] : $default_value;
$settings[] = array_merge(
$field,
$field,
[
'id' => $key,
'value' => $value,
Expand Down

0 comments on commit d503527

Please sign in to comment.