| Conditions | 10 | 
| Paths | 1 | 
| Total Lines | 129 | 
| Code 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  | 
            ||
| 58 | public function addRepositoriesSection(ArrayNodeDefinition $rootNode)  | 
            ||
| 59 |     { | 
            ||
| 60 | $rootNode  | 
            ||
| 61 | ->children()  | 
            ||
| 62 |                 ->arrayNode('repositories') | 
            ||
| 63 |                     ->info('Content repositories configuration') | 
            ||
| 64 | ->example(  | 
            ||
| 65 | array(  | 
            ||
| 66 | 'main' => array(  | 
            ||
| 67 | 'storage' => array(  | 
            ||
| 68 | 'engine' => 'legacy',  | 
            ||
| 69 | 'connection' => 'my_doctrine_connection_name',  | 
            ||
| 70 | ),  | 
            ||
| 71 | ),  | 
            ||
| 72 | )  | 
            ||
| 73 | )  | 
            ||
| 74 |                     ->useAttributeAsKey('alias') | 
            ||
| 75 |                     ->prototype('array') | 
            ||
| 76 | ->beforeNormalization()  | 
            ||
| 77 | ->always(  | 
            ||
| 78 | // Handling deprecated structure by mapping it to new one  | 
            ||
| 79 |                                 function ($v) { | 
            ||
| 80 |                                     if (isset($v['storage'])) { | 
            ||
| 81 | return $v;  | 
            ||
| 82 | }  | 
            ||
| 83 | |||
| 84 |                                     if (isset($v['engine'])) { | 
            ||
| 85 | $v['storage']['engine'] = $v['engine'];  | 
            ||
| 86 | unset($v['engine']);  | 
            ||
| 87 | }  | 
            ||
| 88 | |||
| 89 |                                     if (isset($v['connection'])) { | 
            ||
| 90 | $v['storage']['connection'] = $v['connection'];  | 
            ||
| 91 | unset($v['connection']);  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 |                                     if (isset($v['config'])) { | 
            ||
| 95 | $v['storage']['config'] = $v['config'];  | 
            ||
| 96 | unset($v['config']);  | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 | return $v;  | 
            ||
| 100 | }  | 
            ||
| 101 | )  | 
            ||
| 102 | ->end()  | 
            ||
| 103 | ->beforeNormalization()  | 
            ||
| 104 | ->always(  | 
            ||
| 105 | // Setting default values  | 
            ||
| 106 |                                 function ($v) { | 
            ||
| 107 |                                     if ($v === null) { | 
            ||
| 108 | $v = array();  | 
            ||
| 109 | }  | 
            ||
| 110 | |||
| 111 |                                     if (!isset($v['storage'])) { | 
            ||
| 112 | $v['storage'] = array();  | 
            ||
| 113 | }  | 
            ||
| 114 | |||
| 115 |                                     if (!isset($v['search'])) { | 
            ||
| 116 | $v['search'] = array();  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 |                                     if (!isset($v['fields_groups']['list'])) { | 
            ||
| 120 | $v['fields_groups']['list'] = [];  | 
            ||
| 121 | }  | 
            ||
| 122 | |||
| 123 |                                     if (!isset($v['options'])) { | 
            ||
| 124 | $v['options'] = [];  | 
            ||
| 125 | }  | 
            ||
| 126 | |||
| 127 | return $v;  | 
            ||
| 128 | }  | 
            ||
| 129 | )  | 
            ||
| 130 | ->end()  | 
            ||
| 131 | ->children()  | 
            ||
| 132 |                             ->arrayNode('storage') | 
            ||
| 133 | ->children()  | 
            ||
| 134 |                                     ->scalarNode('engine') | 
            ||
| 135 |                                         ->defaultValue('%ezpublish.api.storage_engine.default%') | 
            ||
| 136 |                                         ->info('The storage engine to use') | 
            ||
| 137 | ->end()  | 
            ||
| 138 |                                     ->scalarNode('connection') | 
            ||
| 139 | ->defaultNull()  | 
            ||
| 140 |                                         ->info('The connection name, if applicable (e.g. Doctrine connection name). If not set, the default connection will be used.') | 
            ||
| 141 | ->end()  | 
            ||
| 142 |                                     ->arrayNode('config') | 
            ||
| 143 |                                         ->info('Arbitrary configuration options, supported by your storage engine') | 
            ||
| 144 |                                         ->useAttributeAsKey('key') | 
            ||
| 145 |                                         ->prototype('variable')->end() | 
            ||
| 146 | ->end()  | 
            ||
| 147 | ->end()  | 
            ||
| 148 | ->end()  | 
            ||
| 149 |                             ->arrayNode('search') | 
            ||
| 150 | ->children()  | 
            ||
| 151 |                                     ->scalarNode('engine') | 
            ||
| 152 |                                         ->defaultValue('%ezpublish.api.search_engine.default%') | 
            ||
| 153 |                                         ->info('The search engine to use') | 
            ||
| 154 | ->end()  | 
            ||
| 155 |                                     ->scalarNode('connection') | 
            ||
| 156 | ->defaultNull()  | 
            ||
| 157 |                                         ->info('The connection name, if applicable (e.g. Doctrine connection name). If not set, the default connection will be used.') | 
            ||
| 158 | ->end()  | 
            ||
| 159 |                                     ->arrayNode('config') | 
            ||
| 160 |                                         ->info('Arbitrary configuration options, supported by your search engine') | 
            ||
| 161 |                                         ->useAttributeAsKey('key') | 
            ||
| 162 |                                         ->prototype('variable')->end() | 
            ||
| 163 | ->end()  | 
            ||
| 164 | ->end()  | 
            ||
| 165 | ->end()  | 
            ||
| 166 |                             ->arrayNode('fields_groups') | 
            ||
| 167 |                                 ->info('Definitions of fields groups.') | 
            ||
| 168 | ->children()  | 
            ||
| 169 |                                     ->arrayNode('list')->prototype('scalar')->end()->end() | 
            ||
| 170 |                                     ->scalarNode('default')->defaultValue('%ezsettings.default.content.field_groups.default%')->end() | 
            ||
| 171 | ->end()  | 
            ||
| 172 | ->end()  | 
            ||
| 173 |                             ->arrayNode('options') | 
            ||
| 174 |                                 ->info('Options for repository.') | 
            ||
| 175 | ->children()  | 
            ||
| 176 |                                     ->scalarNode('default_version_archive_limit') | 
            ||
| 177 | ->defaultValue(5)  | 
            ||
| 178 |                                         ->info('Default version archive limit (0-50), only enforced on publish, not on un-publish.') | 
            ||
| 179 | ->end()  | 
            ||
| 180 | ->end()  | 
            ||
| 181 | ->end()  | 
            ||
| 182 | ->end()  | 
            ||
| 183 | ->end()  | 
            ||
| 184 | ->end()  | 
            ||
| 185 | ->end();  | 
            ||
| 186 | }  | 
            ||
| 187 | |||
| 442 | 
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: