| Conditions | 14 |
| Paths | 99 |
| Total Lines | 46 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 90 | function jetpack_post_details_should_run() { |
||
| 91 | // Empty value representing falsy return value. |
||
| 92 | $void = array( false, null, null, null ); |
||
| 93 | |||
| 94 | // If the theme doesn't support 'jetpack-content-options', don't continue. |
||
| 95 | if ( ! current_theme_supports( 'jetpack-content-options' ) ) { |
||
| 96 | return $void; |
||
| 97 | } |
||
| 98 | |||
| 99 | $options = get_theme_support( 'jetpack-content-options' ); |
||
| 100 | $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; |
||
| 101 | |||
| 102 | // If the theme doesn't support 'jetpack-content-options[ 'post-details' ]', don't continue. |
||
| 103 | if ( empty( $post_details ) ) { |
||
| 104 | return $void; |
||
| 105 | } |
||
| 106 | |||
| 107 | $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; |
||
| 108 | $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; |
||
| 109 | $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; |
||
| 110 | $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; |
||
| 111 | |||
| 112 | // If there is no stylesheet and there are no date, categories, tags or author declared, don't continue. |
||
| 113 | if ( empty( $post_details['stylesheet'] ) |
||
| 114 | && ( empty( $date ) |
||
| 115 | || empty( $categories ) |
||
| 116 | || empty( $tags ) |
||
| 117 | || empty( $author ) ) ) { |
||
| 118 | return $void; |
||
| 119 | } |
||
| 120 | |||
| 121 | $date_option = get_option( 'jetpack_content_post_details_date', 1 ); |
||
| 122 | $categories_option = get_option( 'jetpack_content_post_details_categories', 1 ); |
||
| 123 | $tags_option = get_option( 'jetpack_content_post_details_tags', 1 ); |
||
| 124 | $author_option = get_option( 'jetpack_content_post_details_author', 1 ); |
||
| 125 | |||
| 126 | $options = array( $date_option, $categories_option, $tags_option, $author_option ); |
||
| 127 | $definied = array( $date, $categories, $tags, $author ); |
||
| 128 | |||
| 129 | // If all the options are ticked, don't continue. |
||
| 130 | if ( array( 1, 1, 1, 1 ) === $options ) { |
||
| 131 | return $void; |
||
| 132 | } |
||
| 133 | |||
| 134 | return array( true, $options, $definied, $post_details ); |
||
| 135 | } |
||
| 136 |