| Conditions | 4 |
| Paths | 6 |
| Total Lines | 57 |
| 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 |
||
| 33 | function enqueue_block_editor_assets() { |
||
| 34 | |||
| 35 | //enqueue foogallery dependencies |
||
| 36 | wp_enqueue_script( 'masonry' ); |
||
| 37 | foogallery_enqueue_core_gallery_template_script(); |
||
| 38 | foogallery_enqueue_core_gallery_template_style(); |
||
| 39 | |||
| 40 | $deps = array( |
||
| 41 | 'wp-blocks', |
||
| 42 | 'wp-i18n', |
||
| 43 | 'wp-element', |
||
| 44 | 'wp-components', |
||
| 45 | 'wp-editor', |
||
| 46 | 'foogallery-core' |
||
| 47 | ); |
||
| 48 | |||
| 49 | $js_url = plugins_url( 'gutenberg/dist/blocks.build.js', dirname( __FILE__ ) ); |
||
| 50 | |||
| 51 | // Scripts. |
||
| 52 | wp_enqueue_script( |
||
| 53 | 'foogallery-block-js', // Handle. |
||
| 54 | $js_url, // Block.build.js: We register the block here. Built with Webpack. |
||
| 55 | $deps, // Dependencies, defined above. |
||
| 56 | // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time. |
||
| 57 | true // Enqueue the script in the footer. |
||
| 58 | ); |
||
| 59 | |||
| 60 | // Styles. |
||
| 61 | wp_enqueue_style( |
||
| 62 | 'foogallery-block-editor-css', // Handle. |
||
| 63 | plugins_url( 'gutenberg/dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS. |
||
| 64 | array( 'wp-edit-blocks', 'foogallery-core' ) // Dependency to include the CSS after it. |
||
| 65 | // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time. |
||
| 66 | ); |
||
| 67 | |||
| 68 | $local_data = false; |
||
| 69 | |||
| 70 | if ( function_exists( 'wp_get_jed_locale_data' ) ) { |
||
| 71 | $local_data = wp_get_jed_locale_data( 'foogallery' ); |
||
| 72 | } else if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) { |
||
| 73 | $local_data = gutenberg_get_jed_locale_data( 'foogallery' ); |
||
| 74 | } |
||
| 75 | |||
| 76 | if ( false !== $local_data ) { |
||
| 77 | |||
| 78 | /* |
||
| 79 | * Pass already loaded translations to our JavaScript. |
||
| 80 | * |
||
| 81 | * This happens _before_ our JavaScript runs, afterwards it's too late. |
||
| 82 | */ |
||
| 83 | wp_add_inline_script( |
||
| 84 | 'foogallery-block-js', |
||
| 85 | 'wp.i18n.setLocaleData( ' . json_encode( $local_data ) . ', "foogallery" );', |
||
| 86 | 'before' |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 147 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.