Skip to content

Commit

Permalink
WordPress.PHP.YodaConditions.NotYoda
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Sep 7, 2016
1 parent b70f62b commit 734f284
Show file tree
Hide file tree
Showing 38 changed files with 210 additions and 200 deletions.
14 changes: 8 additions & 6 deletions apigen/hook-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class WC_HookFinder {

private static function get_files( $pattern, $flags = 0, $path = '' ) {

if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {

if ( $dir == '\\' || $dir == '/' ) { $dir = ''; } // End IF Statement
if ( '\\' == $dir || '/' == $dir ) {
$dir = '';
}

return self::get_files( basename( $pattern ), $flags, $dir . '/' );

Expand Down Expand Up @@ -102,13 +104,13 @@ public static function process_hooks() {

foreach ( $tokens as $index => $token ) {
if ( is_array( $token ) ) {
if ( $token[0] == T_CLASS ) {
if ( T_CLASS == $token[0] ) {
$token_type = 'class';
} elseif ( $token[0] == T_FUNCTION ) {
} elseif ( T_FUNCTION == $token[0] ) {
$token_type = 'function';
} elseif ( $token[1] === 'do_action' ) {
} elseif ( 'do_action' === $token[1] ) {
$token_type = 'action';
} elseif ( $token[1] === 'apply_filters' ) {
} elseif ( 'apply_filters' === $token[1] ) {
$token_type = 'filter';
} elseif ( $token_type && ! empty( trim( $token[1] ) ) ) {
switch ( $token_type ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/abstracts/abstract-wc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ public function get_shipping_to_display( $tax_display = '' ) {

if ( $this->get_shipping_total() != 0 ) {

if ( $tax_display == 'excl' ) {
if ( 'excl' === $tax_display ) {

// Show shipping excluding tax.
$shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) );
Expand Down
32 changes: 16 additions & 16 deletions includes/abstracts/abstract-wc-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ public function get_total_stock() {
*/
public function check_stock_status() {
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
if ( $this->stock_status !== 'outofstock' ) {
if ( 'outofstock' !== $this->stock_status ) {
$this->set_stock_status( 'outofstock' );
}
} elseif ( $this->backorders_allowed() || $this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
if ( $this->stock_status !== 'instock' ) {
if ( 'instock' !== $this->stock_status ) {
$this->set_stock_status( 'instock' );
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public function is_type( $type ) {
* @return bool
*/
public function is_downloadable() {
return $this->downloadable == 'yes' ? true : false;
return ( 'yes' === $this->downloadable );
}

/**
Expand Down Expand Up @@ -464,7 +464,7 @@ public function get_file_download_path( $download_id ) {
* @return bool
*/
public function is_virtual() {
return apply_filters( 'woocommerce_is_virtual', $this->virtual == 'yes' ? true : false, $this );
return apply_filters( 'woocommerce_is_virtual', ( 'yes' === $this->virtual ), $this );
}

/**
Expand Down Expand Up @@ -599,7 +599,7 @@ public function add_to_cart_text() {
* @return bool
*/
public function managing_stock() {
return ( ! isset( $this->manage_stock ) || $this->manage_stock == 'no' || get_option( 'woocommerce_manage_stock' ) !== 'yes' ) ? false : true;
return ( ! isset( $this->manage_stock ) || 'no' === $this->manage_stock || 'yes' !== get_option( 'woocommerce_manage_stock' ) ) ? false : true;
}

/**
Expand All @@ -608,7 +608,7 @@ public function managing_stock() {
* @return bool
*/
public function is_in_stock() {
return apply_filters( 'woocommerce_product_is_in_stock', $this->stock_status === 'instock', $this );
return apply_filters( 'woocommerce_product_is_in_stock', ( 'instock' === $this->stock_status ), $this );
}

/**
Expand All @@ -617,7 +617,7 @@ public function is_in_stock() {
* @return bool
*/
public function backorders_allowed() {
return apply_filters( 'woocommerce_product_backorders_allowed', $this->backorders === 'yes' || $this->backorders === 'notify' ? true : false, $this->id, $this );
return apply_filters( 'woocommerce_product_backorders_allowed', ( 'yes' === $this->backorders || 'notify' === $this->backorders ), $this->id, $this );
}

/**
Expand All @@ -626,7 +626,7 @@ public function backorders_allowed() {
* @return bool
*/
public function backorders_require_notification() {
return apply_filters( 'woocommerce_product_backorders_require_notification', $this->managing_stock() && $this->backorders === 'notify' ? true : false, $this );
return apply_filters( 'woocommerce_product_backorders_require_notification', ( $this->managing_stock() && 'notify' === $this->backorders ), $this );
}

/**
Expand Down Expand Up @@ -731,7 +731,7 @@ protected function get_availability_class() {
* @return bool
*/
public function is_featured() {
return $this->featured === 'yes' ? true : false;
return ( 'yes' === $this->featured ) ? true : false;
}

/**
Expand All @@ -744,7 +744,7 @@ public function is_visible() {
$visible = false;

// Published/private
} elseif ( $this->post->post_status !== 'publish' && ! current_user_can( 'edit_post', $this->id ) ) {
} elseif ( 'publish' !== $this->post->post_status && ! current_user_can( 'edit_post', $this->id ) ) {
$visible = false;

// Out of stock visibility
Expand Down Expand Up @@ -794,7 +794,7 @@ public function is_purchasable() {
$purchasable = false;

// Check the product is published
} elseif ( $this->post->post_status !== 'publish' && ! current_user_can( 'edit_post', $this->id ) ) {
} elseif ( 'publish' !== $this->post->post_status && ! current_user_can( 'edit_post', $this->id ) ) {
$purchasable = false;
}

Expand Down Expand Up @@ -855,7 +855,7 @@ public function get_price() {
*/
public function get_price_including_tax( $qty = 1, $price = '' ) {

if ( $price === '' ) {
if ( '' === $price ) {
$price = $this->get_price();
}

Expand Down Expand Up @@ -913,7 +913,7 @@ public function get_price_including_tax( $qty = 1, $price = '' ) {
*/
public function get_price_excluding_tax( $qty = 1, $price = '' ) {

if ( $price === '' ) {
if ( '' === $price ) {
$price = $this->get_price();
}

Expand All @@ -937,12 +937,12 @@ public function get_price_excluding_tax( $qty = 1, $price = '' ) {
*/
public function get_display_price( $price = '', $qty = 1 ) {

if ( $price === '' ) {
if ( '' === $price ) {
$price = $this->get_price();
}

$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
$display_price = $tax_display_mode == 'incl' ? $this->get_price_including_tax( $qty, $price ) : $this->get_price_excluding_tax( $qty, $price );
$display_price = ( 'incl' === $tax_display_mode ) ? $this->get_price_including_tax( $qty, $price ) : $this->get_price_excluding_tax( $qty, $price );

return $display_price;
}
Expand All @@ -956,7 +956,7 @@ public function get_display_price( $price = '', $qty = 1 ) {
*/
public function get_price_suffix( $price = '', $qty = 1 ) {

if ( $price === '' ) {
if ( '' === $price ) {
$price = $this->get_price();
}

Expand Down
8 changes: 4 additions & 4 deletions includes/abstracts/abstract-wc-settings-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function generate_settings_html( $form_fields = array(), $echo = true ) {
* @return string
*/
public function get_tooltip_html( $data ) {
if ( $data['desc_tip'] === true ) {
if ( true === $data['desc_tip'] ) {
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$tip = $data['desc_tip'];
Expand All @@ -325,7 +325,7 @@ public function get_tooltip_html( $data ) {
* @return string
*/
public function get_description_html( $data ) {
if ( $data['desc_tip'] === true ) {
if ( true === $data['desc_tip'] ) {
$description = '';
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
Expand Down Expand Up @@ -797,7 +797,7 @@ public function validate_text_field( $key, $value ) {
*/
public function validate_price_field( $key, $value ) {
$value = is_null( $value ) ? '' : $value;
return $value === '' ? '' : wc_format_decimal( trim( stripslashes( $value ) ) );
return ( '' === $value ) ? '' : wc_format_decimal( trim( stripslashes( $value ) ) );
}

/**
Expand All @@ -811,7 +811,7 @@ public function validate_price_field( $key, $value ) {
*/
public function validate_decimal_field( $key, $value ) {
$value = is_null( $value ) ? '' : $value;
return $value === '' ? '' : wc_format_decimal( trim( stripslashes( $value ) ) );
return ( '' === $value ) ? '' : wc_format_decimal( trim( stripslashes( $value ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/abstracts/abstract-wc-shipping-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function add_rate( $args = array() ) {
$taxes = $args['taxes'];

// Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable. This saves shipping methods having to do complex tax calculations.
if ( ! is_array( $taxes ) && $taxes !== false && $total_cost > 0 && $this->is_taxable() ) {
if ( ! is_array( $taxes ) && false !== $taxes && $total_cost > 0 && $this->is_taxable() ) {
$taxes = 'per_item' === $args['calc_tax'] ? $this->get_taxes_per_item( $args['cost'] ) : WC_Tax::calc_shipping_tax( $total_cost, WC_Tax::get_shipping_tax_rates() );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wc-admin-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function admin_scripts() {
}

// Product sorting - only when sorting by menu order on the products page
if ( current_user_can( 'edit_others_pages' ) && $screen_id == 'edit-product' && isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) {
if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true );
wp_enqueue_script( 'woocommerce_product_ordering' );
}
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/class-wc-admin-duplicate-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function dupe_link( $actions, $post ) {
return $actions;
}

if ( $post->post_type != 'product' ) {
if ( 'product' !== $post->post_type ) {
return $actions;
}

Expand All @@ -63,7 +63,7 @@ public function dupe_button() {
return;
}

if ( $post->post_type != 'product' ) {
if ( 'product' !== $post->post_type ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wc-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static function template_file_check_notice() {
$theme_file = get_template_directory() . '/woocommerce/' . $file;
}

if ( $theme_file !== false ) {
if ( false !== $theme_file ) {
$core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file );
$theme_version = WC_Admin_Status::get_file_version( $theme_file );

Expand Down
6 changes: 3 additions & 3 deletions includes/admin/class-wc-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public static function get_option( $option_name, $default = '' ) {
$option_value = stripslashes( $option_value );
}

return $option_value === null ? $default : $option_value;
return ( null === $option_value ) ? $default : $option_value;
}

/**
Expand Down Expand Up @@ -297,7 +297,7 @@ public static function output_fields( $options ) {
$type = $value['type'];
$option_value = self::get_option( $value['id'], $value['default'] );

if ( $value['type'] == 'color' ) {
if ( 'color' === $value['type'] ) {
$type = 'text';
$value['class'] .= 'colorpick';
$description .= '<div id="colorPickerDiv_' . esc_attr( $value['id'] ) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
Expand Down Expand Up @@ -366,7 +366,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<select
name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
Expand Down
8 changes: 4 additions & 4 deletions includes/class-wc-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ public static function add_order_note() {
$note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
$note_type = $_POST['note_type'];

$is_customer_note = $note_type == 'customer' ? 1 : 0;
$is_customer_note = ( 'customer' === $note_type ) ? 1 : 0;

if ( $post_id > 0 ) {
$order = wc_get_order( $post_id );
Expand Down Expand Up @@ -1918,8 +1918,8 @@ public static function refund_line_items() {
$line_item_qtys = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_qtys'] ) ), true );
$line_item_totals = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_totals'] ) ), true );
$line_item_tax_totals = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_tax_totals'] ) ), true );
$api_refund = $_POST['api_refund'] === 'true' ? true : false;
$restock_refunded_items = $_POST['restock_refunded_items'] === 'true' ? true : false;
$api_refund = ( 'true' === $_POST['api_refund'] ) ? true : false;
$restock_refunded_items = ( 'true' === $_POST['restock_refunded_items'] ) ? true : false;
$refund = false;
$response_data = array();

Expand Down Expand Up @@ -2338,7 +2338,7 @@ public static function save_variations() {
$product_type_terms = wp_get_object_terms( $product_id, 'product_type' );

// If the product type hasn't been set or it has changed, update it before saving variations
if ( empty( $product_type_terms ) || $product_type !== sanitize_title( current( $product_type_terms )->name ) ) {
if ( empty( $product_type_terms ) || sanitize_title( current( $product_type_terms )->name ) !== $product_type ) {
wp_set_object_terms( $product_id, $product_type, 'product_type' );
}

Expand Down
18 changes: 9 additions & 9 deletions includes/class-wc-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function __get( $key ) {
break;
case 'display_totals_ex_tax' :
case 'display_cart_ex_tax' :
return $this->tax_display_cart === 'excl';
return 'excl' === $this->tax_display_cart;
break;
case 'cart_contents_weight' :
return $this->get_cart_contents_weight();
Expand Down Expand Up @@ -760,7 +760,7 @@ public function get_tax_totals() {
foreach ( $taxes as $key => $tax ) {
$code = WC_Tax::get_rate_code( $key );

if ( $code || $key === apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) ) {
if ( $code || apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) === $key ) {
if ( ! isset( $tax_totals[ $code ] ) ) {
$tax_totals[ $code ] = new stdClass();
$tax_totals[ $code ]->amount = 0;
Expand Down Expand Up @@ -830,7 +830,7 @@ public function get_displayed_subtotal() {
* @return string cart item key
*/
public function find_product_in_cart( $cart_id = false ) {
if ( $cart_id !== false ) {
if ( false !== $cart_id ) {
if ( is_array( $this->cart_contents ) && isset( $this->cart_contents[ $cart_id ] ) ) {
return $cart_id;
}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ public function restore_cart_item( $cart_item_key ) {
* @return bool
*/
public function set_quantity( $cart_item_key, $quantity = 1, $refresh_totals = true ) {
if ( $quantity == 0 || $quantity < 0 ) {
if ( 0 == $quantity || $quantity < 0 ) {
do_action( 'woocommerce_before_cart_item_quantity_zero', $cart_item_key );
unset( $this->cart_contents[ $cart_item_key ] );
} else {
Expand Down Expand Up @@ -1593,7 +1593,7 @@ public function get_cart_shipping_total() {
if ( $this->shipping_total > 0 ) {

// Display varies depending on settings
if ( $this->tax_display_cart == 'excl' ) {
if ( 'excl' === $this->tax_display_cart ) {

$return = wc_price( $this->shipping_total );

Expand Down Expand Up @@ -1859,7 +1859,7 @@ public function remove_coupon( $coupon_code ) {
$coupon_code = apply_filters( 'woocommerce_coupon_code', $coupon_code );
$position = array_search( $coupon_code, $this->applied_coupons );

if ( $position !== false ) {
if ( false !== $position ) {
unset( $this->applied_coupons[ $position ] );
}

Expand Down Expand Up @@ -2090,7 +2090,7 @@ public function get_cart_subtotal( $compound = false ) {
} else {

// Display varies depending on settings
if ( $this->tax_display_cart == 'excl' ) {
if ( 'excl' === $this->tax_display_cart ) {

$cart_subtotal = wc_price( $this->subtotal_ex_tax );

Expand All @@ -2117,7 +2117,7 @@ public function get_cart_subtotal( $compound = false ) {
* @return string formatted price
*/
public function get_product_price( $_product ) {
if ( $this->tax_display_cart == 'excl' ) {
if ( 'excl' === $this->tax_display_cart ) {
$product_price = $_product->get_price_excluding_tax();
} else {
$product_price = $_product->get_price_including_tax();
Expand Down Expand Up @@ -2145,7 +2145,7 @@ public function get_product_subtotal( $_product, $quantity ) {
// Taxable
if ( $taxable ) {

if ( $this->tax_display_cart == 'excl' ) {
if ( 'excl' === $this->tax_display_cart ) {

$row_price = $_product->get_price_excluding_tax( $quantity );
$product_subtotal = wc_price( $row_price );
Expand Down
Loading

0 comments on commit 734f284

Please sign in to comment.