Complex classes like WindowsCommon 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 WindowsCommon, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class WindowsCommon extends \core\DeviceConfig { |
||
28 | |||
29 | public function copyBasicFiles() { |
||
30 | if (!($this->copyFile('wlan_test.exe') && |
||
31 | $this->copyFile('check_wired.cmd') && |
||
32 | $this->copyFile('install_wired.cmd') && |
||
33 | $this->copyFile('cat_bg.bmp') && |
||
34 | $this->copyFile('base64.nsh'))) { |
||
35 | throw new Exception("Copying needed files (part 1) failed for at least one file!"); |
||
36 | } |
||
37 | |||
38 | if (!($this->copyFile('cat32.ico') && |
||
39 | $this->copyFile('cat_150.bmp') && |
||
40 | $this->copyFile('WLANSetEAPUserData/WLANSetEAPUserData32.exe', 'WLANSetEAPUserData32.exe') && |
||
41 | $this->copyFile('WLANSetEAPUserData/WLANSetEAPUserData64.exe', 'WLANSetEAPUserData64.exe'))) { |
||
42 | throw new Exception("Copying needed files (part 2) failed for at least one file!"); |
||
43 | } |
||
44 | if (!$this->translateFile('common.inc', 'common.nsh', $this->codePage)) { |
||
45 | throw new Exception("Translating needed file common.inc failed!"); |
||
46 | } |
||
47 | return; |
||
48 | } |
||
49 | |||
50 | public function copyPwdFiles() { |
||
51 | if (!($this->copyFile('Aruba_Networks_EAP-pwd_x32.msi') && |
||
52 | $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi'))) { |
||
53 | throw new Exception("Copying needed files (EAP-pwd) failed for at least one file!"); |
||
54 | } |
||
55 | if (!$this->translateFile('pwd.inc', 'cat.NSI', $this->codePage)) { |
||
56 | throw new Exception("Translating needed file pwd.inc failed!"); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | public function copyGeantLinkFiles() { |
||
61 | if (!($this->copyFile('GEANTLink/GEANTLink32.msi', 'GEANTLink32.msi') && |
||
62 | $this->copyFile('GEANTLink/GEANTLink64.msi', 'GEANTLink64.msi') && |
||
63 | $this->copyFile('GEANTLink/CredWrite.exe', 'CredWrite.exe') && |
||
64 | $this->copyFile('GEANTLink/MsiUseFeature.exe', 'MsiUseFeature.exe'))) { |
||
65 | throw new Exception("Copying needed files (GEANTLink) failed for at least one file!"); |
||
66 | } |
||
67 | if (!$this->translateFile('geant_link.inc', 'cat.NSI', $this->codePage)) { |
||
68 | throw new Exception("Translating needed file geant_link.inc failed!"); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | |||
73 | /** |
||
74 | * function to escape double quotes in a special NSI-compatible way |
||
75 | * |
||
76 | * @param string $in input string |
||
77 | * @return string |
||
78 | */ |
||
79 | public static function echo_nsi($in) { |
||
80 | echo preg_replace('/"/', '$\"', $in); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param string $input input string |
||
85 | * @return string |
||
86 | */ |
||
87 | public static function sprint_nsi($input) { |
||
88 | return preg_replace('/"/', '$\"', $input); |
||
89 | } |
||
90 | |||
91 | public function __construct() { |
||
92 | parent::__construct(); |
||
93 | $this->useGeantLink = (isset($this->options['args']) && $this->options['args'] == 'gl' ) ? 1 : 0; |
||
94 | } |
||
95 | |||
96 | protected function prepareInstallerLang() { |
||
106 | |||
107 | public function writeDeviceInfo() { |
||
108 | $ssidCount = count($this->attributes['internal:SSID']); |
||
109 | $out = "<p>"; |
||
110 | $out .= sprintf(_("%s installer will be in the form of an EXE file. It will configure %s on your device, by creating wireless network profiles.<p>When you click the download button, the installer will be saved by your browser. Copy it to the machine you want to configure and execute."), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name'], CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']); |
||
111 | $out .= "<p>"; |
||
112 | if ($ssidCount > 1) { |
||
140 | |||
141 | private function scaleLogo($imagePath, $maxSize) { |
||
160 | |||
161 | protected function combineLogo($logos = NULL, $fedLogo = NULL) { |
||
205 | |||
206 | protected function signInstaller() { |
||
219 | |||
220 | protected function compileNSIS() { |
||
230 | |||
231 | protected function msInfoFile($attr) { |
||
258 | |||
259 | protected function writeAdditionalDeletes($profiles) { |
||
270 | |||
271 | protected function writeClientP12File() { |
||
279 | |||
280 | protected function writeTlsUserProfile() { |
||
283 | |||
284 | public $LANGS = [ |
||
285 | 'fr' => ['nsis' => "French", 'cp' => '1252'], |
||
286 | 'de' => ['nsis' => "German", 'cp' => '1252'], |
||
287 | 'es' => ['nsis' => "SpanishInternational", 'cp' => '1252'], |
||
288 | 'it' => ['nsis' => "Italian", 'cp' => '1252'], |
||
289 | 'nl' => ['nsis' => "Dutch", 'cp' => '1252'], |
||
290 | 'sv' => ['nsis' => "Swedish", 'cp' => '1252'], |
||
291 | 'fi' => ['nsis' => "Finnish", 'cp' => '1252'], |
||
292 | 'pl' => ['nsis' => "Polish", 'cp' => '1250'], |
||
293 | 'ca' => ['nsis' => "Catalan", 'cp' => '1252'], |
||
294 | 'sr' => ['nsis' => "SerbianLatin", 'cp' => '1250'], |
||
295 | 'hr' => ['nsis' => "Croatian", 'cp' => '1250'], |
||
296 | 'sl' => ['nsis' => "Slovenian", 'cp' => '1250'], |
||
297 | 'da' => ['nsis' => "Danish", 'cp' => '1252'], |
||
298 | 'nb' => ['nsis' => "Norwegian", 'cp' => '1252'], |
||
299 | 'nn' => ['nsis' => "NorwegianNynorsk", 'cp' => '1252'], |
||
300 | 'el' => ['nsis' => "Greek", 'cp' => '1253'], |
||
301 | 'ru' => ['nsis' => "Russian", 'cp' => '1251'], |
||
302 | 'pt' => ['nsis' => "Portuguese", 'cp' => '1252'], |
||
303 | 'uk' => ['nsis' => "Ukrainian", 'cp' => '1251'], |
||
304 | 'cs' => ['nsis' => "Czech", 'cp' => '1250'], |
||
305 | 'sk' => ['nsis' => "Slovak", 'cp' => '1250'], |
||
306 | 'bg' => ['nsis' => "Bulgarian", 'cp' => '1251'], |
||
307 | 'hu' => ['nsis' => "Hungarian", 'cp' => '1250'], |
||
308 | 'ro' => ['nsis' => "Romanian", 'cp' => '1250'], |
||
309 | 'lv' => ['nsis' => "Latvian", 'cp' => '1257'], |
||
310 | 'mk' => ['nsis' => "Macedonian", 'cp' => '1251'], |
||
311 | 'et' => ['nsis' => "Estonian", 'cp' => '1257'], |
||
312 | 'tr' => ['nsis' => "Turkish", 'cp' => '1254'], |
||
313 | 'lt' => ['nsis' => "Lithuanian", 'cp' => '1257'], |
||
314 | 'ar' => ['nsis' => "Arabic", 'cp' => '1256'], |
||
315 | 'he' => ['nsis' => "Hebrew", 'cp' => '1255'], |
||
316 | 'id' => ['nsis' => "Indonesian", 'cp' => '1252'], |
||
317 | 'mn' => ['nsis' => "Mongolian", 'cp' => '1251'], |
||
318 | 'sq' => ['nsis' => "Albanian", 'cp' => '1252'], |
||
319 | 'br' => ['nsis' => "Breton", 'cp' => '1252'], |
||
320 | 'be' => ['nsis' => "Belarusian", 'cp' => '1251'], |
||
321 | 'is' => ['nsis' => "Icelandic", 'cp' => '1252'], |
||
322 | 'ms' => ['nsis' => "Malay", 'cp' => '1252'], |
||
323 | 'bs' => ['nsis' => "Bosnian", 'cp' => '1250'], |
||
324 | 'ga' => ['nsis' => "Irish", 'cp' => '1250'], |
||
325 | 'uz' => ['nsis' => "Uzbek", 'cp' => '1251'], |
||
326 | 'gl' => ['nsis' => "Galician", 'cp' => '1252'], |
||
327 | 'af' => ['nsis' => "Afrikaans", 'cp' => '1252'], |
||
328 | 'ast' => ['nsis' => "Asturian", 'cp' => '1252'], |
||
329 | ]; |
||
330 | public $codePage; |
||
331 | public $lang; |
||
332 | public $useGeantLink; |
||
333 | public $background; |
||
334 | |||
335 | } |
||
336 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.