| 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 |
||
| 21 | public function translationTestDataProvider() |
||
| 22 | { |
||
| 23 | $keywords = $this->getKeywords(); |
||
| 24 | $dumper = new KeywordsDumper($keywords); |
||
| 25 | $keywordsArray = $this->getKeywordsArray(); |
||
| 26 | |||
| 27 | // Remove languages with repeated keywords |
||
| 28 | unset($keywordsArray['en-old'], $keywordsArray['uz']); |
||
| 29 | |||
| 30 | $data = array(); |
||
| 31 | foreach ($keywordsArray as $lang => $i18nKeywords) { |
||
| 32 | $features = array(); |
||
| 33 | foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) { |
||
| 34 | $line = 1; |
||
| 35 | if ('en' !== $lang) { |
||
| 36 | $line = 2; |
||
| 37 | } |
||
| 38 | |||
| 39 | $featureLine = $line; |
||
| 40 | $line += 5; |
||
| 41 | |||
| 42 | $keywords = explode('|', $i18nKeywords['background']); |
||
| 43 | $backgroundLine = $line; |
||
| 44 | $line += 1; |
||
| 45 | $background = new BackgroundNode(null, array_merge( |
||
| 46 | $this->getSteps($i18nKeywords['given'], 'there is agent A', $line, 'Given'), |
||
| 47 | $this->getSteps($i18nKeywords['and'], 'there is agent B', $line, 'Given') |
||
| 48 | ), $keywords[0], $backgroundLine); |
||
| 49 | |||
| 50 | $line += 1; |
||
| 51 | |||
| 52 | $scenarios = array(); |
||
| 53 | |||
| 54 | foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) { |
||
| 55 | $scenarioLine = $line; |
||
| 56 | $line += 1; |
||
| 57 | |||
| 58 | $steps = array_merge( |
||
| 59 | $this->getSteps($i18nKeywords['given'], 'there is agent J', $line, 'Given'), |
||
| 60 | $this->getSteps($i18nKeywords['and'], 'there is agent K', $line, 'Given'), |
||
| 61 | $this->getSteps($i18nKeywords['when'], 'I erase agent K\'s memory', $line, 'When'), |
||
| 62 | $this->getSteps($i18nKeywords['then'], 'there should be agent J', $line, 'Then'), |
||
| 63 | $this->getSteps($i18nKeywords['but'], 'there should not be agent K', $line, 'Then') |
||
| 64 | ); |
||
| 65 | |||
| 66 | $scenarios[] = new ScenarioNode('Erasing agent memory', array(), $steps, $scenarioKeyword, $scenarioLine); |
||
| 67 | $line += 1; |
||
| 68 | } |
||
| 69 | foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) { |
||
| 70 | $outlineLine = $line; |
||
| 71 | $line += 1; |
||
| 72 | |||
| 73 | $steps = array_merge( |
||
| 74 | $this->getSteps($i18nKeywords['given'], 'there is agent <agent1>', $line, 'Given'), |
||
| 75 | $this->getSteps($i18nKeywords['and'], 'there is agent <agent2>', $line, 'Given'), |
||
| 76 | $this->getSteps($i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line, 'When'), |
||
| 77 | $this->getSteps($i18nKeywords['then'], 'there should be agent <agent1>', $line, 'Then'), |
||
| 78 | $this->getSteps($i18nKeywords['but'], 'there should not be agent <agent2>', $line, 'Then') |
||
| 79 | ); |
||
| 80 | $line += 1; |
||
| 81 | |||
| 82 | $keywords = explode('|', $i18nKeywords['examples']); |
||
| 83 | $table = new ExampleTableNode(array( |
||
| 84 | ++$line => array('agent1', 'agent2'), |
||
| 85 | ++$line => array('D', 'M') |
||
| 86 | ), $keywords[0]); |
||
| 87 | $line += 1; |
||
| 88 | |||
| 89 | $scenarios[] = new OutlineNode('Erasing other agents\' memory', array(), $steps, $table, $outlineKeyword, $outlineLine); |
||
| 90 | $line += 1; |
||
| 91 | } |
||
| 92 | |||
| 93 | $features[] = new FeatureNode( |
||
| 94 | 'Internal operations', |
||
| 95 | <<<DESC |
||
| 96 | In order to stay secret |
||
| 97 | As a secret organization |
||
| 98 | We need to be able to erase past agents' memory |
||
| 99 | DESC |
||
| 100 | , |
||
| 101 | array(), |
||
| 102 | $background, |
||
| 103 | $scenarios, |
||
| 104 | $featureKeyword, |
||
| 105 | $lang, |
||
| 106 | __DIR__ . DIRECTORY_SEPARATOR . $lang . '_' . ($transNum + 1) . '.feature', |
||
| 107 | $featureLine |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 111 | $dumped = $dumper->dump($lang, false, true); |
||
| 112 | |||
| 113 | foreach ($dumped as $num => $dumpedFeature) { |
||
|
|
|||
| 114 | $data[$lang . "_" . $num] = array($lang, $num, $features[$num], $dumpedFeature); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | return $data; |
||
| 119 | } |
||
| 120 | |||
| 144 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.