| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 60 | public function getAdminsConfigurationNode() |
||
| 61 | { |
||
| 62 | $builder = new TreeBuilder(); |
||
| 63 | $node = $builder->root('admins'); |
||
| 64 | |||
| 65 | $node |
||
|
1 ignored issue
–
show
|
|||
| 66 | ->prototype('array') |
||
| 67 | ->children() |
||
| 68 | ->scalarNode('entity')->end() |
||
| 69 | ->scalarNode('data_provider')->end() |
||
| 70 | ->scalarNode('form')->end() |
||
| 71 | ->scalarNode('max_per_page')->end() |
||
| 72 | ->scalarNode('controller')->defaultValue('LAGAdminBundle:CRUD')->end() |
||
| 73 | // actions configurations |
||
| 74 | ->arrayNode('actions') |
||
| 75 | ->useAttributeAsKey('name') |
||
| 76 | ->prototype('array') |
||
| 77 | ->children() |
||
| 78 | ->scalarNode('title')->end() |
||
| 79 | ->arrayNode('permissions') |
||
| 80 | ->defaultValue(['ROLE_USER']) |
||
| 81 | ->prototype('scalar')->end() |
||
| 82 | ->end() |
||
| 83 | ->arrayNode('export') |
||
| 84 | ->prototype('scalar')->end() |
||
| 85 | ->end() |
||
| 86 | ->arrayNode('order') |
||
| 87 | ->prototype('array') |
||
| 88 | ->children() |
||
| 89 | ->scalarNode('field')->end() |
||
| 90 | ->scalarNode('order')->end() |
||
| 91 | ->end() |
||
| 92 | ->end() |
||
| 93 | ->end() |
||
| 94 | ->arrayNode('fields') |
||
| 95 | ->prototype('array') |
||
| 96 | ->children() |
||
| 97 | ->scalarNode('type')->end() |
||
| 98 | ->arrayNode('options') |
||
| 99 | ->prototype('variable')->end() |
||
| 100 | ->end() |
||
| 101 | ->end() |
||
| 102 | ->end() |
||
| 103 | ->end() |
||
| 104 | ->arrayNode('filters') |
||
| 105 | ->prototype('scalar')->end() |
||
| 106 | ->end() |
||
| 107 | ->arrayNode('batch') |
||
| 108 | ->prototype('variable')->end() |
||
| 109 | ->end() |
||
| 110 | ->arrayNode('actions') |
||
| 111 | ->prototype('array') |
||
| 112 | ->children() |
||
| 113 | ->scalarNode('title')->end() |
||
| 114 | ->scalarNode('route')->end() |
||
| 115 | ->scalarNode('target')->end() |
||
| 116 | ->scalarNode('icon')->end() |
||
| 117 | ->scalarNode('load_strategy')->end() |
||
| 118 | ->arrayNode('criteria') |
||
| 119 | ->prototype('array') |
||
| 120 | ->end() |
||
| 121 | ->end() |
||
| 122 | ->arrayNode('parameters') |
||
| 123 | ->prototype('array') |
||
| 124 | ->end() |
||
| 125 | ->end() |
||
| 126 | ->end() |
||
| 127 | ->end() |
||
| 128 | ->end() |
||
| 129 | ->end() |
||
| 130 | ->end() |
||
| 131 | ->end() |
||
| 132 | ->end() |
||
| 133 | ->end(); |
||
| 134 | |||
| 135 | return $node; |
||
| 136 | } |
||
| 137 | |||
| 179 |
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: