Conditions | 7 |
Paths | 1 |
Total Lines | 181 |
Code Lines | 163 |
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 |
||
21 | public function getConfigTreeBuilder() |
||
22 | { |
||
23 | $treeBuilder = new TreeBuilder(); |
||
24 | $rootNode = $treeBuilder->root('fsi_admin_security'); |
||
25 | |||
26 | $supportedStorages = ['orm']; |
||
27 | $adminChangePasswordFormType = TypeSolver::getFormType( |
||
28 | 'FSi\Bundle\AdminSecurityBundle\Form\Type\Admin\ChangePasswordType', |
||
29 | 'admin_change_password' |
||
30 | ); |
||
31 | $resetRequestFormType = TypeSolver::getFormType( |
||
32 | 'FSi\Bundle\AdminSecurityBundle\Form\Type\PasswordReset\RequestType', |
||
33 | 'admin_password_reset_request' |
||
34 | ); |
||
35 | $changePasswordFormType = TypeSolver::getFormType( |
||
36 | 'FSi\Bundle\AdminSecurityBundle\Form\Type\PasswordReset\ChangePasswordType', |
||
37 | 'admin_password_reset_change_password' |
||
38 | ); |
||
39 | |||
40 | $rootNode |
||
41 | ->beforeNormalization() |
||
42 | ->always(function($v) { |
||
43 | if (isset($v['mailer']['from'])) { |
||
44 | if (!isset($v['activation']['mailer']['from'])) { |
||
45 | $v['activation']['mailer']['from'] = $v['mailer']['from']; |
||
46 | } |
||
47 | if (!isset($v['password_reset']['mailer']['from'])) { |
||
48 | $v['password_reset']['mailer']['from'] = $v['mailer']['from']; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | if (isset($v['mailer']['reply_to'])) { |
||
53 | if (!isset($v['activation']['mailer']['reply_to'])) { |
||
54 | $v['activation']['mailer']['reply_to'] = $v['mailer']['reply_to']; |
||
55 | } |
||
56 | if (!isset($v['password_reset']['mailer']['reply_to'])) { |
||
57 | $v['password_reset']['mailer']['reply_to'] = $v['mailer']['reply_to']; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | return $v; |
||
62 | }) |
||
63 | ->end() |
||
64 | ->children() |
||
65 | ->scalarNode('storage') |
||
66 | ->validate() |
||
67 | ->ifNotInArray($supportedStorages) |
||
68 | ->thenInvalid('The driver %s is not supported. Please choose one of ' . json_encode($supportedStorages)) |
||
69 | ->end() |
||
70 | ->cannotBeOverwritten() |
||
71 | ->isRequired() |
||
72 | ->cannotBeEmpty() |
||
73 | ->end() |
||
74 | ->scalarNode('firewall_name')->isRequired()->cannotBeEmpty()->end() |
||
75 | ->arrayNode('model') |
||
76 | ->isRequired() |
||
77 | ->children() |
||
78 | ->scalarNode('user')->cannotBeEmpty()->isRequired()->end() |
||
79 | ->end() |
||
80 | ->end() |
||
81 | ->arrayNode('mailer') |
||
82 | ->children() |
||
83 | ->scalarNode('from')->defaultNull()->end() |
||
84 | ->scalarNode('reply_to')->defaultNull()->end() |
||
85 | ->end() |
||
86 | ->end() |
||
87 | ->arrayNode('activation') |
||
88 | ->isRequired() |
||
89 | ->addDefaultsIfNotSet() |
||
90 | ->children() |
||
91 | ->integerNode('token_ttl') |
||
92 | ->min(0) |
||
93 | ->defaultValue(43200) // 12h |
||
94 | ->max(172800) // 48h |
||
95 | ->end() |
||
96 | ->integerNode('token_length') |
||
97 | ->min(16) |
||
98 | ->defaultValue(32) |
||
99 | ->max(64) |
||
100 | ->end() |
||
101 | ->arrayNode('mailer') |
||
102 | ->isRequired() |
||
103 | ->addDefaultsIfNotSet() |
||
104 | ->children() |
||
105 | ->scalarNode('from')->cannotBeEmpty()->isRequired()->end() |
||
106 | ->scalarNode('template')->defaultValue('@FSiAdminSecurity/Activation/mail.html.twig')->end() |
||
107 | ->scalarNode('reply_to')->defaultNull()->end() |
||
108 | ->end() |
||
109 | ->end() |
||
110 | ->arrayNode('change_password_form') |
||
111 | ->addDefaultsIfNotSet() |
||
112 | ->children() |
||
113 | ->scalarNode('type')->defaultValue($changePasswordFormType)->end() |
||
114 | ->arrayNode('validation_groups') |
||
115 | ->prototype('scalar')->end() |
||
116 | ->defaultValue(['ResetPassword', 'Default']) |
||
117 | ->end() |
||
118 | ->end() |
||
119 | ->end() |
||
120 | ->end() |
||
121 | ->end() |
||
122 | ->arrayNode('password_reset') |
||
123 | ->isRequired() |
||
124 | ->addDefaultsIfNotSet() |
||
125 | ->children() |
||
126 | ->integerNode('token_ttl') |
||
127 | ->min(0) |
||
128 | ->defaultValue(43200) // 12h |
||
129 | ->max(172800) // 48h |
||
130 | ->end() |
||
131 | ->integerNode('token_length') |
||
132 | ->min(16) |
||
133 | ->defaultValue(32) |
||
134 | ->max(64) |
||
135 | ->end() |
||
136 | ->arrayNode('mailer') |
||
137 | ->isRequired() |
||
138 | ->addDefaultsIfNotSet() |
||
139 | ->children() |
||
140 | ->scalarNode('from')->cannotBeEmpty()->isRequired()->end() |
||
141 | ->scalarNode('template')->defaultValue('@FSiAdminSecurity/PasswordReset/mail.html.twig')->end() |
||
142 | ->scalarNode('reply_to')->defaultNull()->end() |
||
143 | ->end() |
||
144 | ->end() |
||
145 | ->arrayNode('change_password_form') |
||
146 | ->addDefaultsIfNotSet() |
||
147 | ->children() |
||
148 | ->scalarNode('type')->defaultValue($changePasswordFormType)->end() |
||
149 | ->arrayNode('validation_groups') |
||
150 | ->prototype('scalar')->end() |
||
151 | ->defaultValue(['ResetPassword', 'Default']) |
||
152 | ->end() |
||
153 | ->end() |
||
154 | ->end() |
||
155 | ->arrayNode('request_form') |
||
156 | ->addDefaultsIfNotSet() |
||
157 | ->children() |
||
158 | ->scalarNode('type')->defaultValue($resetRequestFormType)->end() |
||
159 | ->end() |
||
160 | ->end() |
||
161 | ->end() |
||
162 | ->end() |
||
163 | ->arrayNode('change_password') |
||
164 | ->addDefaultsIfNotSet() |
||
165 | ->children() |
||
166 | ->arrayNode('form') |
||
167 | ->addDefaultsIfNotSet() |
||
168 | ->children() |
||
169 | ->scalarNode('type')->defaultValue($adminChangePasswordFormType)->end() |
||
170 | ->arrayNode('validation_groups') |
||
171 | ->prototype('scalar')->end() |
||
172 | ->defaultValue(['ChangePassword', 'Default']) |
||
173 | ->end() |
||
174 | ->end() |
||
175 | ->end() |
||
176 | ->end() |
||
177 | ->end() |
||
178 | ->arrayNode('templates') |
||
179 | ->addDefaultsIfNotSet() |
||
180 | ->children() |
||
181 | ->scalarNode('login')->defaultValue('@FSiAdminSecurity/Security/login.html.twig')->end() |
||
182 | ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/Admin/change_password.html.twig')->end() |
||
183 | ->arrayNode('activation') |
||
184 | ->addDefaultsIfNotSet() |
||
185 | ->children() |
||
186 | ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/Activation/change_password.html.twig')->end() |
||
187 | ->end() |
||
188 | ->end() |
||
189 | ->arrayNode('password_reset') |
||
190 | ->addDefaultsIfNotSet() |
||
191 | ->children() |
||
192 | ->scalarNode('request')->defaultValue('@FSiAdminSecurity/PasswordReset/request.html.twig')->end() |
||
193 | ->scalarNode('change_password')->defaultValue('@FSiAdminSecurity/PasswordReset/change_password.html.twig')->end() |
||
194 | ->end() |
||
195 | ->end() |
||
196 | ->end() |
||
197 | ->end() |
||
198 | ->end() |
||
199 | ; |
||
200 | |||
201 | return $treeBuilder; |
||
202 | } |
||
204 |