| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 3 |
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 |
||
| 83 | public function testConvertToArray() |
||
| 84 | { |
||
| 85 | // simple case |
||
| 86 | $optionCategory = new OptionCategory(); |
||
| 87 | $mainCategory = new OptionCategory('twomartens.core'); |
||
| 88 | $options = [ |
||
| 89 | new Option(0, 'one', 'string', 'hello'), |
||
| 90 | new Option(0, 'two', 'boolean', false), |
||
| 91 | new Option(0, 'three', 'array', [1, 2, 3]), |
||
| 92 | ]; |
||
| 93 | $mainCategory->setOptions($options); |
||
| 94 | $optionCategory->setCategories([$mainCategory]); |
||
| 95 | |||
| 96 | $yamlData = ConfigUtil::convertToArray($optionCategory); |
||
| 97 | $expectedYamlData = [ |
||
| 98 | 'twomartens.core' => [ |
||
| 99 | 'one' => 'hello', |
||
| 100 | 'two' => false, |
||
| 101 | 'three' => [1, 2, 3] |
||
| 102 | ] |
||
| 103 | ]; |
||
| 104 | |||
| 105 | $this->assertEquals($expectedYamlData, $yamlData); |
||
| 106 | |||
| 107 | // complex case |
||
| 108 | $optionCategory = new OptionCategory(); |
||
| 109 | $acpCategory = new OptionCategory('acp'); |
||
| 110 | $ourCategory = new OptionCategory('twomartens.core'); |
||
| 111 | $acpCategory->setCategories([$ourCategory]); |
||
| 112 | $optionCategory->setCategories([$acpCategory]); |
||
| 113 | |||
| 114 | $options = [ |
||
| 115 | new Option(0, 'one', 'boolean', true), |
||
| 116 | new Option(0, 'two', 'string', 'foo'), |
||
| 117 | new Option(0, 'three', 'array', [4, 5, 6]) |
||
| 118 | ]; |
||
| 119 | $ourCategory->setOptions($options); |
||
| 120 | |||
| 121 | $yamlData = ConfigUtil::convertToArray($optionCategory); |
||
| 122 | $expectedYamlData = [ |
||
| 123 | 'acp' => [ |
||
| 124 | 'twomartens.core' => [ |
||
| 125 | 'one' => true, |
||
| 126 | 'two' => 'foo', |
||
| 127 | 'three' => [4, 5, 6] |
||
| 128 | ] |
||
| 129 | ] |
||
| 130 | ]; |
||
| 131 | |||
| 132 | $this->assertEquals($expectedYamlData, $yamlData); |
||
| 133 | } |
||
| 134 | } |
||
| 135 |