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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
9 | class Jetpack_WordAds_Gutenblock { |
||
10 | const BLOCK_NAME = 'jetpack/wordads'; |
||
11 | |||
12 | /** |
||
13 | * Check if site is on WP.com Simple. |
||
14 | * |
||
15 | * @return bool |
||
16 | */ |
||
17 | private static function is_wpcom() { |
||
20 | /** |
||
21 | * Check if the WordAds module is active. |
||
22 | * |
||
23 | * @return bool |
||
24 | */ |
||
25 | private static function is_jetpack_module_active() { |
||
28 | |||
29 | /** |
||
30 | * Check if the site is approved for ads for WP.com Simple sites. |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | private static function is_available() { |
||
41 | |||
42 | /** |
||
43 | * Register the WordAds block. |
||
44 | */ |
||
45 | public static function register() { |
||
55 | |||
56 | /** |
||
57 | * Set if the WordAds block is available. |
||
58 | */ |
||
59 | public static function set_availability() { |
||
67 | |||
68 | /** |
||
69 | * Renders the WordAds block. |
||
70 | * |
||
71 | * @param array $attr Block attributes. |
||
72 | * |
||
73 | * @return string Block HTML. |
||
74 | */ |
||
75 | public static function gutenblock_render( $attr ) { |
||
111 | } |
||
112 | |||
122 |