| Conditions | 19 |
| Paths | 195 |
| Total Lines | 198 |
| 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 |
||
| 9 | function ao_ccss_render_rules() { |
||
| 10 | // Attach required arrays. |
||
| 11 | global $ao_ccss_rules; |
||
| 12 | global $ao_ccss_types; |
||
| 13 | ?> |
||
| 14 | <ul id="rules-panel"> |
||
| 15 | <li class="itemDetail"> |
||
| 16 | <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2> |
||
| 17 | |||
| 18 | <!-- BEGIN Rule dialogs --> |
||
| 19 | <!-- Unsaved dialog --> |
||
| 20 | <div id="unSavedWarning" class="hidden updated settings-error notice notice-warning is-dismissible"> |
||
| 21 | <p><?php _e( "<strong>Rules or Queue changed!</strong> Don't forget to save your changes!", 'autoptimize' ); ?></p> |
||
| 22 | </div> |
||
| 23 | |||
| 24 | <!-- Create/edit rule dialog --> |
||
| 25 | <div id="addEditCritCss" class="hidden"> |
||
| 26 | <table class="form-table rules"> |
||
| 27 | <tr id="critcss_addedit_type_wrapper"> |
||
| 28 | <th scope="row"> |
||
| 29 | <?php _e( 'Rule Type', 'autoptimize' ); ?> |
||
| 30 | </th> |
||
| 31 | <td> |
||
| 32 | <select id="critcss_addedit_type" style="width:100%;"> |
||
| 33 | <option value="paths"><?php _e( 'Path', 'autoptimize' ); ?></option> |
||
| 34 | <option value="types"><?php _e( 'Conditional Tag', 'autoptimize' ); ?></option> |
||
| 35 | </select> |
||
| 36 | </td> |
||
| 37 | </tr> |
||
| 38 | <tr id="critcss_addedit_path_wrapper"> |
||
| 39 | <th scope="row"> |
||
| 40 | <?php _e( 'String in Path', 'autoptimize' ); ?> |
||
| 41 | </th> |
||
| 42 | <td> |
||
| 43 | <input type="text" id="critcss_addedit_path" placeholder="<?php _e( "Enter a part of the URL that identifies the page(s) you're targetting.", 'autoptimize' ); ?>" style="width:100%;" value=""> |
||
| 44 | </td> |
||
| 45 | </tr> |
||
| 46 | <tr id="critcss_addedit_pagetype_wrapper"> |
||
| 47 | <th scope="row"> |
||
| 48 | <?php _e( 'Conditional Tag, Custom Post Type or Page Template', 'autoptimize' ); ?> |
||
| 49 | </th> |
||
| 50 | <td> |
||
| 51 | <select id="critcss_addedit_pagetype" style="width:100%;"> |
||
| 52 | <option value="" disabled selected><?php _e( 'Select from the list below...', 'autoptimize' ); ?></option> |
||
| 53 | <optgroup label="<?php _e( 'Standard Conditional Tags', 'autoptimize' ); ?>"> |
||
| 54 | <?php |
||
| 55 | // Render grouped simple conditional tags. |
||
| 56 | foreach ( $ao_ccss_types as $ctag ) { |
||
| 57 | $optgrp = substr( $ctag, 0, 3 ); |
||
|
|
|||
| 58 | if ( substr( $ctag, 0, 3 ) === 'is_' ) { |
||
| 59 | echo '<option value="' . $ctag . '">' . $ctag . '</option>'; |
||
| 60 | } |
||
| 61 | $prevgrp = substr( $ctag, 0, 3 ); |
||
| 62 | } |
||
| 63 | |||
| 64 | // Render grouped custom post types, templates and specific conditional tags. |
||
| 65 | foreach ( $ao_ccss_types as $type ) { |
||
| 66 | $optgrp = substr( $type, 0, 3 ); |
||
| 67 | |||
| 68 | // Option groups labels. |
||
| 69 | if ( $optgrp !== $prevgrp && 'is_' !== $optgrp ) { |
||
| 70 | ?> |
||
| 71 | </optgroup> |
||
| 72 | <?php |
||
| 73 | if ( substr( $type, 0, 12 ) === 'custom_post_' ) { |
||
| 74 | ?> |
||
| 75 | <optgroup label="<?php _e( 'Custom Post Types', 'autoptimize' ); ?>"> |
||
| 76 | <?php |
||
| 77 | } elseif ( substr( $type, 0, 9 ) === 'template_' ) { |
||
| 78 | ?> |
||
| 79 | <optgroup label="<?php _e( 'Page Templates', 'autoptimize' ); ?>"> |
||
| 80 | <?php |
||
| 81 | } elseif ( substr( $type, 0, 4 ) === 'bbp_' ) { |
||
| 82 | ?> |
||
| 83 | <optgroup label="<?php _e( 'BBPress Conditional Tags', 'autoptimize' ); ?>"> |
||
| 84 | <?php |
||
| 85 | } elseif ( substr( $type, 0, 3 ) === 'bp_' ) { |
||
| 86 | ?> |
||
| 87 | <optgroup label="<?php _e( 'BuddyPress Conditional Tags', 'autoptimize' ); ?>"> |
||
| 88 | <?php |
||
| 89 | } elseif ( substr( $type, 0, 4 ) === 'edd_' ) { |
||
| 90 | ?> |
||
| 91 | <optgroup label="<?php _e( 'Easy Digital Downloads Conditional Tags', 'autoptimize' ); ?>"> |
||
| 92 | <?php |
||
| 93 | } elseif ( substr( $type, 0, 4 ) === 'woo_' ) { |
||
| 94 | ?> |
||
| 95 | <optgroup label="<?php _e( 'WooCommerce Conditional Tags', 'autoptimize' ); ?>"> |
||
| 96 | <?php |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | // Options. |
||
| 101 | if ( 'is_' !== $optgrp ) { |
||
| 102 | // Remove prefix from custom post types, templates and some specific conditional tags. |
||
| 103 | if ( substr( $type, 0, 12 ) === 'custom_post_' ) { |
||
| 104 | $_type = str_replace( 'custom_post_', '', $type ); |
||
| 105 | } elseif ( substr( $type, 0, 9 ) === 'template_' ) { |
||
| 106 | $_type = str_replace( 'template_', '', $type ); |
||
| 107 | } elseif ( 'bbp_is_bbpress' == $type ) { |
||
| 108 | $_type = str_replace( 'bbp_', '', $type ); |
||
| 109 | } elseif ( 'bp_is_buddypress' == $type ) { |
||
| 110 | $_type = str_replace( 'bp_', '', $type ); |
||
| 111 | } elseif ( substr( $type, 0, 4 ) === 'woo_' ) { |
||
| 112 | $_type = str_replace( 'woo_', '', $type ); |
||
| 113 | } elseif ( substr( $type, 0, 4 ) === 'edd_' ) { |
||
| 114 | $_type = str_replace( 'edd_', '', $type ); |
||
| 115 | } else { |
||
| 116 | $_type = $type; |
||
| 117 | } |
||
| 118 | |||
| 119 | echo '<option value="' . $type . '">' . $_type . '</option>'; |
||
| 120 | $prevgrp = $optgrp; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | ?> |
||
| 124 | </optgroup> |
||
| 125 | </select> |
||
| 126 | </td> |
||
| 127 | </tr> |
||
| 128 | <tr> |
||
| 129 | <th scope="row"> |
||
| 130 | <?php _e( 'Custom Critical CSS', 'autoptimize' ); ?> |
||
| 131 | </th> |
||
| 132 | <td> |
||
| 133 | <textarea id="critcss_addedit_css" rows="13" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your specific critical CSS here and hit submit to save.', 'autoptimize' ); ?>"></textarea> |
||
| 134 | <input type="hidden" id="critcss_addedit_file"> |
||
| 135 | <input type="hidden" id="critcss_addedit_id"> |
||
| 136 | </td> |
||
| 137 | </tr> |
||
| 138 | </table> |
||
| 139 | </div> |
||
| 140 | |||
| 141 | <!-- Remove dialog --> |
||
| 142 | <div id="confirm-rm" title="<?php _e( 'Delete Rule', 'autoptimize' ); ?>" class="hidden"> |
||
| 143 | <p><?php _e( 'This Critical CSS rule will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p> |
||
| 144 | </div> |
||
| 145 | |||
| 146 | <!-- Remove All dialog --> |
||
| 147 | <div id="confirm-rm-all" title="<?php _e( 'Delete all Rules and Jobs', 'autoptimize' ); ?>" class="hidden"> |
||
| 148 | <p><?php _e( 'All Critical CSS rules will be deleted immediately and cannot be recovered.<br /><br /><strong>Are you sure?</strong>', 'autoptimize' ); ?></p> |
||
| 149 | </div> |
||
| 150 | |||
| 151 | <!-- Add/edit default critical CSS dialog --> |
||
| 152 | <div id="default_critcss_wrapper" class="hidden"> |
||
| 153 | <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea> |
||
| 154 | </div> |
||
| 155 | |||
| 156 | <!-- Add/edit additional critical CSS dialog --> |
||
| 157 | <div id="additional_critcss_wrapper" class="hidden"> |
||
| 158 | <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea> |
||
| 159 | </div> |
||
| 160 | |||
| 161 | <!-- Wrapper for in screen notices --> |
||
| 162 | <div id="rules-notices"></div> |
||
| 163 | <!-- END Rule add/edit dialogs --> |
||
| 164 | |||
| 165 | <!-- BEGIN Rules UI --> |
||
| 166 | <div class="howto"> |
||
| 167 | <div class="title-wrap"> |
||
| 168 | <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4> |
||
| 169 | <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p> |
||
| 170 | </div> |
||
| 171 | <button type="button" class="toggle-btn"> |
||
| 172 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
||
| 173 | </button> |
||
| 174 | <div class="howto-wrap hidden"> |
||
| 175 | <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p> |
||
| 176 | <ol> |
||
| 177 | <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li> |
||
| 178 | <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li> |
||
| 179 | <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li> |
||
| 180 | <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li> |
||
| 181 | <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li> |
||
| 182 | <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li> |
||
| 183 | <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li> |
||
| 184 | <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li> |
||
| 185 | </ol> |
||
| 186 | </div> |
||
| 187 | </div> |
||
| 188 | <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_css_defer_inline', '' ); ?></textarea> |
||
| 189 | <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_ccss_additional', '' ); ?></textarea> |
||
| 190 | <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table> |
||
| 191 | <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'> |
||
| 192 | <div class="submit rules-btn"> |
||
| 193 | <div class="alignleft"> |
||
| 194 | <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span> |
||
| 195 | <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span> |
||
| 196 | <span id="editAdditionalButton" class="button-secondary"><?php _e( 'Add CSS To All Rules', 'autoptimize' ); ?></span> |
||
| 197 | </div> |
||
| 198 | <div class="alignright"> |
||
| 199 | <span id="removeAllRules" class="button-secondary" style="color:red;"><?php _e( 'Remove all rules', 'autoptimize' ); ?></span> |
||
| 200 | </div> |
||
| 201 | </div> |
||
| 202 | <!-- END Rules UI --> |
||
| 203 | </li> |
||
| 204 | </ul> |
||
| 205 | <?php |
||
| 206 | } |
||
| 207 | ?> |
||
| 208 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.