Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
fix(Code Quality): Updates for code quality
Browse files Browse the repository at this point in the history
- Updates linting configuration.
- Updates unit tests to pass linting testings.
- Updates unit testing to use new Dev Container & Docker setup.
- Fixes linting issues.
  • Loading branch information
timnolte committed Apr 27, 2024
1 parent 5590047 commit ec6661e
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh",

// Use 'postStartCommand' to run commands after the container has started.
"postStartCommand": "cd /app && wp plugin activate woocommerce-local-pickup-time-select",
"postStartCommand": "cd /app && wp --quiet plugin activate woocommerce-local-pickup-time-select",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "wp_php",
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fi

if wp core is-installed 2>/dev/null; then
echo "Activating required development plugins.."
wp plugin activate \
wp --quiet plugin activate \
action-scheduler \
debug-bar \
debug-bar-actions-and-filters-addon \
Expand All @@ -57,8 +57,8 @@ if wp core is-installed 2>/dev/null; then
wordpress-importer \
wp-mail-logging

echo "Activating required development plugins.."
wp theme activate storefront
echo "Activating required development theme.."
wp --quiet theme activate storefront
fi

echo "Done!"
32 changes: 8 additions & 24 deletions admin/class-local-pickup-time-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private function __construct() {
add_action( 'init', array( $this, 'register_post_status' ) );
add_filter( 'wc_order_statuses', array( $this, 'wc_order_statuses' ), 10, 1 );
add_filter( 'bulk_actions-edit-shop_order', array( $this, 'add_bulk_actions_edit_shop_order' ), 50, 1 );
add_action( 'woocommerce_email_actions', array( $this, 'woocommerce_email_actions' ) );
add_action( 'woocommerce_email_classes', array( $this, 'woocommerce_email_classes' ) );
add_filter( 'woocommerce_email_actions', array( $this, 'woocommerce_email_actions' ) );
add_filter( 'woocommerce_email_classes', array( $this, 'woocommerce_email_classes' ) );

/*
* Show Pickup Time in the Order Details in the Admin Screen
Expand All @@ -82,9 +82,8 @@ private function __construct() {
*/
add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_orders_list_pickup_date_column_header' ) );
add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_orders_list_pickup_date_column_content' ) );
add_action( 'manage_edit-shop_order_sortable_columns', array( $this, 'add_orders_list_pickup_date_column_sorting' ) );
add_action( 'pre_get_posts', array( $this, 'filter_orders_list_by_pickup_date' ) );

add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'add_orders_list_pickup_date_column_sorting' ) );
add_filter( 'pre_get_posts', array( $this, 'filter_orders_list_by_pickup_date' ) );
}

