phpcs fixes in includes/admin/importers/class-wc-tax-rate-importer.php

This commit is contained in:
Rodrigo Primo 2018-03-09 17:24:55 -03:00
parent 73cb1663ec
commit 1dc2511c2c
1 changed files with 18 additions and 19 deletions

View File

@ -3,9 +3,7 @@
* Tax importer class file
*
* @version 2.3.0
* @category Admin
* @package WooCommerce/Admin
* @author WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -19,8 +17,6 @@ if ( ! class_exists( 'WP_Importer' ) ) {
/**
* Tax Rates importer - import tax rates and local tax rates into WooCommerce.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Importers
* @version 2.3.0
*/
@ -59,8 +55,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
*/
public function __construct() {
$this->import_page = 'woocommerce_tax_rate_csv';
// @codingStandardsIgnoreLine
$this->delimiter = empty( $_POST['delimiter'] ) ? ',' : (string) wc_clean( $_POST['delimiter'] );
$this->delimiter = empty( $_POST['delimiter'] ) ? ',' : (string) wc_clean( wp_unslash( $_POST['delimiter'] ) ); // WPCS: CSRF ok.
}
/**
@ -106,7 +101,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
*/
private function import_start() {
if ( function_exists( 'gc_enable' ) ) {
gc_enable();
gc_enable(); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.gc_enableFound
}
wc_set_time_limit( 0 );
@ob_flush();
@ -137,15 +132,18 @@ class WC_Tax_Rate_Importer extends WP_Importer {
$this->import_start();
$loop = 0;
$loop = 0;
$handle = fopen( $file, 'r' );
if ( ( $handle = fopen( $file, 'r' ) ) !== false ) {
if ( false !== $handle ) {
$header = fgetcsv( $handle, 0, $this->delimiter );
if ( 10 === count( $header ) ) {
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== false ) {
$row = fgetcsv( $handle, 0, $this->delimiter );
while ( false !== $row ) {
list( $country, $state, $postcode, $city, $rate, $name, $priority, $compound, $shipping, $class ) = $row;
@ -174,8 +172,8 @@ class WC_Tax_Rate_Importer extends WP_Importer {
// Show Result.
echo '<div class="updated settings-error"><p>';
/* translators: %s: tax rates count */
printf(
/* translators: %s: tax rates count */
esc_html__( 'Import complete - imported %s tax rates.', 'woocommerce' ),
'<strong>' . absint( $loop ) . '</strong>'
);
@ -200,9 +198,10 @@ class WC_Tax_Rate_Importer extends WP_Importer {
* @return bool False if error uploading or invalid file, true otherwise
*/
public function handle_upload() {
// @codingStandardsIgnoreLine
if ( empty( $_POST['file_url'] ) ) {
// phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification -- Nonce already verified in WC_Tax_Rate_Importer::dispatch()
$file_url = isset( $_POST['file_url'] ) ? esc_url_raw( wp_unslash( $_POST['file_url'] ) ) : '';
if ( empty( $file_url ) ) {
$file = wp_import_handle_upload();
if ( isset( $file['error'] ) ) {
@ -210,13 +209,12 @@ class WC_Tax_Rate_Importer extends WP_Importer {
}
$this->id = absint( $file['id'] );
// @codingStandardsIgnoreLine
} elseif ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
// @codingStandardsIgnoreLine
$this->file_url = esc_attr( $_POST['file_url'] );
} elseif ( file_exists( ABSPATH . $file_url ) ) {
$this->file_url = esc_attr( $file_url );
} else {
$this->import_error();
}
// phpcs:enable
return true;
}
@ -244,6 +242,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
echo '<div class="narrow">';
echo '<p>' . esc_html__( 'Hi there! Upload a CSV file containing tax rates to import the contents into your shop. Choose a .csv file to upload, then click "Upload file and import".', 'woocommerce' ) . '</p>';
/* translators: 1: Link to tax rates sample file */
echo '<p>' . sprintf( esc_html__( 'Tax rates need to be defined with columns in a specific order (10 columns). <a href="%s">Click here to download a sample</a>.', 'woocommerce' ), esc_url( WC()->plugin_url() ) . '/sample-data/sample_tax_rates.csv' ) . '</p>';
$action = 'admin.php?import=woocommerce_tax_rate_csv&step=1';
@ -271,8 +270,8 @@ class WC_Tax_Rate_Importer extends WP_Importer {
<input type="hidden" name="max_file_size" value="<?php echo absint( $bytes ); ?>" />
<small>
<?php
/* translators: %s: maximum upload size */
printf(
/* translators: %s: maximum upload size */
esc_html__( 'Maximum size: %s', 'woocommerce' ),
esc_attr( $size )
);
@ -307,7 +306,7 @@ class WC_Tax_Rate_Importer extends WP_Importer {
/**
* Show import error and quit.
*
* @param string $message Error messag.
* @param string $message Error message.
*/
private function import_error( $message = '' ) {
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'woocommerce' ) . '</strong><br />';