Complex classes like AliasRecord 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 AliasRecord, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class AliasRecord extends Config implements AliasRecordInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $name; |
||
20 | |||
21 | /** |
||
22 | * @inheritdoc |
||
23 | */ |
||
24 | public function __construct(array $data = null, $name = '', $env = '') |
||
32 | |||
33 | /** |
||
34 | * @inheritdoc |
||
35 | */ |
||
36 | public function getConfig(ConfigInterface $config, $key, $default = null) |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | public function name() |
||
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | public function setName($name) |
||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | public function hasRoot() |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | * |
||
71 | * @throws \Exception when the alias does not specify a root. |
||
72 | */ |
||
73 | public function root() |
||
84 | |||
85 | /** |
||
86 | * @inheritdoc |
||
87 | */ |
||
88 | public function uri() |
||
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | */ |
||
96 | public function setUri($uri) |
||
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | public function remoteHostWithUser() |
||
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | public function remoteUser() |
||
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | public function hasRemoteUser() |
||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function remoteHost() |
||
136 | |||
137 | /** |
||
138 | * @inheritdoc |
||
139 | */ |
||
140 | public function isRemote() |
||
141 | { |
||
142 | return $this->has('host') || $this->isDockerCompose(); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @inheritdoc |
||
147 | */ |
||
148 | public function isLocal() |
||
152 | |||
153 | /** |
||
154 | * Does the alias record use the Docker Compose transport. |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function isDockerCompose() |
||
162 | |||
163 | /** |
||
164 | * @inheritdoc |
||
165 | */ |
||
166 | public function isNone() |
||
170 | |||
171 | /** |
||
172 | * @inheritdoc |
||
173 | */ |
||
174 | public function localRoot() |
||
182 | |||
183 | /** |
||
184 | * os returns the OS that this alias record points to. For local alias |
||
185 | * records, PHP_OS will be returned. For remote alias records, the |
||
186 | * value from the `os` element will be returned. If there is no `os` |
||
187 | * element, then the default assumption is that the remote system is Linux. |
||
188 | * |
||
189 | * @return string |
||
190 | * Linux |
||
191 | * WIN* (e.g. WINNT) |
||
192 | * CYGWIN |
||
193 | * MINGW* (e.g. MINGW32) |
||
194 | */ |
||
195 | public function os() |
||
202 | |||
203 | /** |
||
204 | * @inheritdoc |
||
205 | */ |
||
206 | public function exportConfig() |
||
210 | |||
211 | /** |
||
212 | * Reconfigure data exported from the form it is expected to be in |
||
213 | * inside an alias record to the form it is expected to be in when |
||
214 | * inside a configuration file. |
||
215 | */ |
||
216 | protected function remap($data) |
||
230 | |||
231 | /** |
||
232 | * Fetch the parameter-specific options from the 'alias-parameters' section of the alias. |
||
233 | * @param string $parameterName |
||
234 | * @return array |
||
235 | */ |
||
236 | protected function getParameterSpecificOptions($aliasData, $parameterName) |
||
243 | |||
244 | /** |
||
245 | * Convert the data in this record to the layout that was used |
||
246 | * in the legacy code, for backwards compatiblity. |
||
247 | */ |
||
248 | public function legacyRecord() |
||
261 | |||
262 | /** |
||
263 | * Conversion table from old to new option names. These all implicitly |
||
264 | * go in `options`, although they can come from different locations. |
||
265 | */ |
||
266 | protected function remapOptionTable() |
||
277 | } |
||
278 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.