Complex classes like TranslateScript 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 TranslateScript, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class TranslateScript extends AdminScript |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var string $fileType |
||
| 22 | */ |
||
| 23 | protected $fileType; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string $output |
||
| 27 | */ |
||
| 28 | protected $output; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string $path |
||
| 32 | */ |
||
| 33 | protected $path; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var array $locales |
||
| 37 | */ |
||
| 38 | protected $locales; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Valid arguments: |
||
| 42 | * - path : path/to/files |
||
| 43 | * - type : mustache | php |
||
| 44 | * |
||
| 45 | * @return array |
||
| 46 | */ |
||
| 47 | public function defaultArguments() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param RequestInterface $request A PSR-7 compatible Request instance. |
||
| 73 | * @param ResponseInterface $response A PSR-7 compatible Response instance. |
||
| 74 | * @return ResponseInterface |
||
| 75 | */ |
||
| 76 | public function run(RequestInterface $request, ResponseInterface $response) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $pattern The pattern to search. |
||
| 159 | * @param integer $flags The glob flags. |
||
| 160 | * @return array |
||
| 161 | * @see http://in.php.net/manual/en/function.glob.php#106595 |
||
| 162 | */ |
||
| 163 | public function globRecursive($pattern, $flags = 0) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * BASE URL |
||
| 180 | * Realpath |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function base() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * ARGUMENTS |
||
| 190 | * @return TranslateScript Chainable |
||
| 191 | */ |
||
| 192 | public function getPath() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function path() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return TranslateScript Chainable |
||
| 212 | */ |
||
| 213 | public function getFileType() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function fileType() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | public function file() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns associative array |
||
| 247 | * 'original text' => [ 'translation' => 'translation text', 'context' => 'filename' ] |
||
| 248 | * |
||
| 249 | * @return array |
||
| 250 | */ |
||
| 251 | public function fromCSV() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param array $translations The translations to save in CSV. |
||
| 283 | * @return TranslateScript Chainable |
||
| 284 | */ |
||
| 285 | public function toCSV(array $translations) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @param array $data The translation data. |
||
| 318 | * @return array |
||
| 319 | * @todo multiple langs |
||
| 320 | * data[0] = ORIGINAL |
||
| 321 | * data[1] = TRANSLATION |
||
| 322 | * data[2] = CONTEXT |
||
| 323 | */ |
||
| 324 | public function translateCSV(array $data) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @todo make this optional |
||
| 343 | * @return string lang ident |
||
| 344 | */ |
||
| 345 | public function origLanguage() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Get opposite languages from DATABASE |
||
| 352 | * |
||
| 353 | * @return [type] [description] |
||
| 354 | */ |
||
| 355 | public function oppositeLanguages() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Locales set in config.json |
||
| 374 | * Expects languages | file | default_language |
||
| 375 | * |
||
| 376 | * @return array |
||
| 377 | */ |
||
| 378 | public function locales() |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Columns of CSV file |
||
| 401 | * This is already built to take multiple languages |
||
| 402 | * |
||
| 403 | * @return array |
||
| 404 | */ |
||
| 405 | public function columns() |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @return string |
||
| 424 | */ |
||
| 425 | public function enclosure() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @return string |
||
| 432 | */ |
||
| 433 | public function separator() |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @return integer |
||
| 440 | */ |
||
| 441 | public function maxRecursiveLevel() |
||
| 445 | } |
||
| 446 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.