Complex classes like PerfectCMSImageDataExtension 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 PerfectCMSImageDataExtension, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 7 | class PerfectCMSImageDataExtension extends DataExtension | ||
|  | |||
| 8 | { | ||
| 9 | /** | ||
| 10 | * background image for padded images... | ||
| 11 | * | ||
| 12 | * @var string | ||
| 13 | */ | ||
| 14 | private static $perfect_cms_images_background_padding_color = '#cccccc'; | ||
| 15 | |||
| 16 | /*** | ||
| 17 | * sizes of the images | ||
| 18 | * width: 3200 | ||
| 19 | * height: 3200 | ||
| 20 | * folder: "myfolder" | ||
| 21 | * filetype: "try jpg" | ||
| 22 | * | ||
| 23 | * @var array | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | private static $perfect_cms_images_image_definitions = array(); | ||
| 27 | |||
| 28 | /*** | ||
| 29 | * Images Titles will be appended to the links only | ||
| 30 | * if the ClassName of the Image is in this array | ||
| 31 | * @var array | ||
| 32 | * | ||
| 33 | */ | ||
| 34 | private static $perfect_cms_images_append_title_to_image_links_classes = array(); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @var string $name name of Image Field template | ||
| 38 | * @return string (link) | ||
| 39 | */ | ||
| 40 | public function PerfectCMSImageLinkNonRetina($name) | ||
| 44 | |||
| 45 | /** | ||
| 46 | * @var string $name name of Image Field template | ||
| 47 | * @return string (link) | ||
| 48 | */ | ||
| 49 | public function PerfectCMSImageLinkRetina($name) | ||
| 53 | |||
| 54 | /** | ||
| 55 | * @param string $name | ||
| 56 | * @param object (optional) $backupObject | ||
| 57 | * @param string (optional) $backupField | ||
| 58 | * | ||
| 59 | * @return string | ||
| 60 | */ | ||
| 61 | public function PerfectCMSImageLink( | ||
| 154 | |||
| 155 | /** | ||
| 156 | * @param string $name | ||
| 157 | * @param Image (optional) $image | ||
| 158 | * | ||
| 159 | * @return int | ||
| 160 | */ | ||
| 161 | public static function get_width($name) | ||
| 165 | |||
| 166 | /** | ||
| 167 | * @param string $name | ||
| 168 | * @param Image (optional) $image | ||
| 169 | * | ||
| 170 | * @return int | ||
| 171 | */ | ||
| 172 | public static function get_height($name) | ||
| 176 | |||
| 177 | /** | ||
| 178 | * @param string $name | ||
| 179 | * @param Image (optional) $image | ||
| 180 | * | ||
| 181 | * @return string | ||
| 182 | */ | ||
| 183 | public static function get_folder($name) | ||
| 187 | |||
| 188 | /** | ||
| 189 | * @param string $name | ||
| 190 | * @param Image (optional) $image | ||
| 191 | * | ||
| 192 | * @return string | ||
| 193 | */ | ||
| 194 | public static function get_file_type($name) | ||
| 198 | |||
| 199 | /** | ||
| 200 | * @param string $name | ||
| 201 | * @param Image (optional) $image | ||
| 202 | * | ||
| 203 | * @return boolean | ||
| 204 | */ | ||
| 205 | public static function get_enforce_size($name) | ||
| 209 | |||
| 210 | /** | ||
| 211 | * @param string $name | ||
| 212 | * @param int $key | ||
| 213 | * @param mixed $default | ||
| 214 | * | ||
| 215 | * @return mixed | ||
| 216 | */ | ||
| 217 | private static function get_one_value_for_image($name, $key, $default = '') | ||
| 231 | |||
| 232 | /** | ||
| 233 | * @return array | ||
| 234 | */ | ||
| 235 | private static function get_all_values_for_images() | ||
| 239 | |||
| 240 | /** | ||
| 241 | * replace the last instance of a string occurence. | ||
| 242 | * | ||
| 243 | * @param string $search needle | ||
| 244 | * @param string $replace new needle | ||
| 245 | * @param string $subject haystack | ||
| 246 | * | ||
| 247 | * @return string | ||
| 248 | */ | ||
| 249 | private function replaceLastInstance($search, $replace, $subject) | ||
| 260 | |||
| 261 | } | ||
| 262 | 
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.