| Conditions | 2 |
| Paths | 2 |
| Total Lines | 55 |
| 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 |
||
| 28 | public function getConfigTreeBuilder() |
||
| 29 | { |
||
| 30 | $treeBuilder = new TreeBuilder('sonata_seo'); |
||
| 31 | |||
| 32 | // Keep compatibility with symfony/config < 4.2 |
||
| 33 | if (!method_exists($treeBuilder, 'getRootNode')) { |
||
| 34 | $rootNode = $treeBuilder->root('sonata_seo'); |
||
| 35 | } else { |
||
| 36 | $rootNode = $treeBuilder->getRootNode(); |
||
| 37 | } |
||
| 38 | |||
| 39 | $rootNode |
||
| 40 | ->children() |
||
| 41 | ->scalarNode('encoding')->defaultValue('UTF-8')->end() |
||
| 42 | ->arrayNode('page') |
||
| 43 | ->addDefaultsIfNotSet() |
||
| 44 | ->children() |
||
| 45 | ->scalarNode('default')->defaultValue('sonata.seo.page.default')->end() |
||
| 46 | ->arrayNode('head') |
||
| 47 | ->normalizeKeys(false) |
||
| 48 | ->useAttributeAsKey('attribute') |
||
| 49 | ->prototype('scalar')->end() |
||
| 50 | ->end() |
||
| 51 | ->arrayNode('metas') |
||
| 52 | ->normalizeKeys(false) |
||
| 53 | ->useAttributeAsKey('element') |
||
| 54 | ->prototype('array') |
||
| 55 | ->normalizeKeys(false) |
||
| 56 | ->useAttributeAsKey('name') |
||
| 57 | ->prototype('scalar')->end() |
||
| 58 | ->end() |
||
| 59 | ->end() |
||
| 60 | ->scalarNode('separator')->defaultValue(' - ')->end() |
||
| 61 | // NEXT_MAJOR: Make this field required |
||
| 62 | ->scalarNode('title')->defaultValue('Project name')->end() |
||
| 63 | ->end() |
||
| 64 | ->end() |
||
| 65 | ->arrayNode('sitemap') |
||
| 66 | ->addDefaultsIfNotSet() |
||
| 67 | ->children() |
||
| 68 | ->arrayNode('doctrine_orm') |
||
| 69 | ->prototype('variable')->end() |
||
| 70 | ->end() |
||
| 71 | ->arrayNode('services') |
||
| 72 | ->prototype('variable')->end() |
||
| 73 | ->end() |
||
| 74 | ->end() |
||
| 75 | ->end() |
||
| 76 | ->end() |
||
| 77 | ; |
||
| 78 | |||
| 79 | $this->addHTTPlugSection($rootNode); |
||
|
|
|||
| 80 | |||
| 81 | return $treeBuilder; |
||
| 82 | } |
||
| 83 | |||
| 104 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.