| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| 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 |
||
| 110 | public function testComplexProcess() |
||
| 111 | { |
||
| 112 | $unit = $this->getUnit('test_table1'); |
||
| 113 | $unit->setFilesystem($this->getFS(10)); |
||
| 114 | $unit->setGeneratorMapping([ |
||
| 115 | 'id' => 'generator.randomDigit', |
||
| 116 | 'code' => function (Generator $generator) { |
||
| 117 | return $generator->word; |
||
| 118 | } |
||
| 119 | ]); |
||
| 120 | $filesystem = $this->getMockBuilder('\Maketok\DataMigration\Storage\Filesystem\ResourceInterface') |
||
| 121 | ->getMock(); |
||
| 122 | $counter1 = 0; |
||
| 123 | $filesystem->expects($this->any()) |
||
| 124 | ->method('writeRow')->willReturnCallback(function () use (&$counter1) { |
||
| 125 | $counter1++; |
||
| 126 | }); |
||
| 127 | /** @var ResourceInterface $filesystem */ |
||
| 128 | $childUnit = $this->getUnit('test_table2'); |
||
| 129 | $childUnit->setFilesystem($filesystem); |
||
| 130 | $childUnit->setGeneratorMapping([ |
||
| 131 | 'id' => 'generator.randomDigit', |
||
| 132 | 'parent_id' => 'map.test_table1_id', |
||
| 133 | 'field1' => '0' |
||
| 134 | ]); |
||
| 135 | $childUnit->setParent($unit); |
||
| 136 | $seed = new \SplFixedArray(2); |
||
| 137 | $seed[0] = 4; |
||
| 138 | $seed[1] = 1; |
||
| 139 | $childUnit->setGenerationSeed($seed); |
||
| 140 | $childDataUnit = $this->getUnit('test_table3'); |
||
| 141 | $counter2 = 0; |
||
| 142 | $filesystem2 = $this->getMockBuilder('\Maketok\DataMigration\Storage\Filesystem\ResourceInterface') |
||
| 143 | ->getMock(); |
||
| 144 | $filesystem2->expects($this->any()) |
||
| 145 | ->method('writeRow')->willReturnCallback(function () use (&$counter2) { |
||
| 146 | $counter2++; |
||
| 147 | }); |
||
| 148 | /** @var ResourceInterface $filesystem2 */ |
||
| 149 | $childDataUnit->setFilesystem($filesystem2); |
||
| 150 | $childDataUnit->setGeneratorMapping([ |
||
| 151 | 'id' => 'generator.randomDigit', |
||
| 152 | 'parent_id' => 'map.test_table2_id', |
||
| 153 | 'field2' => '2' |
||
| 154 | ]); |
||
| 155 | $childDataUnit->setGenerationSeed($seed); |
||
| 156 | $childUnit->addSibling($childDataUnit); |
||
| 157 | $generator = new Generator(); |
||
| 158 | $generator->addProvider(new Base($generator)); |
||
| 159 | $generator->addProvider(new Lorem($generator)); |
||
| 160 | $action = new Generate( |
||
| 161 | $this->getUnitBag([$unit, $childUnit, $childDataUnit]), |
||
| 162 | $this->getConfig(), |
||
| 163 | new LanguageAdapter(new ExpressionLanguage()), |
||
| 164 | $generator, |
||
| 165 | 10, |
||
| 166 | new ArrayMap(), |
||
| 167 | $this->getResourceHelper() |
||
| 168 | ); |
||
| 169 | $action->process($this->getResultMock()); |
||
| 170 | |||
| 171 | $this->assertSame($counter1, $counter2); |
||
| 172 | } |
||
| 173 | |||
| 226 |