Complex classes like Language 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 Language, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Language { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | private $row; |
||
| 40 | |||
| 41 | protected static $flagCache; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Holds the exploded fallBackOrderArray |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $defaultFallBackOrderArray; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Holds the exploded elementFallBackOrderArray |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $elementFallBackOrderArray; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Holds the exploded newFallBackOrderArray |
||
| 59 | * |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $newsFallBackOrderArray; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var holds the lg_iso_2 isocode |
||
| 66 | */ |
||
| 67 | protected $lg_iso_2; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param array $row |
||
| 71 | */ |
||
| 72 | public function setData($row) { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Returns the fallback order of this language as array. |
||
| 78 | * |
||
| 79 | * @param Element $contextElement |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | public function getFallbackOrder(Element $contextElement) { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Returns the fallback order for this language for elements |
||
| 94 | * |
||
| 95 | * @param Element $contextElement |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function getFallbackOrderElement(Element $contextElement) { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Returns the fallback order for news elements as array |
||
| 114 | * |
||
| 115 | * @param Element $contextElement |
||
| 116 | * @return array |
||
| 117 | */ |
||
| 118 | public function getFallbackOrderTTNewsElement(Element $contextElement) { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * |
||
| 134 | * @param unknown_type $key |
||
| 135 | * @param unknown_type $fallbackorder |
||
| 136 | * @param Element $contextElement |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | protected function triggerFallbackHooks($key, $fallbackorder, Element $contextElement) { |
||
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * Method to check if complex fallback settings should be used. |
||
| 163 | * |
||
| 164 | * @return boolean |
||
| 165 | */ |
||
| 166 | public function usesComplexFallbackSettings() { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Method to read the defaultVisibility setting of pages. |
||
| 172 | * |
||
| 173 | * @param Element $contextElement |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | public function getDefaultVisibilityForPage(Element $contextElement) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Method to read the defaultVisibility for elements |
||
| 182 | * |
||
| 183 | * @param Element $contextElement |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getDefaultVisibilityForElement(Element $contextElement) { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Method to read the visibility for tt news Elements. |
||
| 192 | * |
||
| 193 | * @param Element $contextElement |
||
| 194 | * @return boolean |
||
| 195 | */ |
||
| 196 | public function getDefaultVisibilityForTTNewsElement(Element $contextElement) { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @param string $key |
||
| 202 | * @param $visibilityDefault |
||
| 203 | * @param Element $contextElement |
||
| 204 | * @return mixed |
||
| 205 | */ |
||
| 206 | protected function triggerDefaultVisibilityHooks($key, $visibilityDefault, Element $contextElement) { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Method to get the primary key of the language record. |
||
| 229 | * |
||
| 230 | * @return int |
||
| 231 | */ |
||
| 232 | public function getUid() { |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Method to determine the lg_iso_2 code from the static languages record. |
||
| 238 | * |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | public function getIsoCode() { |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Returns the title of the language. |
||
| 254 | * |
||
| 255 | * @param $pidForDefault |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getTitle($pidForDefault = '') { |
||
| 270 | |||
| 271 | protected function _guessCurrentPid() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param Optional the pid of the page. This can be used to get the correct flag for default language (which is set in tsconfig) |
||
| 277 | **/ |
||
| 278 | public function getFlagImg($pidForDefault = '') { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param string $pidForDefault |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | protected function getFlagName($pidForDefault = '') { |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param Optional the pid of the page. This can be used to get the correct flagpath for default language (which is set in tsconfig) |
||
| 303 | **/ |
||
| 304 | public function getFlagImgPath($pidForDefault = '', $BACK_PATH = '') { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * checks if the given languageid is part of the fallback of this language |
||
| 322 | * (used for permission options in the backend) |
||
| 323 | * |
||
| 324 | * @param int uid |
||
| 325 | * @param Element $el |
||
| 326 | * @return boolean |
||
| 327 | */ |
||
| 328 | public function isLanguageUidInFallbackOrder($uid, Element $el) { |
||
| 332 | } |
||
| 333 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: