| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 16 | public function testBuildYml() |
||
| 17 | { |
||
| 18 | Yii::$app->setModule('YandexMarketYml', [ |
||
| 19 | 'class' => YandexMarketYml::className(), |
||
| 20 | 'cacheProvider' => new \yii\caching\DummyCache(), |
||
| 21 | ]); |
||
| 22 | |||
| 23 | /** @var YandexMarketYml $module */ |
||
| 24 | $module = Yii::$app->getModule('YandexMarketYml'); |
||
| 25 | $actual = $module->createControllerByID('default')->renderPartial('index', [ |
||
| 26 | 'shop' => new Shop([ |
||
| 27 | 'name' => 'MyCompanyName', |
||
| 28 | 'company' => 'LTD MyCompanyName', |
||
| 29 | 'url' => 'http://example.com', |
||
| 30 | 'currencies' => [ |
||
| 31 | ['id' => 'RUR', 'rate' => 1] |
||
| 32 | ], |
||
| 33 | 'categories' => [ |
||
| 34 | new Category([ |
||
| 35 | 'id' => 1, |
||
| 36 | 'name' => 'First Category', |
||
| 37 | 'parentId' => null, |
||
| 38 | ]), |
||
| 39 | ], |
||
| 40 | 'offers' => [ |
||
| 41 | new Offer([ |
||
| 42 | 'id' => 1, |
||
| 43 | 'available' => true, |
||
| 44 | 'url' => 'http://example.com/item/1', |
||
| 45 | 'price' => 1560, |
||
| 46 | 'currencyId' => 'RUR', |
||
| 47 | 'categoryId' => 1, |
||
| 48 | 'picture' => 'http://example.com/images/1.jpg', |
||
| 49 | 'name' => 'Jacket', |
||
| 50 | 'vendor' => 'Manufacturer', |
||
| 51 | 'description' => 'Item description', |
||
| 52 | ]), |
||
| 53 | new Offer([ |
||
| 54 | 'id' => 2, |
||
| 55 | 'available' => false, |
||
| 56 | 'url' => 'http://example.com/item/2', |
||
| 57 | 'price' => 2360, |
||
| 58 | 'currencyId' => 'RUR', |
||
| 59 | 'categoryId' => 1, |
||
| 60 | 'picture' => 'http://example.com/images/2.jpg', |
||
| 61 | 'name' => 'T-shirt', |
||
| 62 | 'vendor' => 'Manufacturer', |
||
| 63 | 'description' => 'Items description', |
||
| 64 | ]), |
||
| 65 | ] |
||
| 66 | ]), |
||
| 67 | ]); |
||
| 68 | $expected = file_get_contents(__DIR__ . '/data/yml.bin'); |
||
| 69 | $this->assertEquals($expected, $actual); |
||
| 70 | } |
||
| 71 | } |