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  | 
            ||
| 13 | class Jetpack_Calypsoify { | 
            ||
| 14 | |||
| 15 | /**  | 
            ||
| 16 | * Singleton instance of `Jetpack_Calypsoify`.  | 
            ||
| 17 | *  | 
            ||
| 18 | * @var object  | 
            ||
| 19 | */  | 
            ||
| 20 | public static $instance = false;  | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * Is Calypsoify enabled, based on any value of `calypsoify` user meta.  | 
            ||
| 24 | *  | 
            ||
| 25 | * @var bool  | 
            ||
| 26 | */  | 
            ||
| 27 | public $is_calypsoify_enabled = false;  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * Jetpack_Calypsoify constructor.  | 
            ||
| 31 | */  | 
            ||
| 32 | 	private function __construct() { | 
            ||
| 35 | |||
| 36 | /**  | 
            ||
| 37 | * Original singleton.  | 
            ||
| 38 | *  | 
            ||
| 39 | * @todo We need to leave this in place until wpcomsh is updated. wpcomsh can be updated once 9.3.0 is stable.  | 
            ||
| 40 | *  | 
            ||
| 41 | * Deprecated 9.3.0  | 
            ||
| 42 | *  | 
            ||
| 43 | * @return Jetpack_Calypsoify  | 
            ||
| 44 | */  | 
            ||
| 45 | 	public static function getInstance() { //phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * Singleton.  | 
            ||
| 52 | *  | 
            ||
| 53 | * @return Jetpack_Calypsoify  | 
            ||
| 54 | */  | 
            ||
| 55 | 	public static function get_instance() { | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Setup function that is loaded on the `wp_loaded` hook via the constructor.  | 
            ||
| 65 | */  | 
            ||
| 66 | 	public function setup() { | 
            ||
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * Enqueues scripts, data, and styles for Gutenberg.  | 
            ||
| 78 | */  | 
            ||
| 79 | 	public function enqueue_for_gutenberg() { | 
            ||
| 94 | |||
| 95 | /**  | 
            ||
| 96 | * Returns the Calypso domain that originated the current request.  | 
            ||
| 97 | *  | 
            ||
| 98 | * @return string  | 
            ||
| 99 | */  | 
            ||
| 100 | 	private function get_calypso_origin() { | 
            ||
| 111 | |||
| 112 | /**  | 
            ||
| 113 | * Returns the Calypso URL that displays either the current post type list (if no args  | 
            ||
| 114 | * are supplied) or the classic editor for the current post (if a post ID is supplied).  | 
            ||
| 115 | *  | 
            ||
| 116 | * @param int|null $post_id Post ID.  | 
            ||
| 117 | *  | 
            ||
| 118 | * @return string  | 
            ||
| 119 | */  | 
            ||
| 120 | 	public function get_calypso_url( $post_id = null ) { | 
            ||
| 140 | |||
| 141 | /**  | 
            ||
| 142 | * Returns the URL to be used on the block editor close button for going back to the  | 
            ||
| 143 | * Calypso post list.  | 
            ||
| 144 | *  | 
            ||
| 145 | * @return string  | 
            ||
| 146 | */  | 
            ||
| 147 | 	public function get_close_gutenberg_url() { | 
            ||
| 150 | |||
| 151 | /**  | 
            ||
| 152 | * Returns the URL for switching the user's editor to the Calypso (WordPress.com Classic) editor.  | 
            ||
| 153 | *  | 
            ||
| 154 | * @return string  | 
            ||
| 155 | */  | 
            ||
| 156 | 	public function get_switch_to_classic_editor_url() { | 
            ||
| 163 | |||
| 164 | /**  | 
            ||
| 165 | * Checks if the calypsoify user meta value is set, and deletes it if it is.  | 
            ||
| 166 | * This is to ensure that Calypsoify is not activated without the URL parameter.  | 
            ||
| 167 | */  | 
            ||
| 168 | 	public function check_meta() { | 
            ||
| 173 | |||
| 174 | /**  | 
            ||
| 175 | * Return whether a post type should display the Gutenberg/block editor.  | 
            ||
| 176 | *  | 
            ||
| 177 | * @since 6.7.0  | 
            ||
| 178 | *  | 
            ||
| 179 | * @param string $post_type Post type.  | 
            ||
| 180 | */  | 
            ||
| 181 | 	public function is_post_type_gutenberg( $post_type ) { | 
            ||
| 184 | |||
| 185 | /**  | 
            ||
| 186 | * Determines if the page is an instance of the Gutenberg block editor.  | 
            ||
| 187 | *  | 
            ||
| 188 | * @return bool  | 
            ||
| 189 | */  | 
            ||
| 190 | 	public function is_page_gutenberg() { | 
            ||
| 221 | |||
| 222 | }  | 
            ||
| 223 | |||
| 225 |