Complex classes like GherkinToDusk 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 GherkinToDusk, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class GherkinToDusk extends BaseGherkinToDusk |
||
19 | { |
||
20 | use BuildOutContent; |
||
21 | |||
22 | protected $component = false; |
||
23 | |||
24 | protected $string_contents = null; |
||
25 | |||
26 | /** |
||
27 | * Yml Content of a test yml |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $feature_content; |
||
31 | |||
32 | /** |
||
33 | * @var \Behat\Gherkin\Node\FeatureNode |
||
34 | */ |
||
35 | protected $parsed_feature; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | */ |
||
40 | protected $dusk_class_and_methods; |
||
41 | |||
42 | protected $dusk_test_name; |
||
43 | |||
44 | /** |
||
45 | * @var WritePHPUnitFile |
||
46 | */ |
||
47 | protected $write_unit_test; |
||
48 | |||
49 | /** |
||
50 | * @var WriteBrowserFile |
||
51 | */ |
||
52 | protected $write_browser_test; |
||
53 | |||
54 | 27 | public function initializeFeature() |
|
78 | |||
79 | 6 | protected function featureToBrowser() |
|
89 | |||
90 | 21 | protected function featureToUnit() |
|
100 | |||
101 | /** |
||
102 | * @return Parser |
||
103 | */ |
||
104 | 30 | public function getParser() |
|
108 | |||
109 | /** |
||
110 | * @param Parser $parser |
||
111 | */ |
||
112 | public function setParser($parser) |
||
116 | |||
117 | /** |
||
118 | * @return boolean |
||
119 | */ |
||
120 | public function isComponent() |
||
124 | |||
125 | /** |
||
126 | * @param boolean $component |
||
127 | */ |
||
128 | public function setComponent($component) |
||
132 | |||
133 | /** |
||
134 | * @return mixed |
||
135 | */ |
||
136 | 3 | public function getFeatureContent() |
|
140 | |||
141 | /** |
||
142 | * @param mixed $feature_content |
||
143 | */ |
||
144 | public function setFeatureContent($feature_content) |
||
148 | |||
149 | 27 | private function loadFileContent() |
|
154 | |||
155 | 27 | private function passThroughParser() |
|
159 | |||
160 | /** |
||
161 | * @return \Behat\Gherkin\Node\FeatureNode |
||
162 | */ |
||
163 | 3 | public function getParsedFeature() |
|
167 | |||
168 | /** |
||
169 | * @param \Behat\Gherkin\Node\FeatureNode $parsed_feature |
||
170 | */ |
||
171 | public function setParsedFeature($parsed_feature) |
||
175 | |||
176 | 27 | private function breakIntoMethods() |
|
180 | |||
181 | 27 | private function iterateOverScenariosAndBuildUpClassMethods() |
|
197 | |||
198 | /** |
||
199 | * @param $scenario \Behat\Gherkin\Node\ScenarioNode |
||
200 | */ |
||
201 | 27 | protected function buildOutSteps($scenario, $scenario_index) |
|
212 | |||
213 | 27 | private function buildDuskTestName() |
|
220 | |||
221 | 27 | private function getFullPathToFileAndFileName() |
|
225 | |||
226 | /** |
||
227 | * @return mixed |
||
228 | */ |
||
229 | 24 | public function getDuskClassAndMethods() |
|
233 | |||
234 | /** |
||
235 | * @param mixed $dusk_class_and_methods |
||
236 | */ |
||
237 | public function setDuskClassAndMethods($dusk_class_and_methods) |
||
241 | |||
242 | /** |
||
243 | * @return mixed |
||
244 | */ |
||
245 | 27 | public function getDuskTestName() |
|
249 | |||
250 | /** |
||
251 | * @param mixed $dusk_test_name |
||
252 | */ |
||
253 | public function setDuskTestName($dusk_test_name) |
||
257 | |||
258 | 6 | public function getWriteBrowserTest() |
|
267 | |||
268 | /** |
||
269 | * @param null $write_browser_test |
||
270 | * @return GherkinToDusk |
||
271 | * @internal param WritePHPUnitFile $write_unit_test |
||
272 | */ |
||
273 | 6 | public function setWriteBrowserTest($write_browser_test = null) |
|
282 | |||
283 | 18 | public function getWriteUnitTest() |
|
292 | |||
293 | /** |
||
294 | * @param WritePHPUnitFile $write_unit_test |
||
295 | * @return GherkinToDusk |
||
296 | */ |
||
297 | 18 | public function setWriteUnitTest($write_unit_test = null) |
|
306 | |||
307 | 27 | private function checkIfFileExists() |
|
315 | |||
316 | 27 | public function fullPathToDestinationFile() |
|
320 | } |
||
321 |