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 | * @deprecated 8.8.0 Use Status->is_offline_mode(). |
||
| 20 | * |
||
| 21 | * @return bool Whether Jetpack's offline mode is active. |
||
| 22 | */ |
||
| 23 | public function is_development_mode() { |
||
| 24 | _deprecated_function( __FUNCTION__, 'Jetpack 8.8.0', 'Automattic\Jetpack\Status->is_offline_mode' ); |
||
| 25 | return $this->is_offline_mode(); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Is Jetpack in offline mode? |
||
| 30 | * |
||
| 31 | * This was formerly called "Development Mode", but sites "in development" aren't always offline/localhost. |
||
| 32 | * |
||
| 33 | * @since 8.8.0 |
||
| 34 | * |
||
| 35 | * @return bool Whether Jetpack's offline mode is active. |
||
| 36 | */ |
||
| 37 | public function is_offline_mode() { |
||
| 38 | $offline_mode = false; |
||
| 39 | |||
| 40 | if ( defined( '\\JETPACK_DEV_DEBUG' ) ) { |
||
| 41 | $offline_mode = constant( '\\JETPACK_DEV_DEBUG' ); |
||
| 42 | } elseif ( defined( '\\WP_LOCAL_DEV' ) ) { |
||
| 43 | $offline_mode = constant( '\\WP_LOCAL_DEV' ); |
||
| 44 | } elseif ( $this->is_local_site() ) { |
||
| 45 | $offline_mode = true; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Filters Jetpack's offline mode. |
||
| 50 | * |
||
| 51 | * @see https://jetpack.com/support/development-mode/ |
||
| 52 | * @todo Update documentation ^^. |
||
| 53 | * |
||
| 54 | * @since 2.2.1 |
||
| 55 | * @deprecated 8.8.0 |
||
| 56 | * |
||
| 57 | * @param bool $offline_mode Is Jetpack's offline mode active. |
||
| 58 | */ |
||
| 59 | $offline_mode = (bool) apply_filters_deprecated( 'jetpack_development_mode', array( $offline_mode ), '8.8.0', 'jetpack_offline_mode' ); |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Filters Jetpack's offline mode. |
||
| 63 | * |
||
| 64 | * @see https://jetpack.com/support/development-mode/ |
||
| 65 | * @todo Update documentation ^^. |
||
| 66 | * |
||
| 67 | * @since 8.8.0 |
||
| 68 | * |
||
| 69 | * @param bool $offline_mode Is Jetpack's offline mode active. |
||
| 70 | */ |
||
| 71 | $offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode ); |
||
| 72 | |||
| 73 | return $offline_mode; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Whether this is a system with a multiple networks. |
||
| 78 | * Implemented since there is no core is_multi_network function. |
||
| 79 | * Right now there is no way to tell which network is the dominant network on the system. |
||
| 80 | * |
||
| 81 | * @return boolean |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function is_multi_network() { |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Whether the current site is single user site. |
||
| 101 | * |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function is_single_user_site() { |
|
| 114 | |||
| 115 | /** |
||
| 116 | * If the site is a local site. |
||
| 117 | * |
||
| 118 | * @since 8.8.0 |
||
| 119 | * |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | public function is_local_site() { |
||
| 161 | |||
| 162 | /** |
||
| 163 | * If is a staging site. |
||
| 164 | * |
||
| 165 | * @todo Add IDC detection to a package. |
||
| 166 | * |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | public function is_staging_site() { |
||
| 241 | } |
||
| 242 |