Conditions | 14 |
Paths | 60 |
Total Lines | 85 |
Code Lines | 50 |
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 |
||
14 | public static function do_migration() { |
||
15 | Jetpack_Options::update_option( 'custom_css_4.7_migration', true ); |
||
16 | Jetpack::log( 'custom_css_4.7_migration', 'start' ); |
||
17 | |||
18 | if ( ! post_type_exists( 'safecss' ) ) { |
||
19 | self::register_legacy_post_type(); |
||
20 | } |
||
21 | |||
22 | /** This filter is documented in modules/custom-css/custom-css.php */ |
||
23 | $preprocessors = apply_filters( 'jetpack_custom_css_preprocessors', array() ); |
||
24 | $core_css_post = wp_get_custom_css_post(); |
||
25 | $jetpack_css_post = self::get_post(); |
||
26 | $revisions = self::get_all_revisions(); |
||
27 | |||
28 | // Migrate the settings from revision meta to theme mod. |
||
29 | $options = self::get_options( $jetpack_css_post->ID ); |
||
30 | set_theme_mod( 'jetpack_custom_css', $options ); |
||
31 | |||
32 | if ( empty( $revisions ) || ! is_array( $revisions ) ) { |
||
33 | if ( $jetpack_css_post instanceof WP_Post ) { |
||
|
|||
34 | // Feed in the raw, if the current setting is Sass/LESS, it'll filter it inside. |
||
35 | wp_update_custom_css_post( $jetpack_css_post->post_content ); |
||
36 | return 1; |
||
37 | } |
||
38 | return null; |
||
39 | } |
||
40 | |||
41 | $revisions = array_reverse( $revisions ); |
||
42 | $themes = Jetpack_Custom_CSS_Enhancements::get_themes(); |
||
43 | $migrated = array(); |
||
44 | |||
45 | foreach ( $revisions as $post_id => $post ) { |
||
46 | // Jetpack had stored the theme Name, not the stylesheet directory, for ... reasons. |
||
47 | // Get the stylesheet. If null, the theme is no longer available. Skip. |
||
48 | $stylesheet = isset( $themes[ $post->post_excerpt ] ) ? $themes[ $post->post_excerpt ] : null; |
||
49 | if ( empty( $stylesheet ) ) { |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | $migrated[] = $post->ID; |
||
54 | $preprocessor = get_post_meta( $post->ID, 'custom_css_preprocessor', true ); |
||
55 | $css = $post->post_content; |
||
56 | $pre = ''; |
||
57 | |||
58 | // Do a revision by revision parsing. |
||
59 | if ( $preprocessor && isset( $preprocessors[ $preprocessor ] ) ) { |
||
60 | $pre = $css; |
||
61 | $css = call_user_func( $preprocessors[ $preprocessor ]['callback'], $pre ); |
||
62 | } |
||
63 | |||
64 | // Do we need to remove any filters here for users without `unfiltered_html` ? |
||
65 | |||
66 | wp_update_custom_css_post( $css, array( |
||
67 | 'stylesheet' => $stylesheet, |
||
68 | 'preprocessed' => $pre, |
||
69 | ) ); |
||
70 | } |
||
71 | |||
72 | // If we've migrated some CSS for the current theme and there was already something there in the Core dataset ... |
||
73 | if ( $core_css_post && $jetpack_css_post ) { |
||
74 | $preprocessor = $options['preprocessor']; |
||
75 | |||
76 | $css = $core_css_post->post_content; |
||
77 | $pre = $core_css_post->post_content_filtered; |
||
78 | if ( $preprocessor ) { |
||
79 | if ( $pre ) { |
||
80 | $pre .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
81 | } |
||
82 | $pre .= $jetpack_css_post->post_content; |
||
83 | |||
84 | $css .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
85 | $css .= call_user_func( $preprocessors[ $preprocessor ]['callback'], $jetpack_css_post->post_content ); |
||
86 | } else { |
||
87 | $css .= "\r\n\r\n/*\r\n\t" . esc_js( __( 'CSS Migrated from Jetpack:', 'jetpack' ) ) . "\r\n*/\r\n\r\n"; |
||
88 | $css .= $jetpack_css_post->post_content; |
||
89 | } |
||
90 | |||
91 | wp_update_custom_css_post( $css, array( |
||
92 | 'preprocessed' => $pre, |
||
93 | ) ); |
||
94 | } |
||
95 | |||
96 | Jetpack::log( 'custom_css_4.7_migration', sizeof( $migrated ) . 'revisions migrated' ); |
||
97 | return sizeof( $migrated ); |
||
98 | } |
||
99 | |||
201 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.