Conditions | 7 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
21 | public function getConfigTreeBuilder(): TreeBuilder |
||
22 | { |
||
23 | $treeBuilder = new TreeBuilder(self::ROOT_NAME); |
||
24 | $rootNode = $treeBuilder->getRootNode(); |
||
25 | |||
26 | $rootNode |
||
27 | ->children() |
||
28 | ->scalarNode('repository') |
||
29 | ->isRequired() |
||
30 | ->end() |
||
31 | ->arrayNode('resolver') |
||
32 | ->canBeEnabled() |
||
33 | ->beforeNormalization() |
||
34 | ->ifTrue(static function (array $config) { |
||
35 | if (!$config['enabled']) { |
||
36 | return false; |
||
37 | } |
||
38 | |||
39 | return 'hostname_identified' === $config['type'] && !isset($config['host_mapping']); |
||
40 | }) |
||
41 | ->thenInvalid('A "host_mapping" is required for the hostname_identified resolver') |
||
42 | ->end() |
||
43 | ->beforeNormalization() |
||
44 | ->ifTrue(static function (array $config) { |
||
45 | if (!$config['enabled']) { |
||
46 | return false; |
||
47 | } |
||
48 | |||
49 | return 'prefixed_path_identified' === $config['type'] && !isset($config['identifiers']); |
||
50 | }) |
||
51 | ->thenInvalid('"identifiers" are required for the prefixed_path_identified resolver') |
||
52 | ->end() |
||
53 | ->beforeNormalization() |
||
54 | ->ifTrue(static function (array $config) { |
||
55 | if (!$config['enabled']) { |
||
56 | return false; |
||
57 | } |
||
58 | |||
59 | return 'service' === $config['type'] && !isset($config['service_id']); |
||
60 | }) |
||
61 | ->thenInvalid('A "service_id" is required for the service resolver') |
||
62 | ->end() |
||
63 | ->children() |
||
64 | ->scalarNode('type') |
||
65 | ->cannotBeEmpty() |
||
66 | ->defaultValue('hostname_identified') |
||
67 | ->beforeNormalization() |
||
68 | ->ifNotInArray(self::ALLOWED_RESOLVERS) |
||
69 | ->thenInvalid('Resolver type must be one of: '.implode(', ', self::ALLOWED_RESOLVERS)) |
||
70 | ->end() |
||
71 | ->end() |
||
72 | ->scalarNode('service_id')->end() |
||
73 | ->arrayNode('host_mapping') |
||
74 | ->useAttributeAsKey('identifier') |
||
75 | ->prototype('array') |
||
76 | ->children() |
||
77 | ->scalarNode('identifier')->cannotBeEmpty()->end() |
||
78 | ->arrayNode('hostnames') |
||
79 | ->requiresAtLeastOneElement() |
||
80 | ->beforeNormalization() |
||
81 | ->castToArray() |
||
82 | ->end() |
||
83 | ->prototype('scalar') |
||
84 | ->end() |
||
85 | ->end() |
||
86 | ->arrayNode('locales') |
||
87 | ->requiresAtLeastOneElement() |
||
88 | ->beforeNormalization() |
||
89 | ->castToArray() |
||
90 | ->end() |
||
91 | ->prototype('scalar') |
||
92 | ->end() |
||
93 | ->end() |
||
94 | ->end() |
||
95 | ->end() |
||
96 | ->end() |
||
97 | ->scalarNode('route_parameter')->defaultValue('_site')->cannotBeEmpty()->end() |
||
98 | ->scalarNode('default_identifier')->end() |
||
99 | ->arrayNode('identifiers') |
||
100 | ->prototype('scalar')->end() |
||
101 | ->end() |
||
102 | ->end() |
||
103 | |||
104 | ->end() |
||
105 | ->end(); |
||
106 | |||
107 | return $treeBuilder; |
||
108 | } |
||
110 |