| Conditions | 7 | 
| Paths | 1 | 
| Total Lines | 204 | 
| Code Lines | 193 | 
| Lines | 2 | 
| Ratio | 0.98 % | 
| Tests | 184 | 
| CRAP Score | 7 | 
| Changes | 11 | ||
| Bugs | 0 | Features | 2 | 
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 | ||
| 10 | 11 | public function getConfigTreeBuilder() | |
| 11 |     { | ||
| 12 | 11 |         $storageTypes = array('service', 'array', 'doctrine', 'file'); | |
| 13 | 11 |         $providerTypes = array('file', 'directory', 'upload', 'doctrine', 'service'); | |
| 14 | 11 |         $fileFormats = array('csv', 'excel', 'xml', 'yaml'); | |
| 15 | |||
| 16 | 11 | $treeBuilder = new TreeBuilder(); | |
| 17 | $treeBuilder | ||
| 18 | 11 |             ->root('mathielen_import_engine') | |
| 19 | 11 |             ->fixXmlConfig('importer') | |
| 20 | 11 | ->children() | |
| 21 | 11 |                     ->arrayNode('storageprovider') | |
| 22 | 11 |                         ->useAttributeAsKey('name') | |
| 23 | 11 |                         ->prototype('array') | |
| 24 | 11 |                             ->fixXmlConfig('service') //allows <service> instead of <services> | |
| 25 | 11 |                             ->fixXmlConfig('query', 'queries') //allows <query> instead of <queries> | |
| 26 | 11 | ->children() | |
| 27 | 11 |                                 ->enumNode('type') | |
| 28 | 11 | ->values($providerTypes) | |
| 29 | 11 | ->end() | |
| 30 | 11 |                                 ->scalarNode('uri')->end()      //file | |
| 31 | 11 |                                 ->arrayNode('services') | |
| 32 | 11 |                                     ->useAttributeAsKey('name') | |
| 33 | 11 |                                     ->prototype('array') | |
| 34 | 11 |                                         ->fixXmlConfig('method') //allows <method> instead of <methods> | |
| 35 | 11 | ->beforeNormalization() | |
| 36 | 11 | ->ifArray() | |
| 37 |                                             ->then(function ($v) { return isset($v['methods'])||isset($v['method'])?$v:array('methods'=>$v); }) | ||
| 38 | 11 | ->end() | |
| 39 | 11 | ->children() | |
| 40 | 11 |                                             ->arrayNode('methods') | |
| 41 | 11 |                                                 ->prototype('scalar')->end() | |
| 42 | 11 | ->end() | |
| 43 | 11 | ->end() | |
| 44 | 11 | ->end() | |
| 45 | 11 | ->end() | |
| 46 | 11 |                                 ->arrayNode('queries') | |
| 47 | 11 |                                     ->prototype('scalar')->end() | |
| 48 | 11 | ->end() | |
| 49 | 11 | ->end() | |
| 50 | 11 | ->end() | |
| 51 | 11 | ->end() | |
| 52 | 11 |                     ->arrayNode('importers') | |
| 53 | 11 | ->requiresAtLeastOneElement() | |
| 54 | 11 |                         ->useAttributeAsKey('name') | |
| 55 | 11 |                         ->prototype('array') | |
| 56 | 11 |                             ->fixXmlConfig('mapping') //allows <mapping> instead of <mappings> | |
| 57 | 11 | ->children() | |
| 58 | 11 |                                 ->arrayNode('context') | |
| 59 | 11 |                                     ->prototype('scalar')->end() | |
| 60 | 11 | ->end() | |
| 61 | |||
| 62 | 11 |                                 ->arrayNode('preconditions') | |
| 63 | 11 |                                     ->fixXmlConfig('field')  //allows <field> instead of <fields> | |
| 64 | 11 | ->children() | |
| 65 | 11 |                                         ->arrayNode('format') | |
| 66 | 11 | ->beforeNormalization() | |
| 67 | 11 | ->ifString() | |
| 68 |                                                 ->then(function ($v) { return array($v); }) | ||
| 69 | 11 | ->end() | |
| 70 | 11 |                                             ->prototype('enum') | |
| 71 | 11 | ->values($fileFormats) | |
| 72 | 11 | ->end() | |
| 73 | 11 | ->end() | |
| 74 | 11 |                                         ->integerNode('fieldcount')->min(0)->end() | |
| 75 | 11 |                                         ->arrayNode('filename') | |
| 76 | 11 | ->beforeNormalization() | |
| 77 | 11 | ->ifString() | |
| 78 |                                                 ->then(function ($v) { return array($v); }) | ||
| 79 | 11 | ->end() | |
| 80 | 11 |                                             ->prototype('scalar')->end() | |
| 81 | 11 | ->end() | |
| 82 | 11 |                                         ->arrayNode('fieldset') | |
| 83 | 11 |                                             ->prototype('scalar')->end() | |
| 84 | 11 | ->end() | |
| 85 | 11 |                                         ->arrayNode('fields') | |
| 86 | 11 |                                             ->prototype('scalar')->end() | |
| 87 | 11 | ->end() | |
| 88 | 11 | ->end() | |
| 89 | 11 | ->end() | |
| 90 | |||
| 91 | 11 |                                 ->arrayNode('object_factory') | |
| 92 | 11 | ->children() | |
| 93 | 11 |                                         ->enumNode('type') | |
| 94 | 11 |                                             ->defaultValue('default') | |
| 95 | 11 |                                             ->values(array('default', 'jms_serializer')) | |
| 96 | 11 | ->end() | |
| 97 | 11 |                                         ->scalarNode('class') | |
| 98 | 11 | ->end() | |
| 99 | 11 | ->end() | |
| 100 | 11 | ->end() | |
| 101 | |||
| 102 | 11 |                                 ->arrayNode('filters') | |
| 103 | 11 |                                     ->prototype('scalar')->end() | |
| 104 | 11 | ->end() | |
| 105 | |||
| 106 | 11 |                                 ->arrayNode('mappings') | |
| 107 | 11 | ->normalizeKeys(false) //do not change - to _ with field names | |
| 108 | 11 |                                     ->useAttributeAsKey('from') | |
| 109 | 11 |                                     ->prototype('array') | |
| 110 | 11 | ->beforeNormalization() | |
| 111 | 11 | ->ifString() | |
| 112 |                                             ->then(function ($v) { return array('to'=>$v); }) | ||
| 113 | 11 | ->end() | |
| 114 | 11 | ->children() | |
| 115 | 11 |                                             ->scalarNode('to')->end() | |
| 116 | 11 |                                             ->scalarNode('converter')->end() | |
| 117 | 11 | ->end() | |
| 118 | 11 | ->end() | |
| 119 | 11 | ->end() | |
| 120 | |||
| 121 | 11 |                                 ->arrayNode('source') | |
| 122 | 11 | ->children() | |
| 123 | 11 |                                         ->enumNode('type') | |
| 124 | 11 | ->values($storageTypes) | |
| 125 | 11 | ->end() | |
| 126 | 11 |                                         ->scalarNode('uri')->end() | |
| 127 | 11 |                                         ->arrayNode('format')            //file | |
| 128 | 11 |                                             ->fixXmlConfig('argument') | |
| 129 | 11 | ->beforeNormalization() | |
| 130 | 11 | ->ifString() | |
| 131 |                                                 ->then(function ($v) { return array('type'=>$v); }) | ||
| 132 | 11 | ->end() | |
| 133 | 11 | ->children() | |
| 134 | 11 |                                                 ->scalarNode('type')->isRequired()->end() | |
| 135 | 11 |                                                     ->arrayNode('arguments') | |
| 136 | 11 |                                                     ->prototype('scalar')->end() | |
| 137 | 11 | ->end() | |
| 138 | 11 | ->end() | |
| 139 | 11 | ->end() | |
| 140 | 11 |                                         ->scalarNode('service')->end() | |
| 141 | 11 |                                         ->scalarNode('method')->end() | |
| 142 | 11 | ->end() | |
| 143 | 11 | ->end() | |
| 144 | |||
| 145 | 11 |                                 ->arrayNode('validation') | |
| 146 | 11 | ->children() | |
| 147 | 11 |                                         ->arrayNode('options') | |
| 148 | 11 | ->children() | |
| 149 | 11 |                                                 ->booleanNode('allowExtraFields')->end() | |
| 150 | 11 |                                                 ->booleanNode('allowMissingFields')->end() | |
| 151 | 11 | ->end() | |
| 152 | 11 | ->end() | |
| 153 | 11 |                                         ->arrayNode('source') | |
| 154 | 11 |                                             ->fixXmlConfig('constraint') //allows <constraint> instead of <constraints> | |
| 155 | 11 | ->beforeNormalization() | |
| 156 | 11 | ->ifArray() | |
| 157 | View Code Duplication |                                                 ->then(function ($v) { return isset($v['constraint'])||isset($v['constraints'])?$v:array('constraints'=>$v); }) | |
|  | |||
| 158 | 11 | ->end() | |
| 159 | 11 | ->children() | |
| 160 | 11 |                                                 ->arrayNode('constraints') | |
| 161 | 11 |                                                     ->useAttributeAsKey('field') | |
| 162 | 11 |                                                     ->prototype('scalar')->end() | |
| 163 | 11 | ->end() | |
| 164 | 11 | ->end() | |
| 165 | 11 | ->end() | |
| 166 | 11 |                                         ->arrayNode('target') | |
| 167 | 11 |                                             ->fixXmlConfig('constraint') //allows <constraint> instead of <constraints> | |
| 168 | 11 | ->beforeNormalization() | |
| 169 | 11 | ->ifArray() | |
| 170 | View Code Duplication |                                                 ->then(function ($v) { return isset($v['constraint'])||isset($v['constraints'])?$v:array('constraints'=>$v); }) | |
| 171 | 11 | ->end() | |
| 172 | 11 | ->children() | |
| 173 | 11 |                                                 ->arrayNode('constraints') | |
| 174 | 11 |                                                     ->useAttributeAsKey('field') | |
| 175 | 11 |                                                     ->prototype('scalar')->end() | |
| 176 | 11 | ->end() | |
| 177 | 11 | ->end() | |
| 178 | 11 | ->end() | |
| 179 | 11 | ->end() | |
| 180 | 11 | ->end() | |
| 181 | |||
| 182 | 11 |                                 ->arrayNode('target') | |
| 183 | 11 | ->isRequired() | |
| 184 | 11 | ->children() | |
| 185 | 11 |                                         ->enumNode('type') | |
| 186 | 11 | ->values($storageTypes) | |
| 187 | 11 | ->end() | |
| 188 | 11 |                                         ->arrayNode('format')            //file | |
| 189 | 11 |                                             ->fixXmlConfig('argument') | |
| 190 | 11 | ->beforeNormalization() | |
| 191 | 11 | ->ifString() | |
| 192 |                                                 ->then(function ($v) { return array('type'=>$v); }) | ||
| 193 | 11 | ->end() | |
| 194 | 11 | ->children() | |
| 195 | 11 |                                                 ->scalarNode('type')->isRequired()->end() | |
| 196 | 11 |                                                 ->arrayNode('arguments') | |
| 197 | 11 |                                                     ->prototype('scalar')->end() | |
| 198 | 11 | ->end() | |
| 199 | 11 | ->end() | |
| 200 | 11 | ->end() | |
| 201 | 11 |                                         ->scalarNode('uri')->end()      //file | |
| 202 | 11 |                                         ->scalarNode('service')->end()  //service | |
| 203 | 11 |                                         ->scalarNode('method')->end()   //service | |
| 204 | 11 |                                         ->scalarNode('entity')->end()   //doctrine | |
| 205 | 11 | ->end() | |
| 206 | 11 | ->end() | |
| 207 | 11 | ->end() | |
| 208 | 11 | ->end() | |
| 209 | 11 | ->end() | |
| 210 | 11 | ->end(); | |
| 211 | |||
| 212 | 11 | return $treeBuilder; | |
| 213 | } | ||
| 214 | |||
| 216 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.