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 |
||
15 | class Status { |
||
16 | /** |
||
17 | * Is Jetpack in development (offline) mode? |
||
18 | * |
||
19 | * @return bool Whether Jetpack's development mode is active. |
||
20 | */ |
||
21 | public function is_development_mode() { |
||
22 | $development_mode = false; |
||
23 | $site_url = site_url(); |
||
24 | |||
25 | if ( defined( '\\JETPACK_DEV_DEBUG' ) ) { |
||
26 | $development_mode = constant( '\\JETPACK_DEV_DEBUG' ); |
||
27 | } elseif ( $site_url ) { |
||
28 | $development_mode = false === strpos( $site_url, '.' ); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Filters Jetpack's development mode. |
||
33 | * |
||
34 | * @see https://jetpack.com/support/development-mode/ |
||
35 | * |
||
36 | * @since 2.2.1 |
||
37 | * |
||
38 | * @param bool $development_mode Is Jetpack's development mode active. |
||
39 | */ |
||
40 | $development_mode = (bool) apply_filters( 'jetpack_development_mode', $development_mode ); |
||
41 | |||
42 | return $development_mode; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Whether this is a system with a multiple networks. |
||
47 | * Implemented since there is no core is_multi_network function. |
||
48 | * Right now there is no way to tell which network is the dominant network on the system. |
||
49 | * |
||
50 | * @return boolean |
||
51 | */ |
||
52 | View Code Duplication | public function is_multi_network() { |
|
67 | |||
68 | /** |
||
69 | * Whether the current site is single user site. |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | View Code Duplication | public function is_single_user_site() { |
|
83 | |||
84 | /** |
||
85 | * If is a staging site. |
||
86 | * |
||
87 | * @todo Add IDC detection to a package. |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function is_staging_site() { |
||
152 | } |
||
153 |