Skip to content

Commit

Permalink
scrutinizer best practice
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jun 6, 2016
1 parent 00cd6f7 commit 730019e
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion includes/admin/class-wc-admin-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static function scan_log_files() {
$files = @scandir( WC_LOG_DIR );
$result = array();

if ( $files ) {
if ( ! empty( $files ) ) {

foreach ( $files as $key => $value ) {

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-admin-page-status-report.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@
}
}

if ( $found_files ) {
if ( ! empty( $found_files ) ) {
foreach ( $found_files as $plugin_name => $found_plugin_files ) {
?>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-bulk-edit-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

$tax_classes = WC_Tax::get_tax_classes();

if ( $tax_classes )
if ( ! empty( $tax_classes ) )
foreach ( $tax_classes as $class ) {
$options[ sanitize_title( $class ) ] = esc_html( $class );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-quick-edit-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

$tax_classes = WC_Tax::get_tax_classes();

if ( $tax_classes )
if ( ! empty( $tax_classes ) )
foreach ( $tax_classes as $class ) {
$options[ sanitize_title( $class ) ] = esc_html( $class );
}
Expand Down
4 changes: 2 additions & 2 deletions includes/api/class-wc-rest-products-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ protected function save_product_meta( $product, $request ) {
wp_set_object_terms( $product->id, $values, $attribute_name );
}

if ( $values ) {
if ( ! empty( $values ) ) {
// Add attribute to array, but don't set values.
$attributes[ $attribute_name ] = array(
'name' => $attribute_name,
Expand Down Expand Up @@ -1071,7 +1071,7 @@ protected function save_product_meta( $product, $request ) {
$clear_parent_ids[] = $product->id;
}

if ( $clear_parent_ids ) {
if ( ! empty( $clear_parent_ids ) ) {
foreach ( $clear_parent_ids as $clear_id ) {

$children_by_price = get_posts( array(
Expand Down
4 changes: 2 additions & 2 deletions includes/api/legacy/v2/class-wc-api-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ protected function save_product_meta( $product_id, $data ) {
wp_set_object_terms( $product_id, $values, $taxonomy );
}

if ( $values ) {
if ( ! empty( $values ) ) {
// Add attribute to array, but don't set values
$attributes[ $taxonomy ] = array(
'name' => $taxonomy,
Expand Down Expand Up @@ -1009,7 +1009,7 @@ protected function save_product_meta( $product_id, $data ) {
$clear_parent_ids[] = $product_id;
}

if ( $clear_parent_ids ) {
if ( ! empty( $clear_parent_ids ) ) {
foreach ( $clear_parent_ids as $clear_id ) {

$children_by_price = get_posts( array(
Expand Down
4 changes: 2 additions & 2 deletions includes/api/legacy/v3/class-wc-api-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ protected function save_product_meta( $product_id, $data ) {
wp_set_object_terms( $product_id, $values, $taxonomy );
}

if ( $values ) {
if ( ! empty( $values ) ) {
// Add attribute to array, but don't set values.
$attributes[ $taxonomy ] = array(
'name' => $taxonomy,
Expand Down Expand Up @@ -1494,7 +1494,7 @@ protected function save_product_meta( $product_id, $data ) {
$clear_parent_ids[] = $product_id;
}

if ( $clear_parent_ids ) {
if ( ! empty( $clear_parent_ids ) ) {
foreach ( $clear_parent_ids as $clear_id ) {

$children_by_price = get_posts( array(
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public static function save_attributes() {
wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
}

if ( $values ) {
if ( ! empty( $values ) ) {
// Add attribute to array, but don't set values
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
'name' => wc_clean( $attribute_names[ $i ] ),
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public static function grant_access_to_download() {
die();
}

if ( $files ) {
if ( ! empty( $files ) ) {
foreach ( $files as $download_id => $file ) {
if ( $inserted_id = wc_downloadable_file_permission( $download_id, $product_id, $order ) ) {

Expand Down
2 changes: 0 additions & 2 deletions includes/class-wc-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class WC_API {

/**
* Setup class.
*
* @since 2.0
* @return WC_API
*/
public function __construct() {
// Add query vars.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ public function needs_shipping() {

$needs_shipping = false;

if ( $this->cart_contents ) {
if ( ! empty( $this->cart_contents ) ) {
foreach ( $this->cart_contents as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->needs_shipping() ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function process_checkout() {
}

// Skip account if not needed
if ( $fieldset_key == 'account' && ( is_user_logged_in() || ( $this->must_create_account == false && empty( $this->posted['createaccount'] ) ) ) ) {
if ( 'account' === $fieldset_key && ( is_user_logged_in() || ( false === $this->must_create_account && empty( $this->posted['createaccount'] ) ) ) ) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions includes/class-wc-countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function load_country_states() {
// Load only the state files the shop owner wants/needs.
$allowed = array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() );

if ( $allowed ) {
if ( ! empty( $allowed ) ) {
foreach ( $allowed as $code => $country ) {
if ( ! isset( $states[ $code ] ) && file_exists( WC()->plugin_path() . '/i18n/states/' . $code . '.php' ) ) {
include( WC()->plugin_path() . '/i18n/states/' . $code . '.php' );
Expand Down Expand Up @@ -401,7 +401,7 @@ public function country_dropdown_options( $selected_country = '', $selected_stat
* @return array
*/
public function get_address_formats() {
if ( ! $this->address_formats ) :
if ( empty( $this->address_formats ) ) {

// Common formats
$postcode_before_city = "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}";
Expand Down Expand Up @@ -442,7 +442,7 @@ public function get_address_formats() {
'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
));
endif;
}

return $this->address_formats;
}
Expand Down Expand Up @@ -628,7 +628,7 @@ public function get_country_locale_field_selectors() {
* @todo [2.4] Check select2 4.0.0 compatibility with `placeholder` attribute and uncomment relevant lines. https://github.com/woothemes/woocommerce/issues/7729
*/
public function get_country_locale() {
if ( ! $this->locale ) {
if ( empty( $this->locale ) ) {

// Locale information used by the checkout
$this->locale = apply_filters( 'woocommerce_get_country_locale', array(
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ private static function add_to_cart_handler_variable( $product_id ) {
}
}

if ( $missing_attributes ) {
if ( ! empty( $missing_attributes ) ) {
wc_add_notice( sprintf( _n( '%s is a required field', '%s are required fields', sizeof( $missing_attributes ), 'woocommerce' ), wc_format_list_of_items( $missing_attributes ) ), 'error' );
} elseif ( empty( $variation_id ) ) {
wc_add_notice( __( 'Please choose product options&hellip;', 'woocommerce' ), 'error' );
Expand Down
1 change: 0 additions & 1 deletion includes/class-wc-order-item-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class WC_Order_Item_Meta {
*
* @param array $item defaults to array()
* @param \WC_Product $product defaults to null
* @return \WC_Order_Item_Meta instance
*/
public function __construct( $item = array(), $product = null ) {
// Backwards (pre 2.4) compat
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-shipping-zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function get_zone_matching_package( $package ) {
$matches = wc_postcode_location_matcher( $postcode, $postcode_locations, 'zone_id', 'location_code' );
$do_not_match = array_unique( array_diff( $zone_ids_with_postcode_rules, array_keys( $matches ) ) );

if ( $do_not_match ) {
if ( ! empty( $do_not_match ) ) {
$criteria[] = "AND zones.zone_id NOT IN (" . implode( ',', $do_not_match ) . ")";
}
}
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function get_shipping_method_class_names() {
* @return array
*/
public function load_shipping_methods( $package = array() ) {
if ( $package ) {
if ( ! empty( $package ) ) {
$shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $package );
$this->shipping_methods = $shipping_zone->get_shipping_methods( true );
} else {
Expand Down Expand Up @@ -317,7 +317,7 @@ public function calculate_shipping( $packages = array() ) {
* @return array
*/
public function calculate_shipping_for_package( $package = array(), $package_key = 0 ) {
if ( ! $this->enabled || ! $package ) {
if ( ! $this->enabled || empty( $package ) ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function calc_inclusive_tax( $price, $rates ) {
public static function calc_exclusive_tax( $price, $rates ) {
$taxes = array();

if ( $rates ) {
if ( ! empty( $rates ) ) {
// Multiple taxes
foreach ( $rates as $key => $rate ) {

Expand Down
1 change: 0 additions & 1 deletion includes/class-wc-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class WC_Webhook {
*
* @since 2.2
* @param string|int $id
* @return \WC_Webhook
*/
public function __construct( $id ) {

Expand Down
4 changes: 2 additions & 2 deletions includes/cli/class-wc-cli-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ private function save_product_meta( $product_id, $data ) {
wp_set_object_terms( $product_id, $values, $taxonomy );
}

if ( $values ) {
if ( ! empty( $values ) ) {
// Add attribute to array, but don't set values
$attributes[ $taxonomy ] = array(
'name' => $taxonomy,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ private function save_product_meta( $product_id, $data ) {
$clear_parent_ids[] = $product_id;
}

if ( $clear_parent_ids ) {
if ( ! empty( $clear_parent_ids ) ) {
foreach ( $clear_parent_ids as $clear_id ) {

$children_by_price = get_posts( array(
Expand Down
2 changes: 1 addition & 1 deletion includes/emails/class-wc-email-customer-note.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct() {
*/
public function trigger( $args ) {

if ( $args ) {
if ( ! empty( $args ) ) {

$defaults = array(
'order_id' => '',
Expand Down
2 changes: 1 addition & 1 deletion includes/gateways/bacs/class-wc-gateway-bacs.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function process_payment( $order_id ) {
*/
public function get_country_locale() {

if ( ! $this->locale ) {
if ( empty( $this->locale ) ) {

// Locale information to be used - only those that are not 'Sort Code'
$this->locale = apply_filters( 'woocommerce_get_bacs_locale', array(
Expand Down
2 changes: 1 addition & 1 deletion includes/vendor/class-wp-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ protected function get_additional_fields( $object_type = null ) {
protected function get_object_type() {
$schema = $this->get_item_schema();

if ( ! $schema || ! isset( $schema['title'] ) ) {
if ( empty( $schema ) || ! isset( $schema['title'] ) ) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/wc-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function wc_get_template_part( $slug, $name = '' ) {
* @param string $default_path (default: '')
*/
function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
if ( $args && is_array( $args ) ) {
if ( ! empty( $args ) && is_array( $args ) ) {
extract( $args );
}

Expand Down
4 changes: 2 additions & 2 deletions includes/wc-term-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function wc_product_dropdown_categories( $args = array(), $deprecated_hierarchic

$terms = get_terms( 'product_cat', apply_filters( 'wc_product_dropdown_categories_get_terms_args', $args ) );

if ( ! $terms ) {
if ( empty( $terms ) ) {
return;
}

Expand Down Expand Up @@ -538,7 +538,7 @@ function _wc_term_recount( $terms, $taxonomy, $callback = true, $terms_are_term_
}

// Exit if we have no terms to count
if ( ! $terms ) {
if ( empty( $terms ) ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/wc-update-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function wc_update_200_line_items() {

$order_taxes = (array) maybe_unserialize( $order_tax_row->meta_value );

if ( $order_taxes ) {
if ( ! empty( $order_taxes ) ) {
foreach( $order_taxes as $order_tax ) {

if ( ! isset( $order_tax['label'] ) || ! isset( $order_tax['cart_tax'] ) || ! isset( $order_tax['shipping_tax'] ) )
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/class-wc-widget-layered-nav-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function widget( $args, $instance ) {
echo '<ul>';

// Attributes
if ( $_chosen_attributes ) {
if ( ! empty( $_chosen_attributes ) ) {
foreach ( $_chosen_attributes as $taxonomy => $data ) {
foreach ( $data['terms'] as $term_slug ) {
if ( ! $term = get_term_by( 'slug', $term_slug, $taxonomy ) ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/widgets/class-wc-widget-product-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function widget( $args, $instance ) {

$product_category = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array( 'orderby' => 'parent' ) ) );

if ( $product_category ) {
if ( ! empty( $product_category ) ) {
$this->current_cat = end( $product_category );
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
}
Expand Down
2 changes: 1 addition & 1 deletion templates/checkout/form-coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
return;
}

if ( ! WC()->cart->applied_coupons ) {
if ( empty( WC()->cart->applied_coupons ) ) {
$info_message = apply_filters( 'woocommerce_checkout_coupon_message', __( 'Have a coupon?', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>' );
wc_print_notice( $info_message, 'notice' );
}
Expand Down

0 comments on commit 730019e

Please sign in to comment.