| Conditions | 1 |
| Paths | 1 |
| Total Lines | 117 |
| 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 |
||
| 31 | public function getConfigTreeBuilder() |
||
| 32 | { |
||
| 33 | $treeBuilder = new TreeBuilder('sonata_news'); |
||
| 34 | $rootNode = $treeBuilder->getRootNode(); |
||
| 35 | |||
| 36 | $rootNode |
||
| 37 | ->children() |
||
| 38 | ->scalarNode('title')->isRequired()->end() |
||
| 39 | ->scalarNode('link')->isRequired()->end() |
||
| 40 | ->scalarNode('description')->isRequired()->end() |
||
| 41 | ->scalarNode('permalink_generator')->defaultValue('sonata.news.permalink.date')->end() |
||
| 42 | ->scalarNode('salt')->isRequired()->end() |
||
| 43 | ->arrayNode('permalink') |
||
| 44 | ->addDefaultsIfNotSet() |
||
| 45 | ->children() |
||
| 46 | ->scalarNode('date') |
||
| 47 | ->info('Default format: year/month/day/slug') |
||
| 48 | ->defaultValue('%%1$04d/%%2$d/%%3$d/%%4$s') |
||
| 49 | ->end() |
||
| 50 | ->end() |
||
| 51 | ->end() |
||
| 52 | ->scalarNode('db_driver') |
||
| 53 | // NEXT_MAJOR: Change default value to: no_driver |
||
| 54 | ->defaultValue('doctrine_orm') |
||
| 55 | ->validate() |
||
| 56 | ->ifNotInArray(self::DB_DRIVERS) |
||
| 57 | ->thenInvalid('SonataNewsBundle - Invalid db driver %s.') |
||
| 58 | ->end() |
||
| 59 | ->end() |
||
| 60 | ->arrayNode('table') |
||
| 61 | ->addDefaultsIfNotSet() |
||
| 62 | ->children() |
||
| 63 | ->scalarNode('post_tag')->defaultValue('news__post_tag')->end() |
||
| 64 | ->end() |
||
| 65 | ->end() |
||
| 66 | ->arrayNode('class') |
||
| 67 | ->addDefaultsIfNotSet() |
||
| 68 | ->children() |
||
| 69 | ->scalarNode('tag') |
||
| 70 | ->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Tag') |
||
| 71 | ->end() |
||
| 72 | ->scalarNode('collection') |
||
| 73 | ->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Collection') |
||
| 74 | ->end() |
||
| 75 | ->scalarNode('post') |
||
| 76 | ->defaultValue('Application\\Sonata\\NewsBundle\\Entity\\Post') |
||
| 77 | ->end() |
||
| 78 | ->scalarNode('comment') |
||
| 79 | ->defaultValue('Application\\Sonata\\NewsBundle\\Entity\\Comment') |
||
| 80 | ->end() |
||
| 81 | ->scalarNode('media') |
||
| 82 | ->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\Media') |
||
| 83 | ->end() |
||
| 84 | ->scalarNode('user') |
||
| 85 | ->defaultValue('Application\\Sonata\\UserBundle\\Entity\\User') |
||
| 86 | ->end() |
||
| 87 | ->end() |
||
| 88 | ->end() |
||
| 89 | |||
| 90 | ->arrayNode('admin') |
||
| 91 | ->addDefaultsIfNotSet() |
||
| 92 | ->children() |
||
| 93 | ->arrayNode('post') |
||
| 94 | ->addDefaultsIfNotSet() |
||
| 95 | ->children() |
||
| 96 | ->scalarNode('class') |
||
| 97 | ->cannotBeEmpty() |
||
| 98 | ->defaultValue('Sonata\\NewsBundle\\Admin\\PostAdmin') |
||
| 99 | ->end() |
||
| 100 | ->scalarNode('controller') |
||
| 101 | ->cannotBeEmpty() |
||
| 102 | ->defaultValue('SonataAdminBundle:CRUD') |
||
| 103 | ->end() |
||
| 104 | ->scalarNode('translation') |
||
| 105 | ->cannotBeEmpty() |
||
| 106 | ->defaultValue('SonataNewsBundle') |
||
| 107 | ->end() |
||
| 108 | ->end() |
||
| 109 | ->end() |
||
| 110 | ->arrayNode('comment') |
||
| 111 | ->addDefaultsIfNotSet() |
||
| 112 | ->children() |
||
| 113 | ->scalarNode('class') |
||
| 114 | ->cannotBeEmpty() |
||
| 115 | ->defaultValue('Sonata\\NewsBundle\\Admin\\CommentAdmin') |
||
| 116 | ->end() |
||
| 117 | ->scalarNode('controller') |
||
| 118 | ->cannotBeEmpty() |
||
| 119 | ->defaultValue('SonataNewsBundle:CommentAdmin') |
||
| 120 | ->end() |
||
| 121 | ->scalarNode('translation') |
||
| 122 | ->cannotBeEmpty() |
||
| 123 | ->defaultValue('SonataNewsBundle') |
||
| 124 | ->end() |
||
| 125 | ->end() |
||
| 126 | ->end() |
||
| 127 | ->end() |
||
| 128 | ->end() |
||
| 129 | |||
| 130 | ->arrayNode('comment') |
||
| 131 | ->children() |
||
| 132 | ->arrayNode('notification') |
||
| 133 | ->children() |
||
| 134 | ->arrayNode('emails') |
||
| 135 | ->prototype('scalar')->cannotBeEmpty()->end() |
||
| 136 | ->end() |
||
| 137 | ->scalarNode('from')->cannotBeEmpty()->end() |
||
| 138 | ->scalarNode('template')->cannotBeEmpty()->end() |
||
| 139 | ->end() |
||
| 140 | ->end() |
||
| 141 | ->end() |
||
| 142 | ->end() |
||
| 143 | ->end() |
||
| 144 | ; |
||
| 145 | |||
| 146 | return $treeBuilder; |
||
| 147 | } |
||
| 148 | } |
||
| 149 |