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 | * @param array $script_dependencies An array of view-side Javascript dependencies to be enqueued. |
||
110 | * |
||
111 | * @return void |
||
112 | */ |
||
113 | public static function load_assets_as_required( $type, $script_dependencies = array() ) { |
||
131 | |||
132 | /** |
||
133 | * Check if an asset exists for a block. |
||
134 | * |
||
135 | * @param string $file Path of the file we are looking for. |
||
136 | * |
||
137 | * @return bool $block_has_asset Does the file exist. |
||
138 | */ |
||
139 | public static function block_has_asset( $file ) { |
||
142 | |||
143 | /** |
||
144 | * Get the version number to use when loading the file. Allows us to bypass cache when developing. |
||
145 | * |
||
146 | * @param string $file Path of the file we are looking for. |
||
147 | * |
||
148 | * @return string $script_version Version number. |
||
149 | */ |
||
150 | public static function get_asset_version( $file ) { |
||
155 | |||
156 | /** |
||
157 | * Load Gutenberg editor assets |
||
158 | * |
||
159 | * @since 6.7.0 |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | public static function enqueue_block_editor_assets() { |
||
220 | } |
||
221 |