Conditions | 7 |
Paths | 19 |
Total Lines | 99 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
20 | public function translationTestDataProvider() |
||
21 | { |
||
22 | $keywords = $this->getKeywords(); |
||
23 | $dumper = new KeywordsDumper($keywords); |
||
24 | $keywordsArray = $this->getKeywordsArray(); |
||
25 | |||
26 | // Remove languages with repeated keywords |
||
27 | unset($keywordsArray['en-old'], $keywordsArray['uz']); |
||
28 | |||
29 | $data = array(); |
||
30 | foreach ($keywordsArray as $lang => $i18nKeywords) { |
||
31 | $features = array(); |
||
32 | foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) { |
||
33 | $line = 1; |
||
34 | if ('en' !== $lang) { |
||
35 | $line = 2; |
||
36 | } |
||
37 | |||
38 | $featureLine = $line; |
||
39 | $line += 5; |
||
40 | |||
41 | $keywords = explode('|', $i18nKeywords['background']); |
||
42 | $backgroundLine = $line; |
||
43 | $line += 1; |
||
44 | $background = new BackgroundNode(null, array_merge( |
||
45 | $this->getSteps($i18nKeywords['given'], 'there is agent A', $line, 'Given'), |
||
46 | $this->getSteps($i18nKeywords['and'], 'there is agent B', $line, 'Given') |
||
47 | ), $keywords[0], $backgroundLine); |
||
48 | |||
49 | $line += 1; |
||
50 | |||
51 | $scenarios = array(); |
||
52 | |||
53 | foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) { |
||
54 | $scenarioLine = $line; |
||
55 | $line += 1; |
||
56 | |||
57 | $steps = array_merge( |
||
58 | $this->getSteps($i18nKeywords['given'], 'there is agent J', $line, 'Given'), |
||
59 | $this->getSteps($i18nKeywords['and'], 'there is agent K', $line, 'Given'), |
||
60 | $this->getSteps($i18nKeywords['when'], 'I erase agent K\'s memory', $line, 'When'), |
||
61 | $this->getSteps($i18nKeywords['then'], 'there should be agent J', $line, 'Then'), |
||
62 | $this->getSteps($i18nKeywords['but'], 'there should not be agent K', $line, 'Then') |
||
63 | ); |
||
64 | |||
65 | $scenarios[] = new ScenarioNode('Erasing agent memory', array(), $steps, $scenarioKeyword, $scenarioLine); |
||
66 | $line += 1; |
||
67 | } |
||
68 | foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) { |
||
69 | $outlineLine = $line; |
||
70 | $line += 1; |
||
71 | |||
72 | $steps = array_merge( |
||
73 | $this->getSteps($i18nKeywords['given'], 'there is agent <agent1>', $line, 'Given'), |
||
74 | $this->getSteps($i18nKeywords['and'], 'there is agent <agent2>', $line, 'Given'), |
||
75 | $this->getSteps($i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line, 'When'), |
||
76 | $this->getSteps($i18nKeywords['then'], 'there should be agent <agent1>', $line, 'Then'), |
||
77 | $this->getSteps($i18nKeywords['but'], 'there should not be agent <agent2>', $line, 'Then') |
||
78 | ); |
||
79 | $line += 1; |
||
80 | |||
81 | $keywords = explode('|', $i18nKeywords['examples']); |
||
82 | $table = new ExampleTableNode(array( |
||
83 | ++$line => array('agent1', 'agent2'), |
||
84 | ++$line => array('D', 'M') |
||
85 | ), $keywords[0]); |
||
86 | $line += 1; |
||
87 | |||
88 | $scenarios[] = new OutlineNode('Erasing other agents\' memory', array(), $steps, $table, $outlineKeyword, $outlineLine); |
||
89 | $line += 1; |
||
90 | } |
||
91 | |||
92 | $features[] = new FeatureNode( |
||
93 | 'Internal operations', |
||
94 | <<<DESC |
||
95 | In order to stay secret |
||
96 | As a secret organization |
||
97 | We need to be able to erase past agents' memory |
||
98 | DESC |
||
99 | , |
||
|
|||
100 | array(), |
||
101 | $background, |
||
102 | $scenarios, |
||
103 | $featureKeyword, |
||
104 | $lang, |
||
105 | $lang . '_' . ($transNum + 1) . '.feature', |
||
106 | $featureLine |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | $dumped = $dumper->dump($lang, false, true); |
||
111 | |||
112 | foreach ($dumped as $num => $dumpedFeature) { |
||
113 | $data[] = array($lang, $num, $features[$num], $dumpedFeature); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | return $data; |
||
118 | } |
||
119 | |||
143 |