| Conditions | 15 |
| Paths | 62 |
| Total Lines | 89 |
| Code Lines | 52 |
| 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 |
||
| 32 | public static function do_migration() { |
||
| 33 | Jetpack_Options::update_option( 'custom_css_4.7_migration', true ); |
||
| 34 | Jetpack::log( 'custom_css_4.7_migration', 'start' ); |
||
| 35 | |||
| 36 | if ( ! post_type_exists( 'safecss' ) ) { |
||
| 37 | self::register_legacy_post_type(); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** This filter is documented in modules/custom-css/custom-css.php */ |
||
| 41 | $preprocessors = apply_filters( 'jetpack_custom_css_preprocessors', array() ); |
||
| 42 | $core_css_post = wp_get_custom_css_post(); |
||
| 43 | $jetpack_css_post = self::get_post(); |
||
| 44 | |||
| 45 | if ( ! $jetpack_css_post ) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | $revisions = self::get_all_revisions(); |
||
|
|
|||
| 50 | |||
| 51 | // Migrate the settings from revision meta to theme mod. |
||
| 52 | $options = self::get_options( $jetpack_css_post->ID ); |
||
| 53 | set_theme_mod( 'jetpack_custom_css', $options ); |
||
| 54 | |||
| 55 | if ( empty( $revisions ) || ! is_array( $revisions ) ) { |
||
| 56 | if ( $jetpack_css_post instanceof WP_Post ) { |
||
| 57 | // Feed in the raw, if the current setting is Sass/LESS, it'll filter it inside. |
||
| 58 | wp_update_custom_css_post( $jetpack_css_post->post_content ); |
||
| 59 | return 1; |
||
| 60 | } |
||
| 61 | return null; |
||
| 62 | } |
||
| 63 | |||
| 64 | $revisions = array_reverse( $revisions ); |
||
| 65 | $themes = Jetpack_Custom_CSS_Enhancements::get_themes(); |
||
| 66 | $migrated = array(); |
||
| 67 | |||
| 68 | foreach ( $revisions as $post_id => $post ) { |
||
| 69 | // Jetpack had stored the theme Name, not the stylesheet directory, for ... reasons. |
||
| 70 | // Get the stylesheet. If null, the theme is no longer available. Skip. |
||
| 71 | $stylesheet = isset( $themes[ $post->post_excerpt ] ) ? $themes[ $post->post_excerpt ] : null; |
||
| 72 | if ( empty( $stylesheet ) ) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | |||
| 76 | $migrated[] = $post->ID; |
||
| 77 | $preprocessor = get_post_meta( $post->ID, 'custom_css_preprocessor', true ); |
||
| 78 | $css = $post->post_content; |
||
| 79 | $pre = ''; |
||
| 80 | |||
| 81 | // Do a revision by revision parsing. |
||
| 82 | if ( $preprocessor && isset( $preprocessors[ $preprocessor ] ) ) { |
||
| 83 | $pre = $css; |
||
| 84 | $css = call_user_func( $preprocessors[ $preprocessor ]['callback'], $pre ); |
||
| 85 | } |
||
| 86 | |||
| 87 | // Do we need to remove any filters here for users without `unfiltered_html` ? |
||
| 88 | wp_update_custom_css_post( $css, array( |
||
| 89 | 'stylesheet' => $stylesheet, |
||
| 90 | 'preprocessed' => $pre, |
||
| 91 | ) ); |
||
| 92 | } |
||
| 93 | |||
| 94 | // If we've migrated some CSS for the current theme and there was already something there in the Core dataset ... |
||
| 95 | if ( $core_css_post && $jetpack_css_post ) { |
||
| 96 | $preprocessor = $options['preprocessor']; |
||
| 97 | |||
| 98 | $css = $core_css_post->post_content; |
||
| 99 | $pre = $core_css_post->post_content_filtered; |
||
| 100 | if ( $preprocessor ) { |
||
| 101 | if ( $pre ) { |
||
| 102 | $pre .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
| 103 | } |
||
| 104 | $pre .= $jetpack_css_post->post_content; |
||
| 105 | |||
| 106 | $css .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
| 107 | $css .= call_user_func( $preprocessors[ $preprocessor ]['callback'], $jetpack_css_post->post_content ); |
||
| 108 | } else { |
||
| 109 | $css .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
| 110 | $css .= $jetpack_css_post->post_content; |
||
| 111 | } |
||
| 112 | |||
| 113 | wp_update_custom_css_post( $css, array( |
||
| 114 | 'preprocessed' => $pre, |
||
| 115 | ) ); |
||
| 116 | } |
||
| 117 | |||
| 118 | Jetpack::log( 'custom_css_4.7_migration', count( $migrated ) . 'revisions migrated' ); |
||
| 119 | return count( $migrated ); |
||
| 120 | } |
||
| 121 | |||
| 241 |
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.