From 011de4523404670237992f29012a5e06b5439dee Mon Sep 17 00:00:00 2001 From: vendidero Date: Fri, 27 Sep 2024 15:53:00 +0200 Subject: [PATCH] Tests, composer update. Plugin review. --- .gitattributes | 3 +- .gitignore | 1 + assets/css/admin.scss | 50 +++++ assets/js/static/admin-settings.js | 20 +- bin/vendor-clean.sh | 4 + composer.json | 10 +- docker-compose.yml | 2 +- .../views/html-order-shipment-content.php | 2 +- .../admin/views/html-preview-shipment.php | 8 +- .../html-shipment-label-backbone-error.php | 8 - .../class-wc-stc-email-customer-shipment.php | 2 +- includes/wc-stc-shipment-functions.php | 8 +- includes/wc-stc-template-functions.php | 3 +- phpcs.xml | 23 ++- src/Admin/Admin.php | 173 ++++++------------ src/Admin/BulkActionHandler.php | 2 - src/Admin/BulkLabel.php | 3 +- src/Admin/PackagingSettings.php | 4 +- src/Admin/Settings.php | 14 +- src/Admin/Table.php | 30 +-- src/Admin/Tabs/ShippingProvider.php | 2 +- src/Admin/Tabs/Tab.php | 2 +- src/Admin/Tabs/Tabs.php | 2 +- src/Ajax.php | 73 ++++---- src/Api.php | 4 +- src/Automation.php | 12 +- src/Blocks/Checkout.php | 8 +- .../CheckoutPickupLocationSelect.php | 2 +- .../Routes/V1/CartSearchPickupLocations.php | 2 +- src/Blocks/StoreApi/RoutesController.php | 2 +- src/Blocks/StoreApi/StoreApi.php | 2 +- src/Bootstrap.php | 2 +- src/Caches/Helper.php | 4 +- src/Caches/PackagingCache.php | 16 +- src/Caches/ShipmentCache.php | 16 +- src/Caches/ShipmentLabelCache.php | 16 +- src/Caches/ShipmentOrderCache.php | 16 +- src/Caches/ShippingProviderCache.php | 16 +- src/Compatibility/Bundles.php | 2 +- src/DataStores/Label.php | 8 +- src/DataStores/Packaging.php | 8 +- src/DataStores/Shipment.php | 10 +- src/DataStores/ShipmentItem.php | 10 +- src/DataStores/ShippingProvider.php | 10 +- src/FormHandler.php | 2 +- src/Install.php | 6 +- src/Interfaces/Compatibility.php | 5 - src/Interfaces/LabelConfigurationSet.php | 5 - src/Interfaces/ShipmentLabel.php | 5 - src/Interfaces/ShipmentReturnLabel.php | 8 - src/Interfaces/ShippingProvider.php | 10 +- src/Interfaces/ShippingProviderAuto.php | 9 - src/Labels/Automation.php | 2 +- src/Labels/ConfigurationSet.php | 14 +- src/Labels/DownloadHandler.php | 6 +- src/Labels/Factory.php | 4 +- src/Labels/Label.php | 8 +- src/Labels/Query.php | 13 +- src/Order.php | 80 ++++---- src/Orders/Factory.php | 2 +- src/PDFMerger.php | 2 +- src/PDFSplitter.php | 1 - src/Package.php | 4 +- src/Packaging/AsyncReportGenerator.php | 2 +- src/Packaging/Report.php | 8 +- src/Packaging/ReportHelper.php | 20 +- src/PackagingFactory.php | 2 +- src/Packing/Helper.php | 6 +- src/PickupDelivery.php | 6 +- src/Registry/Container.php | 2 +- src/Rest/ShipmentsController.php | 56 +++--- src/SecretBox.php | 10 +- src/Shipment.php | 10 +- src/ShipmentFactory.php | 4 +- src/ShipmentQuery.php | 13 +- src/ShippingMethod/MethodHelper.php | 8 +- src/ShippingMethod/ShippingMethod.php | 28 ++- src/ShippingProvider/Auto.php | 14 +- src/ShippingProvider/PickupLocation.php | 6 +- src/ShippingProvider/Product.php | 22 +-- src/ShippingProvider/Simple.php | 19 +- src/Utilities/NumberUtil.php | 2 +- src/Validation.php | 10 +- ...customer-guest-return-shipment-request.php | 2 +- .../customer-return-shipment-delivered.php | 2 +- templates/emails/customer-return-shipment.php | 2 +- templates/emails/customer-shipment.php | 6 +- templates/emails/email-order-shipments.php | 2 +- ...customer-guest-return-shipment-request.php | 2 +- .../customer-return-shipment-delivered.php | 2 +- .../emails/plain/customer-return-shipment.php | 3 +- templates/emails/plain/customer-shipment.php | 6 +- .../emails/plain/email-order-shipments.php | 2 +- templates/global/empty.php | 2 - templates/global/form-return-request.php | 4 +- tests/Bootstrap.php | 2 +- tests/Framework/UnitTestCase.php | 3 + tests/bin/install.sh | 4 +- tests/unit-tests/units.php | 104 +++++++++++ 99 files changed, 634 insertions(+), 563 deletions(-) create mode 100644 tests/unit-tests/units.php diff --git a/.gitattributes b/.gitattributes index 06493318..e66a9324 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,9 +3,10 @@ /node_modules* export-ignore /tests export-ignore /bin export-ignore -/composer.* export-ignore +/composer-lock.* export-ignore /phpcs.xml export-ignore /phpunit.* export-ignore +/.phpunit.* export-ignore /renovate.json export-ignore /package.json export-ignore /webpack.config.js export-ignore diff --git a/.gitignore b/.gitignore index aa65fbb4..799075b0 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ Thumbs.db /vendor/composer/* composer.lock +.phpunit.result.cache # Packages /packages/* diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 1b2859e2..00b099d7 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -599,6 +599,56 @@ table.wc-shiptastic-shipping-rules { } } +.wc-shiptastic-create-packaging-report { + margin-bottom: 15px; + padding: 0; + + select { + width: auto !important; + min-width: 120px; + } + + button.button { + height: 34px; + margin-left: 10px; + } +} + +table.packaging_reports_table { + thead { + th { + padding: 10px; + } + td { + padding: 15px 10px; + + .packaging-report-status { + margin-left: 5px; + } + } + } +} + +tbody.packaging_list { + tr td { + padding: .5em; + } + + select { + width: 100% !important; + } + + .input-inner-wrap { + clear: both; + + input.wc_input_decimal { + width: 33% !important; + min-width: auto !important; + float: left !important; + } + } +} + .packaging-report-status { background: #f8dda7; color: #94660c; diff --git a/assets/js/static/admin-settings.js b/assets/js/static/admin-settings.js index 8714176d..8a3305bf 100644 --- a/assets/js/static/admin-settings.js +++ b/assets/js/static/admin-settings.js @@ -11,11 +11,29 @@ window.shiptastic.admin = window.shiptastic.admin || {}; $( document ) .on( 'click', 'a.woocommerce-stc-shipment-input-toggle-trigger', self.onInputToggleClick ) - .on( 'change shiptastic_show_or_hide_fields', 'table.form-table :input[id]', self.onChangeInput ); + .on( 'change shiptastic_show_or_hide_fields', 'table.form-table :input[id]', self.onChangeInput ) + .on( 'click', '.wc_input_table a.add', self.onAddInputRow ); $( 'table.form-table :input[id]' ).trigger( 'shiptastic_show_or_hide_fields' ); }, + onAddInputRow: function() { + var self = shipments.admin.shipment_settings, + $wrapper = $( this ).parents( '.wc_input_table' ), + size = $wrapper.find( 'tbody tr.item:visible' ).length, + $template = $wrapper.find( 'tr.template' ).clone(); + + $template.find( ':input' ).each( function() { + $( this ).attr('name', $( this ).attr( 'name' ).replace( 'size', size ) ); + }); + + $template.appendTo( $wrapper.find( 'tbody' ) ).removeClass( 'template' ).show(); + + $( document.body ).trigger( 'wc-enhanced-select-init' ); + + return false; + }, + getCleanInputId: function( $mainInput ) { var self = shipments.admin.shipment_settings, fieldId = $mainInput.attr( 'id' ) ? $mainInput.attr( 'id' ) : $mainInput.attr( 'name' ); diff --git a/bin/vendor-clean.sh b/bin/vendor-clean.sh index 0ee096e4..b0854659 100755 --- a/bin/vendor-clean.sh +++ b/bin/vendor-clean.sh @@ -28,6 +28,10 @@ fi output 3 "Clean vendor dirs to save space..." rm -rf ./vendor/dvdoug/boxpacker/visualiser/* +rm -rf ./vendor/dvdoug/boxpacker/docs/* +rm -rf ./vendor/dvdoug/boxpacker/features/* rm -rf ./vendor/dvdoug/boxpacker/tests/data/* +rm -rf ./vendor/dvdoug/boxpacker/*.md +rm -rf ./vendor/dvdoug/boxpacker/.github/* output 2 "Done!" \ No newline at end of file diff --git a/composer.json b/composer.json index 39938902..b19ed849 100644 --- a/composer.json +++ b/composer.json @@ -8,21 +8,21 @@ "version": "dev-main", "minimum-stability": "dev", "require": { - "automattic/jetpack-autoloader": "^2.0.0", + "automattic/jetpack-autoloader": "2.11.18", "setasign/fpdi": "^2.3", "setasign/fpdf": "^1.8.2", "dvdoug/boxpacker": "^3.9.0" }, "require-dev": { - "phpunit/phpunit": "7.5.14", - "yoast/phpunit-polyfills": "^1.1.0", - "woocommerce/woocommerce-sniffs": "^0.1.3" + "phpunit/phpunit": "^9.0.0", + "yoast/phpunit-polyfills": "^3.0", + "woocommerce/woocommerce-sniffs": "^1.0.0" }, "config": { "optimize-autoloader": true, "allow-plugins": true, "platform": { - "php": "7.1" + "php": "7.4" }, "preferred-install": "dist", "sort-packages": true diff --git a/docker-compose.yml b/docker-compose.yml index d1cb6645..5aaccfe3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: build: context: ./tests/bin ports: - - 8087:80 + - 8089:80 restart: on-failure environment: WORDPRESS_DB_HOST: diff --git a/includes/admin/views/html-order-shipment-content.php b/includes/admin/views/html-order-shipment-content.php index fe6aaab8..0d00024d 100644 --- a/includes/admin/views/html-order-shipment-content.php +++ b/includes/admin/views/html-order-shipment-content.php @@ -262,7 +262,7 @@ is_editable() ) : ?> - get_type() ) ) ); ?> + get_type() ) ) ); ?>

- get_type() ) ), esc_html( $position_number ), esc_html( $total_shipments ) ); ?> + get_type() ) ), esc_html( $position_number ), esc_html( $total_shipments ) ); ?> get_order() ) && is_callable( array( $s_order, 'get_edit_order_url' ) ) ) : ?> - get_order_number() ) ); ?> + get_order_number() ) ); ?> - get_order_number() ) ); ?> + get_order_number() ) ); ?>

@@ -34,7 +34,7 @@ if ( ! empty( $provider ) && ! empty( $tracking_id ) ) : ?>

- + has_tracking() && ( $tracking_url = $shipment->get_tracking_url() ) ) : ?> diff --git a/includes/admin/views/label/html-shipment-label-backbone-error.php b/includes/admin/views/label/html-shipment-label-backbone-error.php index 6d3be874..a01a7fbf 100644 --- a/includes/admin/views/label/html-shipment-label-backbone-error.php +++ b/includes/admin/views/label/html-shipment-label-backbone-error.php @@ -7,14 +7,6 @@ defined( 'ABSPATH' ) || exit; ?>

-
get_error_messages() as $message ) : ?>
diff --git a/includes/emails/class-wc-stc-email-customer-shipment.php b/includes/emails/class-wc-stc-email-customer-shipment.php index bcd32585..b51e1b28 100644 --- a/includes/emails/class-wc-stc-email-customer-shipment.php +++ b/includes/emails/class-wc-stc-email-customer-shipment.php @@ -191,7 +191,7 @@ public function get_shipped_position_number( $shipment_id ) { foreach ( $order->get_simple_shipments() as $key => $shipment ) { if ( $shipment->is_shipped() ) { if ( (int) $shipment->get_id() !== (int) $shipment_id ) { - $shipped_count++; + ++$shipped_count; } } } diff --git a/includes/wc-stc-shipment-functions.php b/includes/wc-stc-shipment-functions.php index 05614fd5..f39c0e6a 100644 --- a/includes/wc-stc-shipment-functions.php +++ b/includes/wc-stc-shipment-functions.php @@ -1548,12 +1548,12 @@ function wc_stc_get_shipment_error( $error ) { } } -function wc_shiptastic_substring( $string, $start, $length = null ) { +function wc_shiptastic_substring( $str, $start, $length = null ) { if ( function_exists( 'mb_substr' ) ) { - $string = mb_substr( $string, $start, $length ); + $str = mb_substr( $str, $start, $length ); } else { - $string = substr( $string, $start, $length ); + $str = substr( $str, $start, $length ); } - return $string; + return $str; } diff --git a/includes/wc-stc-template-functions.php b/includes/wc-stc-template-functions.php index 026bce84..6dc6d7fc 100644 --- a/includes/wc-stc-template-functions.php +++ b/includes/wc-stc-template-functions.php @@ -141,7 +141,6 @@ function woocommerce_shiptastic_template_view_shipment( $shipment_id ) { if ( ! function_exists( 'woocommerce_shiptastic_template_add_return_shipment' ) ) { function woocommerce_shiptastic_template_add_return_shipment( $order_id ) { - if ( ( ! ( $order = wc_get_order( $order_id ) ) ) || ( ! wc_stc_customer_can_add_return_shipment( $order_id ) ) ) { echo '
' . esc_html_x( 'Invalid order.', 'shipments', 'shiptastic-for-woocommerce' ) . ' ' . esc_html_x( 'My account', 'shipments', 'shiptastic-for-woocommerce' ) . '
'; return; @@ -156,7 +155,7 @@ function woocommerce_shiptastic_template_add_return_shipment( $order_id ) { // Output notices in case notices have not been outputted yet. if ( ! empty( $notices ) ) { - echo '
' . $notices . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '
' . wc_kses_notice( $notices ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } wc_get_template( diff --git a/phpcs.xml b/phpcs.xml index 11c241ca..ce9a9ef8 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -104,7 +104,28 @@ * - + * + + + * + + + + * + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Admin/Admin.php b/src/Admin/Admin.php index bbc43113..b9a5f5cd 100644 --- a/src/Admin/Admin.php +++ b/src/Admin/Admin.php @@ -85,7 +85,7 @@ public static function init() { add_action( 'admin_init', - function() { + function () { // Order shipping status add_filter( 'manage_' . ( 'shop_order' === self::get_order_screen_id() ? 'shop_order_posts' : self::get_order_screen_id() ) . '_columns', array( __CLASS__, 'register_order_shipping_status_column' ), 20 ); add_action( 'manage_' . ( 'shop_order' === self::get_order_screen_id() ? 'shop_order_posts' : self::get_order_screen_id() ) . '_custom_column', array( __CLASS__, 'render_order_columns' ), 20, 2 ); @@ -603,7 +603,7 @@ public static function render_packaging_page() {

-

+

@@ -616,7 +616,7 @@ public static function hide_packaging_page_from_menu() { } public static function save_packaging_page() { - if ( ! current_user_can( 'manage_woocommerce' ) || ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['_wpnonce'] ), 'woocommerce-stc-packaging-settings' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( ! current_user_can( 'manage_woocommerce' ) || ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['_wpnonce'] ) ), 'woocommerce-stc-packaging-settings' ) ) { wp_die( '', 400 ); } @@ -913,7 +913,7 @@ protected static function add_settings_after( $settings, $id, $insert = array(), $key = self::get_setting_key_by_id( $settings, $id, $type ); if ( is_numeric( $key ) ) { - $key ++; + ++$key; $settings = array_merge( array_merge( array_slice( $settings, 0, $key, true ), $insert ), array_slice( $settings, $key, count( $settings ) - 1, true ) ); } else { $settings += $insert; @@ -1151,41 +1151,31 @@ public static function output_return_reasons_field( $value ) { - - - - '; - } + $count = 0; + foreach ( wc_stc_get_return_shipment_reasons() as $reason ) : + ?> + + + + + + + + + + +
- -
@@ -1414,7 +1364,7 @@ public static function output_packaging_list( $value ) { @@ -1422,51 +1372,34 @@ public static function output_packaging_list( $value ) { + + + + + + + + + + + + + + + + + + + + +
- wc_stc_get_packaging_types(), + ); if ( self::is_shipping_settings_request() ) { $params['clean_input_callback'] = 'shiptastic.admin.shipping_provider_method.getCleanInputId'; diff --git a/src/Admin/BulkActionHandler.php b/src/Admin/BulkActionHandler.php index 0a5e18b2..853e7806 100644 --- a/src/Admin/BulkActionHandler.php +++ b/src/Admin/BulkActionHandler.php @@ -81,11 +81,9 @@ public function get_success_message() { } public function admin_handled() { - } public function admin_after_error() { - } public function add_notice( $notice, $type = 'error' ) { diff --git a/src/Admin/BulkLabel.php b/src/Admin/BulkLabel.php index 06450b6a..f10bd017 100644 --- a/src/Admin/BulkLabel.php +++ b/src/Admin/BulkLabel.php @@ -75,7 +75,6 @@ protected function get_download_button() { $download_button = ''; if ( ( $path = $this->get_file() ) && file_exists( $path ) ) { - $download_url = add_query_arg( array( 'action' => 'wc-stc-download-export-shipment-label', @@ -94,7 +93,7 @@ public function get_success_message() { $download_button = $this->get_download_button(); if ( empty( $download_button ) ) { - return sprintf( _x( 'The chosen shipments were not suitable for automatic label creation. Please check the shipping provider option of the corresponding shipments.', 'shipments', 'shiptastic-for-woocommerce' ), $download_button ); + return sprintf( _x( 'The chosen shipments were not suitable for automatic label creation. Please check the shipping provider option of the corresponding shipments.', 'shipments', 'shiptastic-for-woocommerce' ), $download_button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { return sprintf( _x( 'Successfully generated labels. %s', 'shipments', 'shiptastic-for-woocommerce' ), $download_button ); } diff --git a/src/Admin/PackagingSettings.php b/src/Admin/PackagingSettings.php index f5faad76..bfe62d87 100644 --- a/src/Admin/PackagingSettings.php +++ b/src/Admin/PackagingSettings.php @@ -264,7 +264,7 @@ public static function save_settings( $packaging, $tab, $section = '' ) { add_filter( 'woocommerce_admin_settings_sanitize_option', - function( $value, $setting, $raw_value ) use ( $packaging ) { + function ( $value, $setting, $raw_value ) use ( $packaging ) { $setting_id = $setting['id']; $args = $packaging->get_configuration_set_args_by_id( $setting_id ); $value = wc_clean( $value ); @@ -289,7 +289,7 @@ function( $value, $setting, $raw_value ) use ( $packaging ) { } else { add_filter( 'pre_update_option', - function( $value, $option, $old_value ) use ( $packaging ) { + function ( $value, $option, $old_value ) use ( $packaging ) { if ( is_callable( array( $packaging, "set_{$option}" ) ) ) { $setter = "set_{$option}"; diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index f4600f5a..352dab28 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -152,7 +152,7 @@ public static function get_sanitized_settings( $settings, $data = null ) { return $settings_to_save; } - public static function render_label_fields( $settings, $shipment, $echo = false ) { + public static function render_label_fields( $settings, $shipment, $do_echo = false ) { $missing_div_closes = 0; ob_start(); foreach ( $settings as $setting ) { @@ -198,7 +198,7 @@ public static function render_label_fields( $settings, $shipment, $echo = false woocommerce_wp_text_input( $setting ); } elseif ( 'services_start' === $setting['type'] ) { $hide_default = isset( $setting['hide_default'] ) ? wc_string_to_bool( $setting['hide_default'] ) : false; - $missing_div_closes++; + ++$missing_div_closes; ?>

@@ -211,17 +211,17 @@ public static function render_label_fields( $settings, $shipment, $echo = false

0 ) { while ( $missing_div_closes > 0 ) { - $missing_div_closes--; + --$missing_div_closes; echo '
'; } } $html = ob_get_clean(); - if ( ! $echo ) { + if ( ! $do_echo ) { return $html; } else { echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped diff --git a/src/Admin/Table.php b/src/Admin/Table.php index 78365cb5..07aefbd0 100644 --- a/src/Admin/Table.php +++ b/src/Admin/Table.php @@ -120,7 +120,7 @@ public function handle_bulk_actions( $action, $ids, $redirect_to ) { * @package Vendidero/Shiptastic */ do_action( 'woocommerce_shiptastic_shipment_edit_status', $id, $new_status ); - $changed++; + ++$changed; } } } @@ -128,7 +128,7 @@ public function handle_bulk_actions( $action, $ids, $redirect_to ) { foreach ( $ids as $id ) { if ( $shipment = wc_stc_get_shipment( $id ) ) { $shipment->delete( true ); - $changed++; + ++$changed; } } } elseif ( 'confirm_requests' === $action ) { @@ -137,7 +137,7 @@ public function handle_bulk_actions( $action, $ids, $redirect_to ) { if ( 'return' === $shipment->get_type() ) { if ( $shipment->is_customer_requested() && $shipment->has_status( 'requested' ) ) { if ( $shipment->confirm_customer_request() ) { - $changed++; + ++$changed; } } } @@ -375,7 +375,6 @@ public function no_items() { /** * Determine if the current view is the "All" view. * - * * @return bool Whether the current view is the "All" view. */ protected function is_base_request() { @@ -434,8 +433,15 @@ protected function get_views() { 'shipment_status' => $status, ); + $label = array( + 'singular' => sprintf( '%s (%s)', esc_html( $title ), $num_shipments[ $status ] ), + 'plural' => sprintf( '%s (%s)', esc_html( $title ), $num_shipments[ $status ] ), + 'context' => '', + 'domain' => 'shiptastic-for-woocommerce', + ); + $status_label = sprintf( - translate_nooped_plural( _nx_noop( ( $title . ' (%s)' ), ( $title . ' (%s)' ), 'shipments', 'shiptastic-for-woocommerce' ), $num_shipments[ $status ] ), // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingle,WordPress.WP.I18n.NonSingularStringLiteralPlural + translate_nooped_plural( $label, $num_shipments[ $status ] ), // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingular, WordPress.WP.I18n.NonSingularStringLiteralPlural number_format_i18n( $num_shipments[ $status ] ) ); @@ -451,20 +457,21 @@ protected function get_views() { * * @param string[] $args Associative array of URL parameters for the link. * @param string $label Link text. - * @param string $class Optional. Class attribute. Default empty string. + * @param string $class_name Optional. Class attribute. Default empty string. + * * @return string The formatted link string. */ - protected function get_edit_link( $args, $label, $class = '' ) { + protected function get_edit_link( $args, $label, $class_name = '' ) { $url = add_query_arg( $args, $this->get_main_page() ); $class_html = $aria_current = ''; - if ( ! empty( $class ) ) { + if ( ! empty( $class_name ) ) { $class_html = sprintf( ' class="%s"', - esc_attr( $class ) + esc_attr( $class_name ) ); - if ( 'current' === $class ) { + if ( 'current' === $class_name ) { $aria_current = ' aria-current="page"'; } } @@ -686,7 +693,7 @@ protected function order_filter() { } ?> get_hook_prefix()}bulk_actions", $actions ); } - } diff --git a/src/Admin/Tabs/ShippingProvider.php b/src/Admin/Tabs/ShippingProvider.php index 2283579b..c14bfc42 100644 --- a/src/Admin/Tabs/ShippingProvider.php +++ b/src/Admin/Tabs/ShippingProvider.php @@ -180,7 +180,7 @@ public function get_next_pointers_link( $provider_name = false ) { if ( is_a( $provider, '\Vendidero\Shiptastic\ShippingProvider\Auto' ) && ! empty( $provider->get_settings_help_pointers() ) ) { $provider_indexes[ $provider_key ] = $count; $provider_counts[ $count ] = $provider_key; - $count++; + ++$count; } } diff --git a/src/Admin/Tabs/Tab.php b/src/Admin/Tabs/Tab.php index 27cae372..4fe92ff8 100644 --- a/src/Admin/Tabs/Tab.php +++ b/src/Admin/Tabs/Tab.php @@ -52,7 +52,7 @@ public function header() { $count = 0; foreach ( $breadcrumb as $breadcrumb_item ) { - $count ++; + ++$count; echo '
'; } diff --git a/src/Admin/Tabs/Tabs.php b/src/Admin/Tabs/Tabs.php index 4128eab0..0c125566 100644 --- a/src/Admin/Tabs/Tabs.php +++ b/src/Admin/Tabs/Tabs.php @@ -44,7 +44,7 @@ public function header() {
    diff --git a/src/Ajax.php b/src/Ajax.php index 6c20ee0c..c21f9c26 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -59,8 +59,11 @@ public static function add_ajax_events() { } public static function suppress_errors() { + /** + * Turn off display_errors during AJAX events to prevent malformed JSON. + */ if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { - @ini_set( 'display_errors', 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.PHP.IniSet.display_errors_Blacklisted + @ini_set( 'display_errors', 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.IniSet.display_errors_Disallowed } $GLOBALS['wpdb']->hide_errors(); @@ -92,8 +95,7 @@ public static function send_return_shipment_notification_email() { if ( isset( $_GET['shipment_id'] ) ) { wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=wc-stc-return-shipments' ) ); exit; - } else { - if ( $success ) { + } elseif ( $success ) { wp_send_json( array( 'success' => true, @@ -102,16 +104,15 @@ public static function send_return_shipment_notification_email() { ), ) ); - } else { - wp_send_json( - array( - 'success' => false, - 'messages' => array( - _x( 'There was an error while sending the notification.', 'shipments', 'shiptastic-for-woocommerce' ), - ), - ) - ); - } + } else { + wp_send_json( + array( + 'success' => false, + 'messages' => array( + _x( 'There was an error while sending the notification.', 'shipments', 'shiptastic-for-woocommerce' ), + ), + ) + ); } } } @@ -143,8 +144,7 @@ public static function confirm_return_request() { if ( isset( $_GET['shipment_id'] ) ) { wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=wc-stc-return-shipments' ) ); exit; - } else { - if ( $success ) { + } elseif ( $success ) { wp_send_json( array( 'success' => true, @@ -158,16 +158,15 @@ public static function confirm_return_request() { ), ) ); - } else { - wp_send_json( - array( - 'success' => false, - 'messages' => array( - _x( 'There was an error while confirming the request.', 'shipments', 'shiptastic-for-woocommerce' ), - ), - ) - ); - } + } else { + wp_send_json( + array( + 'success' => false, + 'messages' => array( + _x( 'There was an error while confirming the request.', 'shipments', 'shiptastic-for-woocommerce' ), + ), + ) + ); } } } @@ -638,7 +637,7 @@ public static function update_shipment_status() { private static function get_shipment_ids( $shipments ) { return array_values( array_map( - function( $s ) { + function ( $s ) { return $s->get_id(); }, $shipments @@ -748,7 +747,7 @@ public static function add_shipment() { $shipment_count = 0; foreach ( $shipments as $id => $shipment ) { - $shipment_count++; + ++$shipment_count; $shipment_type = $shipment->get_type(); if ( 1 === $shipment_count ) { @@ -986,19 +985,17 @@ public static function json_search_orders() { if ( Package::is_hpos_enabled() ) { $ids = wc_get_orders( array( 's' => $term ) ); - } else { - if ( ! is_numeric( $term ) ) { + } elseif ( ! is_numeric( $term ) ) { $ids = wc_get_orders( array( 's' => $term ) ); - } else { - global $wpdb; + } else { + global $wpdb; - $ids = $wpdb->get_col( - $wpdb->prepare( - "SELECT DISTINCT p1.ID FROM {$wpdb->posts} p1 WHERE p1.ID LIKE %s AND post_type = 'shop_order'", // @codingStandardsIgnoreLine - $wpdb->esc_like( wc_clean( $term ) ) . '%' - ) - ); - } + $ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT DISTINCT p1.ID FROM {$wpdb->posts} p1 WHERE p1.ID LIKE %s AND post_type = 'shop_order'", // @codingStandardsIgnoreLine + $wpdb->esc_like( wc_clean( $term ) ) . '%' + ) + ); } $excluded = array(); diff --git a/src/Api.php b/src/Api.php index 2309d15b..50843564 100644 --- a/src/Api.php +++ b/src/Api.php @@ -30,8 +30,8 @@ public static function init() { add_filter( 'woocommerce_rest_prepare_product_variation_object', array( __CLASS__, 'prepare_product' ), 10, 3 ); } - public static function prepare_product( $response, $object, $request ) { - if ( $product = wc_get_product( $object ) ) { + public static function prepare_product( $response, $product_object, $request ) { + if ( $product = wc_get_product( $product_object ) ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $response->set_data( array_merge_recursive( $response->data, self::get_product_data( $product, $context ) ) ); diff --git a/src/Automation.php b/src/Automation.php index 2163c30a..c8fe6b8e 100644 --- a/src/Automation.php +++ b/src/Automation.php @@ -33,7 +33,7 @@ public static function init() { */ add_action( 'woocommerce_new_order', - function( $order_id ) { + function ( $order_id ) { self::$current_new_order_id = $order_id; add_action( 'woocommerce_after_order_object_save', array( __CLASS__, 'after_new_order' ), 150 ); }, @@ -278,13 +278,12 @@ public static function maybe_create_shipments( $order_id, $args = array() ) { if ( self::is_admin_edit_order_request() ) { add_action( 'woocommerce_process_shop_order_meta', - function( $order_id ) { + function ( $order_id ) { self::create_shipments( $order_id ); }, 70 ); - } else { - if ( $args['allow_deferred_sync'] ) { + } elseif ( $args['allow_deferred_sync'] ) { Package::log( 'Deferring order #' . $order_id . ' shipments sync' ); $queue = WC()->queue(); @@ -303,9 +302,8 @@ function( $order_id ) { $defer_args, 'woocommerce-shiptastic-order-sync' ); - } else { - self::create_shipments( $order_id ); - } + } else { + self::create_shipments( $order_id ); } } } diff --git a/src/Blocks/Checkout.php b/src/Blocks/Checkout.php index af9a6c98..ec1b9b74 100644 --- a/src/Blocks/Checkout.php +++ b/src/Blocks/Checkout.php @@ -28,7 +28,7 @@ public function __construct( $schema_controller ) { private function register_validation_and_storage() { add_action( 'woocommerce_store_api_checkout_update_order_from_request', - function( $order, $request ) { + function ( $order, $request ) { $this->validate_checkout_data( $order, $request ); }, 10, @@ -161,7 +161,7 @@ private function validate_checkout_data( $order, $request ) { private function register_integrations() { add_action( 'woocommerce_blocks_checkout_block_registration', - function( $integration_registry ) { + function ( $integration_registry ) { $integration_registry->register( Package::container()->get( Integrations\CheckoutPickupLocationSelect::class ) ); } ); @@ -179,7 +179,7 @@ private function register_endpoint_data() { array( 'endpoint' => CartSchema::IDENTIFIER, 'namespace' => 'woocommerce-shiptastic', - 'data_callback' => function() { + 'data_callback' => function () { return $this->get_cart_data(); }, 'schema_callback' => function () { @@ -282,7 +282,7 @@ private function get_cart_data() { 'default_pickup_location' => WC()->customer->get_meta( 'pickup_location_code' ), 'default_pickup_location_customer_number' => WC()->customer->get_meta( 'pickup_location_customer_number' ), 'pickup_locations' => array_map( - function( $location ) { + function ( $location ) { return $location->get_data(); }, $locations diff --git a/src/Blocks/Integrations/CheckoutPickupLocationSelect.php b/src/Blocks/Integrations/CheckoutPickupLocationSelect.php index 115cfbe6..08424a59 100644 --- a/src/Blocks/Integrations/CheckoutPickupLocationSelect.php +++ b/src/Blocks/Integrations/CheckoutPickupLocationSelect.php @@ -38,7 +38,7 @@ public function initialize() { add_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_after', - function() { + function () { wp_enqueue_style( 'wc-shiptastic-checkout-pickup-location-select-block' ); wp_enqueue_style( 'wc-shiptastic-checkout' ); } diff --git a/src/Blocks/StoreApi/Routes/V1/CartSearchPickupLocations.php b/src/Blocks/StoreApi/Routes/V1/CartSearchPickupLocations.php index 436baeb0..9dae9889 100644 --- a/src/Blocks/StoreApi/Routes/V1/CartSearchPickupLocations.php +++ b/src/Blocks/StoreApi/Routes/V1/CartSearchPickupLocations.php @@ -100,7 +100,7 @@ protected function get_route_post_response( \WP_REST_Request $request ) { $result = new \stdClass(); $result->pickup_locations = array_map( - function( $location ) { + function ( $location ) { return $location->get_data(); }, $results['locations'] diff --git a/src/Blocks/StoreApi/RoutesController.php b/src/Blocks/StoreApi/RoutesController.php index 6a12bc32..161a9fc4 100644 --- a/src/Blocks/StoreApi/RoutesController.php +++ b/src/Blocks/StoreApi/RoutesController.php @@ -77,7 +77,7 @@ public function get( $name, $version = 'v1' ) { * @param string $version API Version being registered.. * @param string $namespace Overrides the default route namespace. */ - protected function register_routes( $version = 'v1', $namespace = 'wc/store/v1' ) { + protected function register_routes( $version = 'v1', $namespace = 'wc/store/v1' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound if ( ! isset( $this->routes[ $version ] ) ) { return; } diff --git a/src/Blocks/StoreApi/StoreApi.php b/src/Blocks/StoreApi/StoreApi.php index 33ea2254..4aab15db 100644 --- a/src/Blocks/StoreApi/StoreApi.php +++ b/src/Blocks/StoreApi/StoreApi.php @@ -13,7 +13,7 @@ final class StoreApi { public function init() { add_action( 'rest_api_init', - function() { + function () { Package::container()->get( RoutesController::class )->register_all_routes(); } ); diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 5775bf0b..293318e7 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -57,7 +57,7 @@ protected function init() { } else { add_action( 'woocommerce_blocks_loaded', - function() { + function () { $this->load_blocks(); } ); diff --git a/src/Caches/Helper.php b/src/Caches/Helper.php index fa788c37..c7c52849 100644 --- a/src/Caches/Helper.php +++ b/src/Caches/Helper.php @@ -16,14 +16,14 @@ class Helper { public static function init() { add_action( 'woocommerce_after_order_object_save', - function( $order_id ) { + function ( $order_id ) { self::flush_order_cache( $order_id ); } ); add_action( 'woocommerce_before_delete_order', - function( $order_id ) { + function ( $order_id ) { self::flush_order_cache( $order_id ); } ); diff --git a/src/Caches/PackagingCache.php b/src/Caches/PackagingCache.php index f2195eaf..36e56e6b 100644 --- a/src/Caches/PackagingCache.php +++ b/src/Caches/PackagingCache.php @@ -22,22 +22,24 @@ public function get_object_type(): string { /** * Get the id of an object to be cached. * - * @param array|object $object The object to be cached. + * @param array|object $cache_object The object to be cached. + * * @return int|string|null The id of the object, or null if it can't be determined. */ - protected function get_object_id( $object ) { - return $object->get_id(); + protected function get_object_id( $cache_object ) { + return $cache_object->get_id(); } /** * Validate an object before caching it. * - * @param array|object $object The object to validate. + * @param array|object $cache_object The object to validate. + * * @return string[]|null An array of error messages, or null if the object is valid. */ - protected function validate( $object ): ?array { - if ( ! $object instanceof Packaging ) { - return array( 'The supplied packaging is not an instance of Packaging, ' . gettype( $object ) ); + protected function validate( $cache_object ): ?array { + if ( ! $cache_object instanceof Packaging ) { + return array( 'The supplied packaging is not an instance of Packaging, ' . gettype( $cache_object ) ); } return null; diff --git a/src/Caches/ShipmentCache.php b/src/Caches/ShipmentCache.php index bbec5ff8..5504f7c8 100644 --- a/src/Caches/ShipmentCache.php +++ b/src/Caches/ShipmentCache.php @@ -22,22 +22,24 @@ public function get_object_type(): string { /** * Get the id of an object to be cached. * - * @param array|object $object The object to be cached. + * @param array|object $cache_object The object to be cached. + * * @return int|string|null The id of the object, or null if it can't be determined. */ - protected function get_object_id( $object ) { - return $object->get_id(); + protected function get_object_id( $cache_object ) { + return $cache_object->get_id(); } /** * Validate an object before caching it. * - * @param array|object $object The object to validate. + * @param array|object $cache_object The object to validate. + * * @return string[]|null An array of error messages, or null if the object is valid. */ - protected function validate( $object ): ?array { - if ( ! $object instanceof Shipment ) { - return array( 'The supplied shipment is not an instance of Shipment, ' . gettype( $object ) ); + protected function validate( $cache_object ): ?array { + if ( ! $cache_object instanceof Shipment ) { + return array( 'The supplied shipment is not an instance of Shipment, ' . gettype( $cache_object ) ); } return null; diff --git a/src/Caches/ShipmentLabelCache.php b/src/Caches/ShipmentLabelCache.php index 71e0c521..05d1d67f 100644 --- a/src/Caches/ShipmentLabelCache.php +++ b/src/Caches/ShipmentLabelCache.php @@ -22,22 +22,24 @@ public function get_object_type(): string { /** * Get the id of an object to be cached. * - * @param array|object $object The object to be cached. + * @param array|object $cache_object The object to be cached. + * * @return int|string|null The id of the object, or null if it can't be determined. */ - protected function get_object_id( $object ) { - return $object->get_id(); + protected function get_object_id( $cache_object ) { + return $cache_object->get_id(); } /** * Validate an object before caching it. * - * @param array|object $object The object to validate. + * @param array|object $cache_object The object to validate. + * * @return string[]|null An array of error messages, or null if the object is valid. */ - protected function validate( $object ): ?array { - if ( ! $object instanceof Label ) { - return array( 'The supplied label is not an instance of Label, ' . gettype( $object ) ); + protected function validate( $cache_object ): ?array { + if ( ! $cache_object instanceof Label ) { + return array( 'The supplied label is not an instance of Label, ' . gettype( $cache_object ) ); } return null; diff --git a/src/Caches/ShipmentOrderCache.php b/src/Caches/ShipmentOrderCache.php index 6f2de4f7..83094f6b 100644 --- a/src/Caches/ShipmentOrderCache.php +++ b/src/Caches/ShipmentOrderCache.php @@ -22,22 +22,24 @@ public function get_object_type(): string { /** * Get the id of an object to be cached. * - * @param array|object $object The object to be cached. + * @param array|object $cache_object The object to be cached. + * * @return int|string|null The id of the object, or null if it can't be determined. */ - protected function get_object_id( $object ) { - return $object->get_id(); + protected function get_object_id( $cache_object ) { + return $cache_object->get_id(); } /** * Validate an object before caching it. * - * @param array|object $object The object to validate. + * @param array|object $cache_object The object to validate. + * * @return string[]|null An array of error messages, or null if the object is valid. */ - protected function validate( $object ): ?array { - if ( ! $object instanceof Order ) { - return array( 'The supplied order is not an instance of Order, ' . gettype( $object ) ); + protected function validate( $cache_object ): ?array { + if ( ! $cache_object instanceof Order ) { + return array( 'The supplied order is not an instance of Order, ' . gettype( $cache_object ) ); } return null; diff --git a/src/Caches/ShippingProviderCache.php b/src/Caches/ShippingProviderCache.php index fd5c0f46..5524e149 100644 --- a/src/Caches/ShippingProviderCache.php +++ b/src/Caches/ShippingProviderCache.php @@ -22,22 +22,24 @@ public function get_object_type(): string { /** * Get the id of an object to be cached. * - * @param array|object $object The object to be cached. + * @param array|object $cache_object The object to be cached. + * * @return int|string|null The id of the object, or null if it can't be determined. */ - protected function get_object_id( $object ) { - return $object->get_id(); + protected function get_object_id( $cache_object ) { + return $cache_object->get_id(); } /** * Validate an object before caching it. * - * @param array|object $object The object to validate. + * @param array|object $cache_object The object to validate. + * * @return string[]|null An array of error messages, or null if the object is valid. */ - protected function validate( $object ): ?array { - if ( ! $object instanceof ShippingProvider ) { - return array( 'The supplied shipping provider is not an instance of ShippingProvider, ' . gettype( $object ) ); + protected function validate( $cache_object ): ?array { + if ( ! $cache_object instanceof ShippingProvider ) { + return array( 'The supplied shipping provider is not an instance of ShippingProvider, ' . gettype( $cache_object ) ); } return null; diff --git a/src/Compatibility/Bundles.php b/src/Compatibility/Bundles.php index 79e5e219..ba8fb093 100644 --- a/src/Compatibility/Bundles.php +++ b/src/Compatibility/Bundles.php @@ -19,7 +19,7 @@ public static function is_active() { public static function init() { add_action( 'woocommerce_shiptastic_before_prepare_cart_contents', - function() { + function () { self::$cart_bundled_by_map = array(); } ); diff --git a/src/DataStores/Label.php b/src/DataStores/Label.php index 1272aeb3..a9904a5f 100644 --- a/src/DataStores/Label.php +++ b/src/DataStores/Label.php @@ -417,18 +417,18 @@ protected function save_label_data( &$label ) { * * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. * - * @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc). + * @param WC_Data $label The WP_Data object (WC_Coupon for coupons, etc). * @param string $meta_key Meta key to update. * @param mixed $meta_value Value to save. * * * @return bool True if updated/deleted. */ - protected function update_or_delete_meta( $object, $meta_key, $meta_value ) { + protected function update_or_delete_meta( $label, $meta_key, $meta_value ) { if ( in_array( $meta_value, array( array(), '' ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { - $updated = delete_metadata( $this->meta_type, $object->get_id(), $meta_key ); + $updated = delete_metadata( $this->meta_type, $label->get_id(), $meta_key ); } else { - $updated = update_metadata( $this->meta_type, $object->get_id(), $meta_key, $meta_value ); + $updated = update_metadata( $this->meta_type, $label->get_id(), $meta_key, $meta_value ); } return (bool) $updated; diff --git a/src/DataStores/Packaging.php b/src/DataStores/Packaging.php index db615d45..4015434d 100644 --- a/src/DataStores/Packaging.php +++ b/src/DataStores/Packaging.php @@ -368,18 +368,18 @@ protected function save_packaging_data( &$packaging ) { * * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. * - * @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc). + * @param WC_Data $packaging The WP_Data object (WC_Coupon for coupons, etc). * @param string $meta_key Meta key to update. * @param mixed $meta_value Value to save. * * * @return bool True if updated/deleted. */ - protected function update_or_delete_meta( $object, $meta_key, $meta_value ) { + protected function update_or_delete_meta( $packaging, $meta_key, $meta_value ) { if ( in_array( $meta_value, array( array(), '' ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { - $updated = delete_metadata( $this->meta_type, $object->get_id(), $meta_key ); + $updated = delete_metadata( $this->meta_type, $packaging->get_id(), $meta_key ); } else { - $updated = update_metadata( $this->meta_type, $object->get_id(), $meta_key, $meta_value ); + $updated = update_metadata( $this->meta_type, $packaging->get_id(), $meta_key, $meta_value ); } return (bool) $updated; diff --git a/src/DataStores/Shipment.php b/src/DataStores/Shipment.php index 78e07954..8ebc5db4 100644 --- a/src/DataStores/Shipment.php +++ b/src/DataStores/Shipment.php @@ -508,18 +508,18 @@ protected function save_shipment_data( &$shipment ) { * * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. * - * @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc). + * @param WC_Data $shipment The WP_Data object (WC_Coupon for coupons, etc). * @param string $meta_key Meta key to update. * @param mixed $meta_value Value to save. * * * @return bool True if updated/deleted. */ - protected function update_or_delete_meta( $object, $meta_key, $meta_value ) { + protected function update_or_delete_meta( $shipment, $meta_key, $meta_value ) { if ( in_array( $meta_value, array( array(), '' ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { - $updated = delete_metadata( 'stc_shipment', $object->get_id(), $meta_key ); + $updated = delete_metadata( 'stc_shipment', $shipment->get_id(), $meta_key ); } else { - $updated = update_metadata( 'stc_shipment', $object->get_id(), $meta_key, $meta_value ); + $updated = update_metadata( 'stc_shipment', $shipment->get_id(), $meta_key, $meta_value ); } return (bool) $updated; @@ -560,7 +560,7 @@ public function read_items( $shipment ) { $shipment_type = $shipment->get_type(); $items = array_map( - function( $item_id ) use ( $shipment_type, $shipment ) { + function ( $item_id ) use ( $shipment_type, $shipment ) { $item = wc_stc_get_shipment_item( $item_id, $shipment_type ); if ( $item ) { diff --git a/src/DataStores/ShipmentItem.php b/src/DataStores/ShipmentItem.php index 0c8cdafc..c679bab0 100644 --- a/src/DataStores/ShipmentItem.php +++ b/src/DataStores/ShipmentItem.php @@ -234,18 +234,18 @@ protected function read_item_data( &$item ) { * * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. * - * @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc). + * @param WC_Data $shipment_item The WP_Data object (WC_Coupon for coupons, etc). * @param string $meta_key Meta key to update. * @param mixed $meta_value Value to save. * * * @return bool True if updated/deleted. */ - protected function update_or_delete_meta( $object, $meta_key, $meta_value ) { + protected function update_or_delete_meta( $shipment_item, $meta_key, $meta_value ) { if ( in_array( $meta_value, array( array(), '' ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { - $updated = delete_metadata( $this->meta_type, $object->get_id(), $meta_key ); + $updated = delete_metadata( $this->meta_type, $shipment_item->get_id(), $meta_key ); } else { - $updated = update_metadata( $this->meta_type, $object->get_id(), $meta_key, $meta_value ); + $updated = update_metadata( $this->meta_type, $shipment_item->get_id(), $meta_key, $meta_value ); } return (bool) $updated; @@ -341,7 +341,7 @@ public function read_children( &$item ) { if ( ! empty( $items ) ) { $items = array_map( - function( $item ) { + function ( $item ) { return wc_stc_get_shipment_item( $item->shipment_item_id, $item->shipment_item_type ); }, $items diff --git a/src/DataStores/ShippingProvider.php b/src/DataStores/ShippingProvider.php index 72ba7826..2958efbc 100644 --- a/src/DataStores/ShippingProvider.php +++ b/src/DataStores/ShippingProvider.php @@ -125,7 +125,7 @@ protected function get_unqiue_name( $provider ) { do { $alt_provider_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $provider_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_provider_name, $provider->get_id() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared - $suffix++; + ++$suffix; } while ( $provider_name_check || ( $this->is_manual_creation_request() && $this->is_reserved_name( $alt_provider_name ) ) ); $slug = $alt_provider_name; } @@ -405,18 +405,18 @@ protected function save_provider_data( &$provider ) { * * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. * - * @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc). + * @param WC_Data $shipping_provider The WP_Data object (WC_Coupon for coupons, etc). * @param string $meta_key Meta key to update. * @param mixed $meta_value Value to save. * * * @return bool True if updated/deleted. */ - protected function update_or_delete_meta( $object, $meta_key, $meta_value ) { + protected function update_or_delete_meta( $shipping_provider, $meta_key, $meta_value ) { if ( in_array( $meta_value, array( array(), '' ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { - $updated = delete_metadata( 'stc_shipping_provider', $object->get_id(), $meta_key ); + $updated = delete_metadata( 'stc_shipping_provider', $shipping_provider->get_id(), $meta_key ); } else { - $updated = update_metadata( 'stc_shipping_provider', $object->get_id(), $meta_key, $meta_value ); + $updated = update_metadata( 'stc_shipping_provider', $shipping_provider->get_id(), $meta_key, $meta_value ); } return (bool) $updated; diff --git a/src/FormHandler.php b/src/FormHandler.php index fec2547f..680419d8 100644 --- a/src/FormHandler.php +++ b/src/FormHandler.php @@ -2,7 +2,7 @@ namespace Vendidero\Shiptastic; -use \Exception; +use Exception; use WC_Order; use WP_Query; diff --git a/src/Install.php b/src/Install.php index c9f8f68e..f334b970 100644 --- a/src/Install.php +++ b/src/Install.php @@ -261,15 +261,15 @@ private static function create_upload_dir() { $dir = Package::get_upload_dir(); if ( ! @is_dir( $dir['basedir'] ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - @mkdir( $dir['basedir'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @mkdir( $dir['basedir'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_mkdir } if ( ! file_exists( trailingslashit( $dir['basedir'] ) . '.htaccess' ) ) { - @file_put_contents( trailingslashit( $dir['basedir'] ) . '.htaccess', 'deny from all' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents + @file_put_contents( trailingslashit( $dir['basedir'] ) . '.htaccess', 'deny from all' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents } if ( ! file_exists( trailingslashit( $dir['basedir'] ) . 'index.php' ) ) { - @touch( trailingslashit( $dir['basedir'] ) . 'index.php' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @touch( trailingslashit( $dir['basedir'] ) . 'index.php' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_touch } } diff --git a/src/Interfaces/Compatibility.php b/src/Interfaces/Compatibility.php index 5e3b2e93..bfcb2216 100644 --- a/src/Interfaces/Compatibility.php +++ b/src/Interfaces/Compatibility.php @@ -2,11 +2,6 @@ namespace Vendidero\Shiptastic\Interfaces; -/** - * Compatibility - * - * @version 1.0.0 - */ if ( ! defined( 'ABSPATH' ) ) { exit; } diff --git a/src/Interfaces/LabelConfigurationSet.php b/src/Interfaces/LabelConfigurationSet.php index b681b822..1381f754 100644 --- a/src/Interfaces/LabelConfigurationSet.php +++ b/src/Interfaces/LabelConfigurationSet.php @@ -3,11 +3,6 @@ use Vendidero\Shiptastic\Labels\ConfigurationSet; -/** - * Shipment Label Interface - * - * @version 3.1.0 - */ if ( ! defined( 'ABSPATH' ) ) { exit; } diff --git a/src/Interfaces/ShipmentLabel.php b/src/Interfaces/ShipmentLabel.php index 939d12df..04b2b898 100644 --- a/src/Interfaces/ShipmentLabel.php +++ b/src/Interfaces/ShipmentLabel.php @@ -3,11 +3,6 @@ use Vendidero\Shiptastic\ShipmentError; -/** - * Shipment Label Interface - * - * @version 3.1.0 - */ if ( ! defined( 'ABSPATH' ) ) { exit; } diff --git a/src/Interfaces/ShipmentReturnLabel.php b/src/Interfaces/ShipmentReturnLabel.php index 873d5614..078b9f36 100644 --- a/src/Interfaces/ShipmentReturnLabel.php +++ b/src/Interfaces/ShipmentReturnLabel.php @@ -1,18 +1,10 @@ services ) ) { return $name; - } else { - if ( $key = array_search( $name, $this->get_all_services(), true ) ) { + } elseif ( $key = array_search( $name, $this->get_all_services(), true ) ) { return $key; - } } return $name; @@ -238,12 +236,12 @@ public function get_service_meta( $service_id, $meta_key, $default_value = null return array_key_exists( $additional_id, $this->additional ) ? $this->additional[ $additional_id ] : $default_value; } - public function get_service_value( $service, $default = null ) { + public function get_service_value( $service, $default_value = null ) { if ( $service_id = $this->get_service_id( $service ) ) { $service = $service_id; } - return array_key_exists( $service, $this->services ) ? $this->services[ $service ]['value'] : $default; + return array_key_exists( $service, $this->services ) ? $this->services[ $service ]['value'] : $default_value; } public function get_settings() { @@ -314,7 +312,7 @@ public function has_setting( $id ) { return false; } - public function get_setting( $id, $default = null, $group = '' ) { + public function get_setting( $id, $default_value = null, $group = '' ) { $details = $this->get_setting_details( $id ); $settings = $this->get_settings(); @@ -324,7 +322,7 @@ public function get_setting( $id, $default = null, $group = '' ) { } if ( 'service_meta' === $group && ! empty( $details['service_meta'] ) ) { - return $this->get_service_meta( $id, $details['service_meta'], $default ); + return $this->get_service_meta( $id, $details['service_meta'], $default_value ); } else { $setting_id = $this->get_clean_setting_id( $id ); @@ -333,7 +331,7 @@ public function get_setting( $id, $default = null, $group = '' ) { } } - return $default; + return $default_value; } public function update_setting( $id, $value, $group = '' ) { diff --git a/src/Labels/DownloadHandler.php b/src/Labels/DownloadHandler.php index d6461d46..0f042ccf 100644 --- a/src/Labels/DownloadHandler.php +++ b/src/Labels/DownloadHandler.php @@ -24,7 +24,7 @@ public static function init() { public static function download_bulk_export() { if ( isset( $_GET['action'] ) && 'wc-stc-download-export-shipment-label' === $_GET['action'] && isset( $_REQUEST['_wpnonce'] ) ) { - if ( wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'download-export-shipment-label' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'download-export-shipment-label' ) ) { $args = array( 'force' => isset( $_GET['force'] ) ? wc_clean( wp_unslash( $_GET['force'] ) ) : 'no', // phpcs:ignore WordPress.Security.NonceVerification.Recommended ); @@ -45,7 +45,7 @@ public static function download_bulk_export() { } public static function download_label() { - if ( 'wc-stc-download-shipment-label' === $_GET['action'] && wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'download-shipment-label' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( 'wc-stc-download-shipment-label' === $_GET['action'] && wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'download-shipment-label' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated $shipment_id = absint( $_GET['shipment_id'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated $has_permission = current_user_can( 'edit_shop_orders' ); @@ -127,7 +127,7 @@ private static function embed( $file_path, $filename ) { header( 'Content-Length: ' . $file_size ); - @readfile( $file_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.WP.AlternativeFunctions.file_system_read_readfile + @readfile( $file_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_readfile exit(); } } diff --git a/src/Labels/Factory.php b/src/Labels/Factory.php index 995e02fd..31fc03d5 100644 --- a/src/Labels/Factory.php +++ b/src/Labels/Factory.php @@ -10,8 +10,8 @@ use Vendidero\Shiptastic\Caches\Helper; use Vendidero\Shiptastic\Interfaces\ShipmentLabel; -use \WC_Data_Store; -use \Exception; +use WC_Data_Store; +use Exception; defined( 'ABSPATH' ) || exit; diff --git a/src/Labels/Label.php b/src/Labels/Label.php index e4f642bd..5860a4d8 100644 --- a/src/Labels/Label.php +++ b/src/Labels/Label.php @@ -295,17 +295,17 @@ public function has_service( $service ) { * * @param $service * @param $prop - * @param $default + * @param $default_value * * @return mixed */ - public function get_service_prop( $service, $prop, $default = null, $context = 'view' ) { + public function get_service_prop( $service, $prop, $default_value = null, $context = 'view' ) { $meta_key = "service_{$service}_{$prop}"; if ( $this->get_meta( $meta_key, true, $context ) ) { return $this->get_meta( $meta_key, true, $context ); } else { - return $default; + return $default_value; } } @@ -744,7 +744,7 @@ protected function get_per_item_weights( $total_weight, $item_weights, $shipment * Discrepancies detected between item weights and total shipment weight. * Try to distribute the mismatch between items. */ - if ( $item_total_weight != $total_weight ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + if ( $item_total_weight != $total_weight ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual $diff = $total_weight - $item_total_weight; $diff_abs = abs( $diff ); diff --git a/src/Labels/Query.php b/src/Labels/Query.php index d2da7150..f04bdf04 100644 --- a/src/Labels/Query.php +++ b/src/Labels/Query.php @@ -402,25 +402,26 @@ protected function prepare_query() { * Used internally to generate an SQL string for searching across multiple columns * * - * @global \wpdb $wpdb WordPress database abstraction object. - * - * @param string $string + * @param string $search_query * @param array $cols * @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for single site. * Single site allows leading and trailing wildcards, Network Admin only trailing. + * * @return string + *@global \wpdb $wpdb WordPress database abstraction object. + * */ - protected function get_search_sql( $string, $cols, $wild = false ) { + protected function get_search_sql( $search_query, $cols, $wild = false ) { global $wpdb; $searches = array(); $leading_wild = ( 'leading' === $wild || 'both' === $wild ) ? '%' : ''; $trailing_wild = ( 'trailing' === $wild || 'both' === $wild ) ? '%' : ''; - $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; + $like = $leading_wild . $wpdb->esc_like( $search_query ) . $trailing_wild; foreach ( $cols as $col ) { if ( 'ID' === $col ) { - $searches[] = $wpdb->prepare( "$col = %s", $string ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $searches[] = $wpdb->prepare( "$col = %s", $search_query ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } else { $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } diff --git a/src/Order.php b/src/Order.php index 869d2a8d..765deda4 100644 --- a/src/Order.php +++ b/src/Order.php @@ -336,49 +336,47 @@ public function create_shipments( $default_status = 'processing' ) { $errors->add( $code, $message ); } } - } else { - if ( 0 === count( $packed_boxes ) ) { + } elseif ( 0 === count( $packed_boxes ) ) { $errors->add( 404, sprintf( _x( 'Seems like none of your packaging options is available for this order.', 'shipments', 'shiptastic-for-woocommerce' ), Settings::get_settings_url( 'packaging' ) ) ); - } else { - foreach ( $packed_boxes as $box ) { - $packaging = $box->getBox(); - $items = $box->getItems(); - $shipment_items = array(); - - foreach ( $items as $item ) { - $order_item = $item->getItem(); - - if ( ! isset( $shipment_items[ $order_item->get_id() ] ) ) { - $shipment_items[ $order_item->get_id() ] = 1; - } else { - $shipment_items[ $order_item->get_id() ]++; - } - } + } else { + foreach ( $packed_boxes as $box ) { + $packaging = $box->getBox(); + $items = $box->getItems(); + $shipment_items = array(); + + foreach ( $items as $item ) { + $order_item = $item->getItem(); - $shipment = wc_stc_create_shipment( - $this, - array( - 'items' => $shipment_items, - 'props' => array( - 'packaging_id' => $packaging->get_id(), - 'status' => $default_status, - ), - ) - ); - - if ( ! is_wp_error( $shipment ) ) { - $this->add_shipment( $shipment ); - - $shipments_created[ $shipment->get_id() ] = $shipment; + if ( ! isset( $shipment_items[ $order_item->get_id() ] ) ) { + $shipment_items[ $order_item->get_id() ] = 1; } else { - foreach ( $shipments_created as $id => $shipment_created ) { - $shipment_created->delete( true ); - $this->remove_shipment( $id ); - } - - foreach ( $shipment->get_error_messages() as $code => $message ) { - $errors->add( $code, $message ); - } + ++$shipment_items[ $order_item->get_id() ]; + } + } + + $shipment = wc_stc_create_shipment( + $this, + array( + 'items' => $shipment_items, + 'props' => array( + 'packaging_id' => $packaging->get_id(), + 'status' => $default_status, + ), + ) + ); + + if ( ! is_wp_error( $shipment ) ) { + $this->add_shipment( $shipment ); + + $shipments_created[ $shipment->get_id() ] = $shipment; + } else { + foreach ( $shipments_created as $id => $shipment_created ) { + $shipment_created->delete( true ); + $this->remove_shipment( $id ); + } + + foreach ( $shipment->get_error_messages() as $code => $message ) { + $errors->add( $code, $message ); } } } @@ -590,7 +588,7 @@ public function get_shipment_position_number( $shipment ) { if ( $shipment->get_id() === $loop_shipment->get_id() ) { break; } - $number++; + ++$number; } } diff --git a/src/Orders/Factory.php b/src/Orders/Factory.php index 2e63acb1..660e7ab8 100644 --- a/src/Orders/Factory.php +++ b/src/Orders/Factory.php @@ -10,7 +10,7 @@ use Vendidero\Shiptastic\Caches\Helper; use Vendidero\Shiptastic\Order; -use \Exception; +use Exception; defined( 'ABSPATH' ) || exit; diff --git a/src/PDFMerger.php b/src/PDFMerger.php index 283dc5a0..7f9408ea 100644 --- a/src/PDFMerger.php +++ b/src/PDFMerger.php @@ -32,7 +32,7 @@ public function add( $filename, $pages = array(), $width = 210 ) { if ( file_exists( $filename ) ) { $page_count = $this->_pdf->setSourceFile( $filename ); - for ( $i = 1; $i <= $page_count; $i ++ ) { + for ( $i = 1; $i <= $page_count; $i++ ) { if ( $this->_isPageInRange( $i, $pages ) ) { $this->_addPage( $i, $width ); } diff --git a/src/PDFSplitter.php b/src/PDFSplitter.php index fe2f6f62..c6a137ad 100644 --- a/src/PDFSplitter.php +++ b/src/PDFSplitter.php @@ -173,5 +173,4 @@ private function _getRange( $value = null ) { // phpcs:ignore PSR2.Methods.Metho return range( $value[0] > $value[1] ? $value[1] : $value[0], $value[0] > $value[1] ? $value[0] : $value[1] ); } - } diff --git a/src/Package.php b/src/Package.php index 9ce244c7..62101ce5 100644 --- a/src/Package.php +++ b/src/Package.php @@ -851,10 +851,10 @@ public static function get_assets_url( $script_or_style ) { return trailingslashit( $assets_url ) . $script_or_style; } - public static function get_setting( $name, $default = false ) { + public static function get_setting( $name, $default_value = false ) { $option_name = "woocommerce_shiptastic_{$name}"; - return get_option( $option_name, $default ); + return get_option( $option_name, $default_value ); } public static function get_store_address_country() { diff --git a/src/Packaging/AsyncReportGenerator.php b/src/Packaging/AsyncReportGenerator.php index cb32cad0..e535954b 100644 --- a/src/Packaging/AsyncReportGenerator.php +++ b/src/Packaging/AsyncReportGenerator.php @@ -113,7 +113,7 @@ public function next() { $packaging_data[ $country ][ "$packaging_id" ]['count'] += 1; $packaging_data[ $country ][ "$packaging_id" ]['weight_in_kg'] += wc_add_number_precision( (float) wc_get_weight( $packaging_weight, 'kg', $shipment->get_weight_unit() ), false ); - $shipments_processed++; + ++$shipments_processed; } $this->args['processed'] = absint( $this->args['processed'] ) + $shipments_processed; diff --git a/src/Packaging/Report.php b/src/Packaging/Report.php index ffbff60c..84c14270 100644 --- a/src/Packaging/Report.php +++ b/src/Packaging/Report.php @@ -251,10 +251,8 @@ public function get_packaging_count( $packaging_id, $country = '' ) { if ( isset( $this->args['packaging'][ "$packaging_id" ] ) ) { $count = absint( $this->args['packaging'][ "$packaging_id" ]['count'] ); } - } else { - if ( isset( $this->args['countries'][ $country ], $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ] ) ) { + } elseif ( isset( $this->args['countries'][ $country ], $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ] ) ) { $count = absint( $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ]['count'] ); - } } return $count; @@ -267,10 +265,8 @@ public function get_packaging_weight( $packaging_id, $country = '', $round = tru if ( isset( $this->args['packaging'][ "$packaging_id" ] ) ) { $weight = $this->args['packaging'][ "$packaging_id" ]['weight_in_kg']; } - } else { - if ( isset( $this->args['countries'][ $country ], $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ] ) ) { + } elseif ( isset( $this->args['countries'][ $country ], $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ] ) ) { $weight = $this->args['countries'][ $country ]['packaging'][ "$packaging_id" ]['weight_in_kg']; - } } $weight = wc_get_weight( $weight, $unit, 'kg' ); diff --git a/src/Packaging/ReportHelper.php b/src/Packaging/ReportHelper.php index 4ed8f0fb..1539bd47 100644 --- a/src/Packaging/ReportHelper.php +++ b/src/Packaging/ReportHelper.php @@ -18,7 +18,7 @@ public static function init() { add_action( ReportQueue::get_hook_name( $id ), - function( $args ) use ( $type ) { + function ( $args ) use ( $type ) { ReportQueue::next( $type, $args ); }, 10, @@ -171,7 +171,7 @@ public static function render_report() { else : $details = ReportQueue::get_queue_details( $report_id ); ?> -

    Find pending actions', 'shipments', 'shiptastic-for-woocommerce' ), esc_html( $details['shipment_count'] ), ( $details['next_date'] ? esc_html( $details['next_date']->date_i18n( wc_date_format() . ' @ ' . wc_time_format() ) ) : esc_html_x( 'Not yet known', 'shipments', 'shiptastic-for-woocommerce' ) ), esc_url( $details['link'] ) ); ?>

    +

    Find pending actions', 'shipments', 'shiptastic-for-woocommerce' ), esc_html( $details['shipment_count'] ), ( $details['next_date'] ? esc_html( $details['next_date']->date_i18n( wc_date_format() . ' @ ' . wc_time_format() ) ) : esc_html_x( 'Not yet known', 'shipments', 'shiptastic-for-woocommerce' ) ), esc_url( $details['link'] ) ) ); ?>

get_status() ) { - $report->delete(); - } + } elseif ( $report = self::get_report( $report_id ) ) { + if ( 'completed' !== $report->get_status() ) { + $report->delete(); } } } @@ -380,7 +378,7 @@ public static function get_reports( $args = array() ) { if ( array_key_exists( $args['orderby'], array( 'date_start', 'date_end' ) ) ) { usort( $reports_sorted, - function( $a, $b ) use ( $args ) { + function ( $a, $b ) use ( $args ) { if ( $a[ $args['orderby'] ] === $b[ $args['orderby'] ] ) { return 0; } @@ -439,7 +437,7 @@ public static function get_report( $id ) { } public static function delete_report() { - if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wp_unslash( $_GET['_wpnonce'] ) : '', 'wc_shiptastic_packaging_delete_report' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wc_clean( wp_unslash( $_GET['_wpnonce'] ) ) : '', 'wc_shiptastic_packaging_delete_report' ) ) { wp_die(); } @@ -472,7 +470,7 @@ protected static function get_clean_referer() { } public static function refresh_report() { - if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wp_unslash( $_GET['_wpnonce'] ) : '', 'wc_shiptastic_packaging_refresh_report' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wc_clean( wp_unslash( $_GET['_wpnonce'] ) ) : '', 'wc_shiptastic_packaging_refresh_report' ) ) { wp_die(); } @@ -490,7 +488,7 @@ public static function refresh_report() { } public static function cancel_report() { - if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wp_unslash( $_GET['_wpnonce'] ) : '', 'wc_shiptastic_packaging_cancel_report' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( ! current_user_can( 'manage_woocommerce' ) || ! wp_verify_nonce( isset( $_GET['_wpnonce'] ) ? wc_clean( wp_unslash( $_GET['_wpnonce'] ) ) : '', 'wc_shiptastic_packaging_cancel_report' ) ) { wp_die(); } diff --git a/src/PackagingFactory.php b/src/PackagingFactory.php index 4c542c52..e528c0c1 100644 --- a/src/PackagingFactory.php +++ b/src/PackagingFactory.php @@ -9,7 +9,7 @@ */ namespace Vendidero\Shiptastic; -use \Exception; +use Exception; use Vendidero\Shiptastic\Caches\Helper; defined( 'ABSPATH' ) || exit; diff --git a/src/Packing/Helper.php b/src/Packing/Helper.php index 763b8f4e..de21891f 100644 --- a/src/Packing/Helper.php +++ b/src/Packing/Helper.php @@ -81,13 +81,13 @@ public static function enable_auto_packing() { * * @return PackedBoxList */ - public static function pack( $items, $boxes, $for = 'order' ) { + public static function pack( $items, $boxes, $context = 'order' ) { self::$items_too_large = array(); /** * @var \Vendidero\Shiptastic\Packing\Packer $packer */ - $packer = apply_filters( 'woocommerce_shiptastic_packer_instance', new Packer(), $items, $boxes, $for ); + $packer = apply_filters( 'woocommerce_shiptastic_packer_instance', new Packer(), $items, $boxes, $context ); $packer->set_boxes( $boxes ); $packer->set_items( $items ); @@ -98,7 +98,7 @@ public static function pack( $items, $boxes, $for = 'order' ) { $packer->set_max_boxes_to_balance_weight( 0 ); } - do_action( 'woocommerce_shiptastic_packer_before_pack', $packer, $for ); + do_action( 'woocommerce_shiptastic_packer_before_pack', $packer, $context ); $packed_boxes = $packer->pack(); diff --git a/src/PickupDelivery.php b/src/PickupDelivery.php index 2569b3a0..ffe230dd 100644 --- a/src/PickupDelivery.php +++ b/src/PickupDelivery.php @@ -3,7 +3,7 @@ namespace Vendidero\Shiptastic; use Automattic\WooCommerce\StoreApi\Utilities\CartController; -use \Exception; +use Exception; use WC_Order; use WP_Query; @@ -371,7 +371,7 @@ public static function register_pickup_location_notice_field( $field, $key, $arg
>

- + get_label() : '' ); ?>

@@ -877,7 +877,7 @@ public static function register_classic_checkout_fields( $fields ) { if ( 'order' === $current_pickup_location_field_group ) { add_action( 'woocommerce_after_order_notes', - function( $checkout ) use ( $current_pickup_location_field ) { + function ( $checkout ) use ( $current_pickup_location_field ) { if ( ! did_action( 'woocommerce_shiptastic_current_pickup_location_field_rendered' ) ) { woocommerce_form_field( 'current_pickup_location', $current_pickup_location_field, $checkout->get_value( 'current_pickup_location' ) ); } diff --git a/src/Registry/Container.php b/src/Registry/Container.php index a67ec600..39216034 100644 --- a/src/Registry/Container.php +++ b/src/Registry/Container.php @@ -86,7 +86,7 @@ public function get( $id ) { throw new Exception( sprintf( 'Cannot construct an instance of %s because it has not been registered.', - $id + esc_html( $id ) ) ); } diff --git a/src/Rest/ShipmentsController.php b/src/Rest/ShipmentsController.php index e5713d11..33d50a39 100644 --- a/src/Rest/ShipmentsController.php +++ b/src/Rest/ShipmentsController.php @@ -351,10 +351,8 @@ protected function prepare_object_for_database( $request, $creating = false ) { if ( ! $order_shipment->needs_return() ) { throw new \WC_REST_Exception( 'woocommerce_stc_rest_invalid_id', esc_html_x( 'This order does need a return.', 'shipments', 'shiptastic-for-woocommerce' ) ); } - } else { - if ( ! $order_shipment->needs_shipping() ) { + } elseif ( ! $order_shipment->needs_shipping() ) { throw new \WC_REST_Exception( 'woocommerce_stc_rest_invalid_id', esc_html_x( 'This order does need shipping.', 'shipments', 'shiptastic-for-woocommerce' ) ); - } } $shipment->sync(); @@ -613,40 +611,38 @@ protected function set_item( $shipment, $posted ) { } $item->sync( array( 'quantity' => $quantity ) ); - } else { - if ( $order_shipment = $shipment->get_order_shipment() ) { + } elseif ( $order_shipment = $shipment->get_order_shipment() ) { $quantity = isset( $posted['quantity'] ) ? absint( wp_unslash( $posted['quantity'] ) ) : $item->get_quantity(); $quantity_left = 0; - if ( 'return' === $shipment->get_type() ) { - $quantity_left = $order_shipment->get_item_quantity_left_for_returning( - $item->get_order_item_id(), - array( - 'exclude_current_shipment' => true, - 'shipment_id' => $shipment->get_id(), - ) - ); - } elseif ( $order_item = $item->get_order_item() ) { - $quantity_left = $order_shipment->get_item_quantity_left_for_shipping( - $order_item, - array( - 'exclude_current_shipment' => true, - 'shipment_id' => $shipment->get_id(), - ) - ); - } + if ( 'return' === $shipment->get_type() ) { + $quantity_left = $order_shipment->get_item_quantity_left_for_returning( + $item->get_order_item_id(), + array( + 'exclude_current_shipment' => true, + 'shipment_id' => $shipment->get_id(), + ) + ); + } elseif ( $order_item = $item->get_order_item() ) { + $quantity_left = $order_shipment->get_item_quantity_left_for_shipping( + $order_item, + array( + 'exclude_current_shipment' => true, + 'shipment_id' => $shipment->get_id(), + ) + ); + } - if ( $quantity > $quantity_left ) { - $quantity = $quantity_left; - } + if ( $quantity > $quantity_left ) { + $quantity = $quantity_left; + } - if ( $quantity <= 0 ) { - $shipment->remove_item( $item->get_id() ); - return; - } + if ( $quantity <= 0 ) { + $shipment->remove_item( $item->get_id() ); + return; + } $shipment->update_item_quantity( $item->get_id(), $quantity ); - } } $props_to_set = array( diff --git a/src/SecretBox.php b/src/SecretBox.php index 82b45adf..f289ed6d 100644 --- a/src/SecretBox.php +++ b/src/SecretBox.php @@ -198,7 +198,7 @@ public static function supports_auto_insert() { */ $path_to_wp_config = ABSPATH . '/wp-config.php'; // phpcs:ignore - if ( @file_exists( $path_to_wp_config ) && @is_writeable( $path_to_wp_config ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + if ( @file_exists( $path_to_wp_config ) && @is_writeable( $path_to_wp_config ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_is_writeable $supports = true; } @@ -230,8 +230,6 @@ public static function maybe_insert_missing_key( $encryption_type = '' ) { $path_to_wp_config = ABSPATH . '/wp-config.php'; // phpcs:ignore if ( @file_exists( $path_to_wp_config ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - error_reporting( 0 ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting,WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting - // Load file data $config_file = file( $path_to_wp_config ); $last_define_line = false; @@ -275,14 +273,14 @@ public static function maybe_insert_missing_key( $encryption_type = '' ) { array_splice( $config_file, $last_define_line + 1, 0, $to_insert ); } - $handle = fopen( $path_to_wp_config, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + $handle = fopen( $path_to_wp_config, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( $handle ) { foreach ( $config_file as $line ) { - fwrite( $handle, $line ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite + fwrite( $handle, $line ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite } - fclose( $handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + fclose( $handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose $updated = true; } } diff --git a/src/Shipment.php b/src/Shipment.php index 1ce73add..f50012e1 100644 --- a/src/Shipment.php +++ b/src/Shipment.php @@ -2081,13 +2081,13 @@ public function sync_packaging() { public function update_packaging() { if ( $packaging = $this->get_packaging() ) { - $packaging_dimension = wc_stc_get_packaging_dimension_unit(); + $dimension_unit = wc_stc_get_packaging_dimension_unit(); $props = array( - 'width' => wc_get_dimension( $packaging->get_width( 'edit' ), $this->get_dimension_unit(), $packaging_dimension ), - 'length' => wc_get_dimension( $packaging->get_length( 'edit' ), $this->get_dimension_unit(), $packaging_dimension ), - 'height' => wc_get_dimension( $packaging->get_height( 'edit' ), $this->get_dimension_unit(), $packaging_dimension ), - 'packaging_weight' => wc_get_weight( $packaging->get_weight( 'edit' ), $this->get_weight_unit(), wc_stc_get_packaging_weight_unit() ), + 'width' => wc_get_dimension( $packaging->get_width(), $this->get_dimension_unit(), $dimension_unit ), + 'length' => wc_get_dimension( $packaging->get_length(), $this->get_dimension_unit(), $dimension_unit ), + 'height' => wc_get_dimension( $packaging->get_height(), $this->get_dimension_unit(), $dimension_unit ), + 'packaging_weight' => wc_get_weight( $packaging->get_weight(), $this->get_weight_unit(), wc_stc_get_packaging_weight_unit() ), 'packaging_title' => $packaging->get_title(), ); diff --git a/src/ShipmentFactory.php b/src/ShipmentFactory.php index 4cbe8e6e..c11fe5d7 100644 --- a/src/ShipmentFactory.php +++ b/src/ShipmentFactory.php @@ -11,8 +11,8 @@ use Vendidero\Shiptastic\Caches\Helper; use Vendidero\Shiptastic\Shipment; -use \WC_Data_Store; -use \Exception; +use WC_Data_Store; +use Exception; defined( 'ABSPATH' ) || exit; diff --git a/src/ShipmentQuery.php b/src/ShipmentQuery.php index 6f22fe53..d66c62b4 100644 --- a/src/ShipmentQuery.php +++ b/src/ShipmentQuery.php @@ -522,25 +522,26 @@ protected function prepare_query() { * Used internally to generate an SQL string for searching across multiple columns * * - * @global wpdb $wpdb WordPress database abstraction object. - * - * @param string $string + * @param string $search_query * @param array $cols * @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for single site. * Single site allows leading and trailing wildcards, Network Admin only trailing. + * * @return string + *@global wpdb $wpdb WordPress database abstraction object. + * */ - protected function get_search_sql( $string, $cols, $wild = false ) { + protected function get_search_sql( $search_query, $cols, $wild = false ) { global $wpdb; $searches = array(); $leading_wild = ( 'leading' === $wild || 'both' === $wild ) ? '%' : ''; $trailing_wild = ( 'trailing' === $wild || 'both' === $wild ) ? '%' : ''; - $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; + $like = $leading_wild . $wpdb->esc_like( $search_query ) . $trailing_wild; foreach ( $cols as $col ) { if ( 'ID' === $col ) { - $searches[] = $wpdb->prepare( "$wpdb->stc_shipments.$col = %s", $string ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $searches[] = $wpdb->prepare( "$wpdb->stc_shipments.$col = %s", $search_query ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } else { $searches[] = $wpdb->prepare( "$wpdb->stc_shipments.$col LIKE %s", $like ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } diff --git a/src/ShippingMethod/MethodHelper.php b/src/ShippingMethod/MethodHelper.php index 7717b13b..9f1c757e 100644 --- a/src/ShippingMethod/MethodHelper.php +++ b/src/ShippingMethod/MethodHelper.php @@ -191,7 +191,7 @@ public static function set_method_filters( $methods ) { if ( is_callable( array( $wc, 'is_rest_api_request' ) ) && $wc->is_rest_api_request() ) { add_filter( 'pre_option', - function( $pre, $option, $default_value ) { + function ( $pre, $option, $default_value ) { if ( strstr( $option, 'woocommerce_' ) && '_settings' === substr( $option, -9 ) ) { $option_clean = explode( '_', substr( $option, 0, -9 ) ); $last_part = $option_clean[ count( $option_clean ) - 1 ]; @@ -202,7 +202,7 @@ function( $pre, $option, $default_value ) { if ( absint( $last_part ) > 0 ) { add_filter( "option_{$option}", - function( $option_value, $option_name ) { + function ( $option_value, $option_name ) { if ( is_array( $option_value ) ) { foreach ( self::get_method_settings() as $setting_id => $setting ) { if ( ! array_key_exists( $setting_id, $option_value ) ) { @@ -514,7 +514,7 @@ public static function get_method_settings( $force_load_all = false ) { $count = 0; foreach ( $provider_inner_settings as $shipment_type => $settings ) { - $count ++; + ++$count; $tabs_open_id = "label_config_set_tabs_{$provider}_{$shipment_type}_open"; $tabs_close_id = "label_config_set_tabs_{$provider}_{$shipment_type}_close"; @@ -646,7 +646,7 @@ public static function render_method_tabs( $html, $key, $setting, $method ) {