Complex classes like EEH_Schema often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EEH_Schema, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 11 | class EEH_Schema  | 
            ||
| 12 | { | 
            ||
| 13 | |||
| 14 | |||
| 15 | /**  | 
            ||
| 16 | * generates JSON-based linked data for an event  | 
            ||
| 17 | *  | 
            ||
| 18 | * @param EE_Event $event  | 
            ||
| 19 | * @throws EE_Error  | 
            ||
| 20 | */  | 
            ||
| 21 | public static function add_json_linked_data_for_event(EE_Event $event)  | 
            ||
| 117 | |||
| 118 | |||
| 119 | /**  | 
            ||
| 120 | * location  | 
            ||
| 121 | * The location of the event, organization or action.  | 
            ||
| 122 | * Should include the Venue name AND schema formatted address info  | 
            ||
| 123 | *  | 
            ||
| 124 | * @access public  | 
            ||
| 125 | * @param string $location  | 
            ||
| 126 | * @return string  | 
            ||
| 127 | */  | 
            ||
| 128 | public static function location($location = null)  | 
            ||
| 134 | |||
| 135 | |||
| 136 | |||
| 137 | /**  | 
            ||
| 138 | * name  | 
            ||
| 139 | * The name of the Event or Venue.  | 
            ||
| 140 | *  | 
            ||
| 141 | * @access public  | 
            ||
| 142 | * @param string $name  | 
            ||
| 143 | * @return string  | 
            ||
| 144 | */  | 
            ||
| 145 | public static function name($name = null)  | 
            ||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | /**  | 
            ||
| 153 | * streetAddress  | 
            ||
| 154 | * The street address. For example, 1600 Amphitheatre Pkwy.  | 
            ||
| 155 | *  | 
            ||
| 156 | * @access public  | 
            ||
| 157 | * @param EEI_Address $obj_with_address  | 
            ||
| 158 | * @return string  | 
            ||
| 159 | */  | 
            ||
| 160 | public static function streetAddress(EEI_Address $obj_with_address = null)  | 
            ||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | /**  | 
            ||
| 169 | * postOfficeBoxNumber  | 
            ||
| 170 | * The post office box number for PO box addresses.  | 
            ||
| 171 | *  | 
            ||
| 172 | * @access public  | 
            ||
| 173 | * @param EEI_Address $obj_with_address  | 
            ||
| 174 | * @return string  | 
            ||
| 175 | */  | 
            ||
| 176 | public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null)  | 
            ||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | /**  | 
            ||
| 193 | * addressLocality  | 
            ||
| 194 | * The locality (city, town, etc). For example, Mountain View.  | 
            ||
| 195 | *  | 
            ||
| 196 | * @access public  | 
            ||
| 197 | * @param EEI_Address $obj_with_address  | 
            ||
| 198 | * @return string  | 
            ||
| 199 | */  | 
            ||
| 200 | public static function addressLocality(EEI_Address $obj_with_address = null)  | 
            ||
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | /**  | 
            ||
| 209 | * addressRegion  | 
            ||
| 210 | * The region (state, province, etc). For example, CA.  | 
            ||
| 211 | *  | 
            ||
| 212 | * @access public  | 
            ||
| 213 | * @param EEI_Address $obj_with_address  | 
            ||
| 214 | * @return string  | 
            ||
| 215 | */  | 
            ||
| 216 | public static function addressRegion(EEI_Address $obj_with_address = null)  | 
            ||
| 225 | |||
| 226 | |||
| 227 | |||
| 228 | /**  | 
            ||
| 229 | * addressCountry  | 
            ||
| 230 | * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.  | 
            ||
| 231 | *  | 
            ||
| 232 | * @access public  | 
            ||
| 233 | * @param EEI_Address $obj_with_address  | 
            ||
| 234 | * @return string  | 
            ||
| 235 | */  | 
            ||
| 236 | public static function addressCountry(EEI_Address $obj_with_address = null)  | 
            ||
| 245 | |||
| 246 | |||
| 247 | |||
| 248 | /**  | 
            ||
| 249 | * postalCode  | 
            ||
| 250 | * The postal code. For example, 94043.  | 
            ||
| 251 | *  | 
            ||
| 252 | * @access public  | 
            ||
| 253 | * @param EEI_Address $obj_with_address  | 
            ||
| 254 | * @return string  | 
            ||
| 255 | */  | 
            ||
| 256 | public static function postalCode(EEI_Address $obj_with_address = null)  | 
            ||
| 262 | |||
| 263 | |||
| 264 | |||
| 265 | /**  | 
            ||
| 266 | * telephone  | 
            ||
| 267 | * The telephone number.  | 
            ||
| 268 | *  | 
            ||
| 269 | * @access public  | 
            ||
| 270 | * @param string $phone_nmbr  | 
            ||
| 271 | * @return string  | 
            ||
| 272 | */  | 
            ||
| 273 | public static function telephone($phone_nmbr = null)  | 
            ||
| 278 | |||
| 279 | |||
| 280 | |||
| 281 | /**  | 
            ||
| 282 | * URL  | 
            ||
| 283 | * URL of the item as a clickable link  | 
            ||
| 284 | *  | 
            ||
| 285 | * @access public  | 
            ||
| 286 | * @param string $url - the URL that the link will resolve to  | 
            ||
| 287 | * @param string $text - the text that will be used for the visible link  | 
            ||
| 288 | * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )  | 
            ||
| 289 | * @return string (link)  | 
            ||
| 290 | */  | 
            ||
| 291 | public static function url($url = null, $text = null, $attributes = array())  | 
            ||
| 307 | }  | 
            ||
| 308 | 
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: