| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 75 |
| 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 |
||
| 82 | private function addGridsSection(ArrayNodeDefinition $node) |
||
| 83 | { |
||
| 84 | $node |
||
| 85 | ->children() |
||
| 86 | ->arrayNode('grids') |
||
| 87 | ->useAttributeAsKey('code') |
||
| 88 | ->prototype('array') |
||
| 89 | ->children() |
||
| 90 | ->scalarNode('extends')->cannotBeEmpty()->end() |
||
| 91 | ->arrayNode('driver') |
||
| 92 | ->addDefaultsIfNotSet() |
||
| 93 | ->children() |
||
| 94 | ->scalarNode('name')->cannotBeEmpty()->defaultValue(DoctrineORMDriver::NAME)->end() |
||
| 95 | ->arrayNode('options') |
||
| 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('fields') |
||
| 107 | ->useAttributeAsKey('name') |
||
| 108 | ->prototype('array') |
||
| 109 | ->children() |
||
| 110 | ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
||
| 111 | ->scalarNode('label')->cannotBeEmpty()->end() |
||
| 112 | ->scalarNode('path')->cannotBeEmpty()->end() |
||
| 113 | ->scalarNode('sortable')->end() |
||
| 114 | ->scalarNode('enabled')->defaultTrue()->end() |
||
| 115 | ->scalarNode('position')->defaultValue(100)->end() |
||
| 116 | ->arrayNode('options') |
||
| 117 | ->prototype('variable')->end() |
||
| 118 | ->end() |
||
| 119 | ->end() |
||
| 120 | ->end() |
||
| 121 | ->end() |
||
| 122 | ->arrayNode('filters') |
||
| 123 | ->useAttributeAsKey('name') |
||
| 124 | ->prototype('array') |
||
| 125 | ->children() |
||
| 126 | ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
||
| 127 | ->scalarNode('label')->cannotBeEmpty()->end() |
||
| 128 | ->scalarNode('enabled')->defaultTrue()->end() |
||
| 129 | ->scalarNode('template')->end() |
||
| 130 | ->scalarNode('position')->defaultValue(100)->end() |
||
| 131 | ->arrayNode('options') |
||
| 132 | ->prototype('variable')->end() |
||
| 133 | ->end() |
||
| 134 | ->end() |
||
| 135 | ->end() |
||
| 136 | ->end() |
||
| 137 | ->arrayNode('actions') |
||
| 138 | ->useAttributeAsKey('name') |
||
| 139 | ->prototype('array') |
||
| 140 | ->useAttributeAsKey('name') |
||
| 141 | ->prototype('array') |
||
| 142 | ->children() |
||
| 143 | ->scalarNode('type')->isRequired()->end() |
||
| 144 | ->scalarNode('label')->end() |
||
| 145 | ->scalarNode('icon')->end() |
||
| 146 | ->scalarNode('position')->defaultValue(100)->end() |
||
| 147 | ->arrayNode('options') |
||
| 148 | ->prototype('variable')->end() |
||
| 149 | ->end() |
||
| 150 | ->end() |
||
| 151 | ->end() |
||
| 152 | ->end() |
||
| 153 | ->end() |
||
| 154 | ->end() |
||
| 155 | ->end() |
||
| 156 | ->end() |
||
| 157 | ->end() |
||
| 158 | ; |
||
| 159 | } |
||
| 160 | } |
||
| 161 |
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: