| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 65 |
| 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 |
||
| 54 | private function addResourcesSection(ArrayNodeDefinition $node) |
||
| 55 | { |
||
| 56 | $node |
||
|
|
|||
| 57 | ->children() |
||
| 58 | ->arrayNode('resources') |
||
| 59 | ->useAttributeAsKey('name') |
||
| 60 | ->prototype('array') |
||
| 61 | ->children() |
||
| 62 | ->scalarNode('subject')->isRequired()->end() |
||
| 63 | ->arrayNode('review') |
||
| 64 | ->isRequired() |
||
| 65 | ->addDefaultsIfNotSet() |
||
| 66 | ->children() |
||
| 67 | ->arrayNode('classes') |
||
| 68 | ->addDefaultsIfNotSet() |
||
| 69 | ->children() |
||
| 70 | ->scalarNode('model')->isRequired()->end() |
||
| 71 | ->scalarNode('interface')->defaultValue(ReviewInterface::class)->cannotBeEmpty()->end() |
||
| 72 | ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
||
| 73 | ->scalarNode('repository')->defaultValue(EntityRepository::class)->cannotBeEmpty()->end() |
||
| 74 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
| 75 | ->arrayNode('form') |
||
| 76 | ->addDefaultsIfNotSet() |
||
| 77 | ->children() |
||
| 78 | ->scalarNode('default')->defaultValue(ReviewType::class)->cannotBeEmpty()->end() |
||
| 79 | ->end() |
||
| 80 | ->end() |
||
| 81 | ->end() |
||
| 82 | ->end() |
||
| 83 | ->arrayNode('validation_groups') |
||
| 84 | ->addDefaultsIfNotSet() |
||
| 85 | ->children() |
||
| 86 | ->arrayNode('default') |
||
| 87 | ->prototype('scalar')->end() |
||
| 88 | ->defaultValue(['sylius']) |
||
| 89 | ->end() |
||
| 90 | ->end() |
||
| 91 | ->end() |
||
| 92 | ->end() |
||
| 93 | ->end() |
||
| 94 | ->arrayNode('reviewer') |
||
| 95 | ->addDefaultsIfNotSet() |
||
| 96 | ->children() |
||
| 97 | ->arrayNode('classes') |
||
| 98 | ->addDefaultsIfNotSet() |
||
| 99 | ->children() |
||
| 100 | ->scalarNode('model')->isRequired()->end() |
||
| 101 | ->scalarNode('interface')->defaultValue(ReviewerInterface::class)->cannotBeEmpty()->end() |
||
| 102 | ->scalarNode('repository')->cannotBeEmpty()->end() |
||
| 103 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
| 104 | ->end() |
||
| 105 | ->end() |
||
| 106 | ->arrayNode('validation_groups') |
||
| 107 | ->addDefaultsIfNotSet() |
||
| 108 | ->children() |
||
| 109 | ->arrayNode('default') |
||
| 110 | ->prototype('scalar')->end() |
||
| 111 | ->defaultValue(['sylius']) |
||
| 112 | ->end() |
||
| 113 | ->end() |
||
| 114 | ->end() |
||
| 115 | ->end() |
||
| 116 | ->end() |
||
| 117 | ->end() |
||
| 118 | ->end() |
||
| 119 | ->end() |
||
| 120 | ; |
||
| 121 | } |
||
| 122 | } |
||
| 123 |
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: