| Conditions | 2 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 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 |
||
| 27 | public function getConfigTreeBuilder(): TreeBuilder |
||
| 28 | { |
||
| 29 | $treeBuilder = new TreeBuilder('bitbag_sylius_wishlist_plugin'); |
||
| 30 | $rootNode = $treeBuilder->getRootNode(); |
||
| 31 | /** @phpstan-ignore-next-line */ |
||
| 32 | $rootNode |
||
| 33 | ->children() |
||
| 34 | ->scalarNode('wishlist_cookie_token') |
||
| 35 | ->defaultValue('wishlist_cookie_token') |
||
| 36 | ->cannotBeEmpty() |
||
| 37 | ->validate() |
||
| 38 | ->always(function ($value) { |
||
| 39 | if (!is_string($value)) { |
||
| 40 | throw new InvalidConfigurationException('wishlist_cookie_token must be string'); |
||
| 41 | } |
||
| 42 | |||
| 43 | return $value; |
||
| 44 | }) |
||
| 45 | ->end() |
||
| 46 | ->end() |
||
| 47 | ->arrayNode('allowed_mime_types') |
||
| 48 | ->defaultValue([ |
||
| 49 | 'text/csv', |
||
| 50 | 'text/plain', |
||
| 51 | 'application/csv', |
||
| 52 | 'text/comma-separated-values', |
||
| 53 | 'application/excel', |
||
| 54 | 'application/vnd.ms-excel', |
||
| 55 | 'application/vnd.msexcel', |
||
| 56 | 'text/anytext', |
||
| 57 | 'application/octet-stream', |
||
| 58 | 'application/txt', |
||
| 59 | ]) |
||
| 60 | ->requiresAtLeastOneElement() |
||
| 61 | ->scalarPrototype()->end() |
||
| 62 | ->end() |
||
| 63 | ->arrayNode('resources') |
||
| 64 | ->addDefaultsIfNotSet() |
||
| 65 | ->children() |
||
| 66 | ->arrayNode('wishlist') |
||
| 67 | ->addDefaultsIfNotSet() |
||
| 68 | ->children() |
||
| 69 | ->variableNode('options')->end() |
||
| 70 | ->arrayNode('classes') |
||
| 71 | ->addDefaultsIfNotSet() |
||
| 72 | ->children() |
||
| 73 | ->scalarNode('model')->defaultValue(Wishlist::class)->cannotBeEmpty()->end() |
||
| 74 | ->scalarNode('interface')->defaultValue(WishlistInterface::class)->cannotBeEmpty()->end() |
||
| 75 | ->scalarNode('repository')->defaultValue(WishlistRepository::class)->cannotBeEmpty()->end() |
||
| 76 | ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
||
| 77 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
| 78 | ->end() |
||
| 79 | ->end() |
||
| 80 | ->end() |
||
| 81 | ->end() |
||
| 82 | ->arrayNode('wishlist_product') |
||
| 83 | ->addDefaultsIfNotSet() |
||
| 84 | ->children() |
||
| 85 | ->variableNode('options')->end() |
||
| 86 | ->arrayNode('classes') |
||
| 87 | ->addDefaultsIfNotSet() |
||
| 88 | ->children() |
||
| 89 | ->scalarNode('model')->defaultValue(WishlistProduct::class)->cannotBeEmpty()->end() |
||
| 90 | ->scalarNode('interface')->defaultValue(WishlistProductInterface::class)->cannotBeEmpty()->end() |
||
| 91 | ->scalarNode('repository')->defaultValue(EntityRepository::class)->cannotBeEmpty()->end() |
||
| 92 | ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
||
| 93 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
| 94 | ->end() |
||
| 95 | ->end() |
||
| 96 | ->end() |
||
| 97 | ->end() |
||
| 98 | ->end() |
||
| 99 | ->end() |
||
| 100 | ->end() |
||
| 101 | ; |
||
| 102 | |||
| 103 | return $treeBuilder; |
||
| 104 | } |
||
| 106 |