/**
Expand Down Expand Up @@ -122,7 +121,6 @@ public function plugin_action_links( $actions ) {
array_unshift( $actions, $settings_link );

return $actions;

}

/**
Expand All @@ -141,7 +139,6 @@ public function plugin_add_settings_section( $sections ) {
$sections[ $this->plugin->get_plugin_slug() ] = __( 'Local Pickup Time settings', 'woocommerce-local-pickup-time-select' );

return $sections;

}

/**
Expand Down Expand Up @@ -424,7 +421,6 @@ public function plugin_settings( $settings, $current_section ) {
}

return $settings;

}

/**
Expand All @@ -447,7 +443,6 @@ public function shipping_methods_settings_override( $shipping_methods ) {
}

return $shipping_methods;

}

/**
Expand All @@ -472,7 +467,6 @@ public function shipping_instance_form_add_extra_fields( $fields ) {
);

return $fields;

}

/**
Expand All @@ -496,7 +490,6 @@ public function shipping_method_add_rate_pickup_time_args( $args, $shipping_meth
}

return $args;

}

/**
Expand Down Expand Up @@ -535,7 +528,6 @@ public function wc_order_statuses( $order_statuses ) {
$order_statuses['wc-ready-for-pickup'] = _x( 'Ready for Pickup', 'Order status', 'woocommerce-local-pickup-time-select' );

return $order_statuses;

}

/**
Expand All @@ -552,7 +544,6 @@ public function add_bulk_actions_edit_shop_order( $actions ) {
$actions['mark_ready-for-pickup'] = __( 'Change status to ready for pickup', 'woocommerce-local-pickup-time-select' );

return $actions;

}

/**
Expand All @@ -569,7 +560,6 @@ public function woocommerce_email_actions( $email_actions ) {
$email_actions[] = 'woocommerce_order_status_ready-for-pickup';

return $email_actions;

}

/**
Expand All @@ -586,7 +576,6 @@ public function woocommerce_email_classes( $email_classes ) {
$email_classes['WC_Email_Customer_Ready_For_Pickup_Order'] = include __DIR__ . '/emails/class-wc-email-customer-ready-for-pickup-order.php';

return $email_classes;

}

/**
Expand All @@ -601,15 +590,17 @@ public function woocommerce_email_classes( $email_classes ) {
public function show_metabox( $order ) {

$order_meta = get_post_custom( $order->get_id() );
$pickup_time = $order_meta[ $this->plugin->get_order_meta_key() ][0];
$pickup_time = '';
if ( is_array( $order_meta ) ) {
$pickup_time = $order_meta[ $this->plugin->get_order_meta_key() ][0];
}

$allowed_html = array(
'p' => array(),
'strong' => array(),
);

echo wp_kses( '<p><strong>' . __( 'Pickup Time:', 'woocommerce-local-pickup-time-select' ) . '</strong> ' . esc_html( $this->pickup_time_select_translatable( $pickup_time ) ) . '</p>', $allowed_html );

}

/**
Expand All @@ -634,7 +625,6 @@ public function add_orders_list_pickup_date_column_header( $columns ) {
}

return $new_columns;

}

/**
Expand All @@ -653,7 +643,6 @@ public function add_orders_list_pickup_date_column_content( $column ) {
if ( $this->plugin->get_order_meta_key() === $column ) {
echo esc_html( $this->pickup_time_select_translatable( $the_order->get_meta( $this->plugin->get_order_meta_key() ) ) );
}

}

/**
Expand All @@ -670,7 +659,6 @@ public function add_orders_list_pickup_date_column_sorting( $columns ) {
$new_columns[ $this->plugin->get_order_meta_key() ] = 'pickup_time';

return wp_parse_args( $new_columns, $columns );

}

/**
Expand All @@ -691,7 +679,6 @@ public function filter_orders_list_by_pickup_date( $query ) {
}

return $query;

}

/**
Expand All @@ -705,7 +692,6 @@ public function filter_orders_list_by_pickup_date( $query ) {
public function woocommerce_admin_order_preview_get_order_details( $order_details ) {

return $order_details;

}

/**
Expand All @@ -723,7 +709,5 @@ public function pickup_time_select_translatable( $value ) {

// Call the Public plugin instance of this method to reduce code redundancy.
return $plugin->pickup_time_select_translatable( $value );

}

}
16 changes: 7 additions & 9 deletions admin/emails/class-wc-email-customer-ready-for-pickup-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,26 @@ public function __construct() {
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param object|WC_Order|string $order Order object.
* @param int $order_id The order ID.
* @param object|WC_Order|null $order Order object.
*
* @return void
*/
public function trigger( $order_id, $order = '' ) {
public function trigger( $order_id, $order = null ) {
$this->setup_locale();

if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
if ( ! empty( $order_id ) && empty( $order ) ) {
$order = wc_get_order( $order_id );
}

/* @phpstan-ignore-next-line */
if ( is_a( $order, 'WC_Order' ) ) {
if ( ! empty( $order ) && is_object( $order ) && is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $this->object->get_billing_email();
/* @phpstan-ignore-next-line */
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_date}'] = ! empty( $this->object->get_date_created() ) ? wc_format_datetime( $this->object->get_date_created() ) : 'Unknown';
$this->placeholders['{order_number}'] = $this->object->get_order_number();
}

if ( $this->is_enabled() && $this->get_recipient() ) {
if ( is_object( $order ) && $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}

Expand Down
55 changes: 27 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,36 @@
},
"require-dev": {
"php": ">=7.4",
"brain/monkey": "^2.6",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"johnpbloch/wordpress-core": "~6.2.0",
"johnpbloch/wordpress-core-installer": "^2.0",
"mockery/mockery": "^1.5",
"php-stubs/woocommerce-stubs": "~6.5.0",
"php-stubs/wordpress-stubs": "~6.2.0",
"phpro/grumphp": "^1.16",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^9.6.0",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.7",
"szepeviktor/phpstan-wordpress": "^1.3",
"brain/monkey": "^2.6",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"johnpbloch/wordpress-core": "~6.5.0",
"johnpbloch/wordpress-core-installer": "^2.0",
"mockery/mockery": "^1.5",
"php-stubs/woocommerce-stubs": "~8.7.0",
"php-stubs/wordpress-stubs": "~6.5.0",
"phpro/grumphp": "^1.16",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^9.6.0",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.7",
"szepeviktor/phpstan-wordpress": "^1.3",
"woocommerce/action-scheduler": "^3.5.0",
"woocommerce/woocommerce-sniffs": "^1.0.0",
"wp-coding-standards/wpcs": "^3.0.0",
"wp-phpunit/wp-phpunit": "~6.2.0",
"wpackagist-plugin/debug-bar": "*",
"wpackagist-plugin/debug-bar-actions-and-filters-addon": "*",
"wpackagist-plugin/display-environment-type": "*",
"wpackagist-plugin/health-check": "*",
"wpackagist-plugin/query-monitor": "*",
"wpackagist-plugin/transients-manager": "*",
"wpackagist-plugin/woo-order-test": "*",
"wpackagist-plugin/woocommerce": "~6.5.0",
"wp-coding-standards/wpcs": "^3.0.0",
"wp-phpunit/wp-phpunit": "~6.5.0",
"wpackagist-plugin/debug-bar": "*",
"wpackagist-plugin/debug-bar-actions-and-filters-addon": "*",
"wpackagist-plugin/display-environment-type": "*",
"wpackagist-plugin/health-check": "*",
"wpackagist-plugin/query-monitor": "*",
"wpackagist-plugin/transients-manager": "*",
"wpackagist-plugin/woo-order-test": "*",
"wpackagist-plugin/woocommerce": "~8.7.0",
"wpackagist-plugin/wordpress-importer": "*",
"wpackagist-plugin/wp-mail-logging": "*",
"wpackagist-theme/storefront": "*",
"yoast/phpunit-polyfills": "^2.0"
"wpackagist-theme/storefront": "*",
"yoast/phpunit-polyfills": "^2.0"
},
"autoload": {
"classmap": [
Expand Down
Loading

0 comments on commit ec6661e

Please sign in to comment.