Skip to content

Commit

Permalink
Rearrange code to remove early return
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Timmermans committed Jul 29, 2015
1 parent 5dfabde commit 2e28c47
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions admin/class-primary-term-admin.php
Expand Up @@ -38,20 +38,18 @@ public function enqueue_assets() {
$taxonomies = $this->get_primary_term_taxonomies();

// Only enqueue if there are taxonomies that need a primary term.
if ( empty( $taxonomies ) ) {
return;
}

wp_enqueue_style( 'wpseo-primary-category', plugins_url( 'css/metabox-primary-category' . WPSEO_CSSJS_SUFFIX . '.css', WPSEO_FILE ), array(), WPSEO_VERSION );
if ( ! empty( $taxonomies ) ) {
wp_enqueue_style( 'wpseo-primary-category', plugins_url( 'css/metabox-primary-category' . WPSEO_CSSJS_SUFFIX . '.css', WPSEO_FILE ), array(), WPSEO_VERSION );

wp_enqueue_script( 'wpseo-primary-category', plugins_url( 'js/wp-seo-metabox-category' . WPSEO_CSSJS_SUFFIX . '.js', WPSEO_FILE ), array( 'jquery' ), WPSEO_VERSION, true );
wp_enqueue_script( 'wpseo-primary-category', plugins_url( 'js/wp-seo-metabox-category' . WPSEO_CSSJS_SUFFIX . '.js', WPSEO_FILE ), array( 'jquery' ), WPSEO_VERSION, true );

$taxonomies = array_map( array( $this, 'map_taxonomies_for_js' ), $taxonomies );
$taxonomies = array_map( array( $this, 'map_taxonomies_for_js' ), $taxonomies );

$data = array(
'taxonomies' => $taxonomies,
);
wp_localize_script( 'wpseo-primary-category', 'wpseoPrimaryCategoryL10n', $data );
$data = array(
'taxonomies' => $taxonomies,
);
wp_localize_script( 'wpseo-primary-category', 'wpseoPrimaryCategoryL10n', $data );
}
}

/**
Expand Down

3 comments on commit 2e28c47

@GaryJones
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early returns / guard clauses are usually a good thing.
Why was this one removed?

@Rarst
Copy link
Contributor

@Rarst Rarst commented on 2e28c47 Jul 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, strongly disagree. Early returns & minimizing nesting levels are good.

@atimmer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping me sharp.

Please sign in to comment.