Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 28 | class Jetpack_Gutenberg { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Array of blocks we will be registering. |
||
| 32 | * |
||
| 33 | * @var array $blocks Array of blocks we will be registering. |
||
| 34 | */ |
||
| 35 | public static $blocks = array(); |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Add a block to the list of blocks to be registered. |
||
| 39 | * |
||
| 40 | * @param string $type Slug of the block. |
||
| 41 | * @param array $args Arguments that are passed into the register_block_type. |
||
| 42 | */ |
||
| 43 | public static function add_block( $type, $args ) { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Register all Jetpack blocks available. |
||
| 49 | * |
||
| 50 | * @return void|WP_Block_Type|false The registered block type on success, or false on failure. |
||
| 51 | */ |
||
| 52 | public static function load_blocks() { |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Check if Gutenberg editor is available |
||
| 71 | * |
||
| 72 | * @since 6.7.0 |
||
| 73 | * |
||
| 74 | * @return bool |
||
| 75 | */ |
||
| 76 | public static function is_gutenberg_available() { |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Check whether conditions indicate Gutenberg blocks should be loaded |
||
| 82 | * |
||
| 83 | * Loading blocks is enabled by default and may be disabled via filter: |
||
| 84 | * add_filter( 'jetpack_gutenberg', '__return_false' ); |
||
| 85 | * |
||
| 86 | * @since 6.7.0 |
||
| 87 | * |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | public static function should_load_blocks() { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Only enqueue block assets when needed. |
||
| 107 | * |
||
| 108 | * @param string $type slug of the block. |
||
| 109 | * |
||
| 110 | * @return void |
||
| 111 | */ |
||
| 112 | public static function load_assets_as_required( $type ) { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Check if an asset exists for a block. |
||
| 133 | * |
||
| 134 | * @param string $file Path of the file we are looking for. |
||
| 135 | * |
||
| 136 | * @return bool $block_has_asset Does the file exist. |
||
| 137 | */ |
||
| 138 | public static function block_has_asset( $file ) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Get the version number to use when loading the file. Allows us to bypass cache when developing. |
||
| 144 | * |
||
| 145 | * @param string $file Path of the file we are looking for. |
||
| 146 | * |
||
| 147 | * @return string $script_version Version number. |
||
| 148 | */ |
||
| 149 | public static function get_asset_version( $file ) { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Load Gutenberg editor assets |
||
| 157 | * |
||
| 158 | * @since 6.7.0 |
||
| 159 | * |
||
| 160 | * @return void |
||
| 161 | */ |
||
| 162 | public static function enqueue_block_editor_assets() { |
||
| 219 | } |
||
| 220 |