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 2a80adf
Show file tree
Hide file tree
Showing 23 changed files with 259 additions and 490 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!"
2 changes: 1 addition & 1 deletion .github/workflows/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
- 'fix/**'

env:
ACTION_VERSION: 3
WP_MULTISITE: 0
ACTION_VERSION: 2

jobs:
check_i18n:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
- 'fix/**'

env:
PHP_VERSION: '7.4'
ACTION_VERSION: 3
PHP_VERSION: '8.1'
COMPOSER_VERSION: '2.5'
WP_MULTISITE: 0
COMPOSER_VERSION: '2.2'
ACTION_VERSION: 2

jobs:
check_linting:
Expand Down
22 changes: 6 additions & 16 deletions .github/workflows/pr-unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
pull_request:

env:
PHP_VERSION: '7.4'
WP_VERSION: '5.9.*'
ACTION_VERSION: 4
PHP_VERSION: '8.1'
COMPOSER_VERSION: '2.5'
WP_VERSION: '6.5.*'
WP_MULTISITE: 0
WC_VERSION: '6.4.*'
COMPOSER_VERSION: '2.2'
ACTION_VERSION: 3
WC_VERSION: '8.7.*'

jobs:
pr_unit_testing:
Expand Down Expand Up @@ -41,13 +41,6 @@ jobs:
restore-keys: |
${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ env.WP_VERSION }}-wc-${{ env.WC_VERSION }}-v${{ env.ACTION_VERSION }}-
- name: Setup Node Environment
# https://github.com/marketplace/actions/setup-node-js-environment
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'
cache: ${{ !env.ACT && 'npm' || '' }}

- name: Setup PHP & Composer Environment
# https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
Expand All @@ -64,8 +57,5 @@ jobs:
- name: Install Composer Dependencies
run: composer install --prefer-dist

- name: NPM Setup
run: npm ci

- name: Unit Tests
run: npm run test
run: composer test
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
types: [published]

env:
ACTION_VERSION: 3
WP_MULTISITE: 0
ACTION_VERSION: 2

jobs:
release:
Expand All @@ -21,10 +21,11 @@ jobs:
uses: actions/checkout@v2

- name: Setup Node Environment
uses: actions/setup-node@v1
# https://github.com/marketplace/actions/setup-node-js-environment
uses: actions/setup-node@v2
with:
node-version: 14.x
node-version-file: '.nvmrc'
cache: ${{ !env.ACT && 'npm' || '' }}

- name: Get NPM Cache Directory
id: npm-cache
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
- 'fix/**'

env:
PHP_VERSION: '7.4'
ACTION_VERSION: 3
PHP_VERSION: '8.1'
COMPOSER_VERSION: '2.5'
WP_MULTISITE: 0
COMPOSER_VERSION: '2.2'
ACTION_VERSION: 2

jobs:
check_static_analysis:
Expand Down Expand Up @@ -57,4 +57,4 @@ jobs:
run: composer install

- name: Perform Static Analysis
run: composer run-script analyze
run: composer analyze
30 changes: 10 additions & 20 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- 'release/**'

env:
COMPOSER_VERSION: '2.2'
ACTION_VERSION: 3
ACTION_VERSION: 4
COMPOSER_VERSION: '2.5'

jobs:
matrix_unit_testing:
Expand All @@ -21,24 +21,24 @@ jobs:
fail-fast: false
matrix:
job-name: ['Unit Test']
php-version: ['7.4','8.0']
wordpress-version: ['5.7.*','5.8.*','5.9.*']
woocommerce-version: ['4.*','5.0.*','5.*','6.0.*','6.4.*']
php-version: ['7.4','8.0','8.1']
wordpress-version: ['5.9.*','6.4.*','6.5.*']
woocommerce-version: ['4.*','5.*','6.*','7.*','8.*']
wp-multisite-mode: [0]
bleeding-edge: [false]
include:
- job-name: 'Unit Test Bleeding Edge Requirements'
bleeding-edge: true
php-version: '8.1'
php-version: '8.3'
wordpress-version: 'dev-master'
wp-multisite-mode: 0
woocommerce-version: 'dev-trunk'
- job-name: 'Unit Test Multisite Compatibility Requirements'
bleeding-edge: false
php-version: '8.0'
wordpress-version: '5.9.*'
php-version: '8.1'
wordpress-version: '6.5.*'
wp-multisite-mode: 1
woocommerce-version: '6.4.*'
woocommerce-version: '8.7.*'

name: '${{ matrix.job-name }} (PHP:${{ matrix.php-version }}/WP:${{ matrix.wordpress-version }}/WC:${{ matrix.woocommerce-version }})'

Expand All @@ -63,13 +63,6 @@ jobs:
restore-keys: |
${{ runner.os }}-build-${{ env.composer-cache-name }}-wp-${{ matrix.wordpress-version }}-wc-${{ matrix.woocommerce-version }}-v${{ env.ACTION_VERSION }}-
- name: Setup Node Environment
# https://github.com/marketplace/actions/setup-node-js-environment
uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'
cache: ${{ !env.ACT && 'npm' || '' }}

- name: Setup PHP & Composer Environment
# https://github.com/marketplace/actions/setup-php-action
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -110,10 +103,7 @@ jobs:
if: matrix.php-version != '8.0' && matrix.php-version != '8.1'
run: composer install --prefer-dist

- name: NPM Setup
run: npm ci

- name: Unit Tests
env:
WP_MULTISITE: ${{ matrix.wp-multisite-mode }}
run: npm run test
run: composer test
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 );

}

}
Loading

0 comments on commit 2a80adf

Please sign in to comment.