| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 93 | 
| Code Lines | 90 | 
| 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 | ||
| 81 | private function addGridsSection(ArrayNodeDefinition $node): void | ||
| 82 |     { | ||
| 83 | $node | ||
| 84 | ->children() | ||
| 85 |                 ->arrayNode('grids') | ||
| 86 |                     ->useAttributeAsKey('code') | ||
| 87 |                     ->prototype('array') | ||
| 88 | ->children() | ||
| 89 |                             ->scalarNode('extends')->cannotBeEmpty()->end() | ||
| 90 |                             ->arrayNode('driver') | ||
| 91 | ->addDefaultsIfNotSet() | ||
| 92 | ->children() | ||
| 93 |                                     ->scalarNode('name')->cannotBeEmpty()->defaultValue(DoctrineORMDriver::NAME)->end() | ||
| 94 |                                     ->arrayNode('options') | ||
| 95 | ->performNoDeepMerging() | ||
| 96 |                                         ->prototype('variable')->end() | ||
| 97 | ->defaultValue([]) | ||
| 98 | ->end() | ||
| 99 | ->end() | ||
| 100 | ->end() | ||
| 101 |                             ->arrayNode('sorting') | ||
| 102 | ->performNoDeepMerging() | ||
| 103 |                                 ->useAttributeAsKey('name') | ||
| 104 |                                 ->prototype('enum')->values(['asc', 'desc'])->cannotBeEmpty()->end() | ||
| 105 | ->end() | ||
| 106 |                             ->arrayNode('limits') | ||
| 107 | ->performNoDeepMerging() | ||
| 108 |                                 ->prototype('integer')->end() | ||
| 109 | ->defaultValue([10, 25, 50]) | ||
| 110 | ->end() | ||
| 111 |                             ->arrayNode('fields') | ||
| 112 |                                 ->useAttributeAsKey('name') | ||
| 113 |                                 ->prototype('array') | ||
| 114 | ->children() | ||
| 115 |                                         ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() | ||
| 116 |                                         ->scalarNode('label')->cannotBeEmpty()->end() | ||
| 117 |                                         ->scalarNode('path')->cannotBeEmpty()->end() | ||
| 118 |                                         ->scalarNode('sortable')->end() | ||
| 119 |                                         ->scalarNode('enabled')->defaultTrue()->end() | ||
| 120 |                                         ->scalarNode('position')->defaultValue(100)->end() | ||
| 121 |                                         ->arrayNode('options') | ||
| 122 | ->performNoDeepMerging() | ||
| 123 |                                             ->prototype('variable')->end() | ||
| 124 | ->end() | ||
| 125 | ->end() | ||
| 126 | ->end() | ||
| 127 | ->end() | ||
| 128 |                             ->arrayNode('filters') | ||
| 129 |                                 ->useAttributeAsKey('name') | ||
| 130 |                                 ->prototype('array') | ||
| 131 | ->children() | ||
| 132 |                                         ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() | ||
| 133 |                                         ->scalarNode('label')->cannotBeEmpty()->end() | ||
| 134 |                                         ->scalarNode('enabled')->defaultTrue()->end() | ||
| 135 |                                         ->scalarNode('template')->end() | ||
| 136 |                                         ->scalarNode('position')->defaultValue(100)->end() | ||
| 137 |                                         ->arrayNode('options') | ||
| 138 | ->performNoDeepMerging() | ||
| 139 |                                             ->prototype('variable')->end() | ||
| 140 | ->end() | ||
| 141 |                                         ->arrayNode('form_options') | ||
| 142 | ->performNoDeepMerging() | ||
| 143 |                                             ->prototype('variable')->end() | ||
| 144 | ->end() | ||
| 145 |                                         ->variableNode('default_value')->end() | ||
| 146 | ->end() | ||
| 147 | ->end() | ||
| 148 | ->end() | ||
| 149 |                             ->arrayNode('actions') | ||
| 150 |                                 ->useAttributeAsKey('name') | ||
| 151 |                                 ->prototype('array') | ||
| 152 |                                     ->useAttributeAsKey('name') | ||
| 153 |                                     ->prototype('array') | ||
| 154 | ->children() | ||
| 155 |                                             ->scalarNode('type')->isRequired()->end() | ||
| 156 |                                             ->scalarNode('label')->end() | ||
| 157 |                                             ->scalarNode('enabled')->defaultTrue()->end() | ||
| 158 |                                             ->scalarNode('icon')->end() | ||
| 159 |                                             ->scalarNode('position')->defaultValue(100)->end() | ||
| 160 |                                             ->arrayNode('options') | ||
| 161 | ->performNoDeepMerging() | ||
| 162 |                                                 ->prototype('variable')->end() | ||
| 163 | ->end() | ||
| 164 | ->end() | ||
| 165 | ->end() | ||
| 166 | ->end() | ||
| 167 | ->end() | ||
| 168 | ->end() | ||
| 169 | ->end() | ||
| 170 | ->end() | ||
| 171 | ->end() | ||
| 172 | ; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | 
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: