Conditions | 1 |
Paths | 1 |
Total Lines | 152 |
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 |
||
117 | private function init($sTranslationDir, $sTemplateDir) |
||
118 | { |
||
119 | /* |
||
120 | * Parameters |
||
121 | */ |
||
122 | // Translation directory |
||
123 | $this->libContainer['jaxon.core.translation_dir'] = $sTranslationDir; |
||
124 | // Template directory |
||
125 | $this->libContainer['jaxon.core.template_dir'] = $sTemplateDir; |
||
126 | |||
127 | /* |
||
128 | * Core library objects |
||
129 | */ |
||
130 | // Global Response |
||
131 | $this->libContainer[Response::class] = function() { |
||
132 | return new Response(); |
||
133 | }; |
||
134 | // Dialog |
||
135 | $this->libContainer[Dialog::class] = function() { |
||
136 | return new Dialog(); |
||
137 | }; |
||
138 | // Jaxon App |
||
139 | $this->libContainer[App::class] = function() { |
||
140 | return new App(); |
||
141 | }; |
||
142 | // Jaxon App bootstrap |
||
143 | $this->libContainer[Bootstrap::class] = function() { |
||
144 | return new Bootstrap(); |
||
145 | }; |
||
146 | |||
147 | /* |
||
148 | * Plugins |
||
149 | */ |
||
150 | // Callable objects repository |
||
151 | $this->libContainer[CallableRepository::class] = function() { |
||
152 | return new CallableRepository(); |
||
153 | }; |
||
154 | // Callable objects registry |
||
155 | $this->libContainer[CallableRegistry::class] = function($c) { |
||
156 | return new CallableRegistry($c[CallableRepository::class]); |
||
157 | }; |
||
158 | // Callable class plugin |
||
159 | $this->libContainer[CallableClass::class] = function($c) { |
||
160 | return new CallableClass($c[CallableRegistry::class], $c[CallableRepository::class]); |
||
161 | }; |
||
162 | // Callable dir plugin |
||
163 | $this->libContainer[CallableDir::class] = function($c) { |
||
164 | return new CallableDir($c[CallableRegistry::class]); |
||
165 | }; |
||
166 | // Callable function plugin |
||
167 | $this->libContainer[CallableFunction::class] = function() { |
||
168 | return new CallableFunction(); |
||
169 | }; |
||
170 | // File upload support |
||
171 | $this->libContainer[FileUploadSupport::class] = function() { |
||
172 | return new FileUploadSupport(); |
||
173 | }; |
||
174 | // File upload plugin |
||
175 | $this->libContainer[FileUpload::class] = function($c) { |
||
176 | return new FileUpload($c[FileUploadSupport::class]); |
||
177 | }; |
||
178 | // JQuery response plugin |
||
179 | $this->libContainer[JQueryPlugin::class] = function() { |
||
180 | return new JQueryPlugin(); |
||
181 | }; |
||
182 | |||
183 | /* |
||
184 | * Managers |
||
185 | */ |
||
186 | // Plugin Manager |
||
187 | $this->libContainer[PluginManager::class] = function() { |
||
188 | return new PluginManager(); |
||
189 | }; |
||
190 | // Request Handler |
||
191 | $this->libContainer[RequestHandler::class] = function($c) { |
||
192 | return new RequestHandler($c[PluginManager::class], $c[ResponseManager::class], $c[FileUpload::class]); |
||
193 | }; |
||
194 | // Request Factory |
||
195 | $this->libContainer[RequestFactory::class] = function($c) { |
||
196 | return new RequestFactory($c[CallableRegistry::class]); |
||
197 | }; |
||
198 | // Parameter Factory |
||
199 | $this->libContainer[ParameterFactory::class] = function() { |
||
200 | return new ParameterFactory(); |
||
201 | }; |
||
202 | // Response Manager |
||
203 | $this->libContainer[ResponseManager::class] = function() { |
||
204 | return new ResponseManager(); |
||
205 | }; |
||
206 | // Code Generator |
||
207 | $this->libContainer[CodeGenerator::class] = function($c) { |
||
208 | return new CodeGenerator($c[PluginManager::class], $c[TemplateEngine::class]); |
||
209 | }; |
||
210 | // View Manager |
||
211 | $this->libContainer[ViewManager::class] = function() { |
||
212 | return new ViewManager(); |
||
213 | }; |
||
214 | // View Renderer |
||
215 | $this->libContainer[ViewRenderer::class] = function($c) { |
||
216 | return new ViewRenderer($c[ViewManager::class]); |
||
217 | }; |
||
218 | |||
219 | /* |
||
220 | * Config |
||
221 | */ |
||
222 | $this->libContainer[Config::class] = function() { |
||
223 | return new Config(); |
||
224 | }; |
||
225 | $this->libContainer[ConfigReader::class] = function() { |
||
226 | return new ConfigReader(); |
||
227 | }; |
||
228 | |||
229 | /* |
||
230 | * Services |
||
231 | */ |
||
232 | // Minifier |
||
233 | $this->libContainer[Minifier::class] = function() { |
||
234 | return new Minifier(); |
||
235 | }; |
||
236 | // Translator |
||
237 | $this->libContainer[Translator::class] = function($c) { |
||
238 | return new Translator($c['jaxon.core.translation_dir'], $c[Config::class]); |
||
239 | }; |
||
240 | // Template engine |
||
241 | $this->libContainer[TemplateEngine::class] = function($c) { |
||
242 | return new TemplateEngine($c['jaxon.core.template_dir']); |
||
243 | }; |
||
244 | // Template Renderer |
||
245 | $this->libContainer[TemplateRenderer::class] = function($c) { |
||
246 | return $c[TemplateEngine::class]; |
||
247 | }; |
||
248 | // Validator |
||
249 | $this->libContainer[Validator::class] = function($c) { |
||
250 | return new Validator($c[Translator::class], $c[Config::class]); |
||
251 | }; |
||
252 | // Pagination Paginator |
||
253 | $this->libContainer[Paginator::class] = function($c) { |
||
254 | return new Paginator($c[PaginationRenderer::class]); |
||
255 | }; |
||
256 | // Pagination Renderer |
||
257 | $this->libContainer[PaginationRenderer::class] = function($c) { |
||
258 | return new PaginationRenderer($c[TemplateRenderer::class]); |
||
259 | }; |
||
260 | // Event Dispatcher |
||
261 | $this->libContainer[EventDispatcher::class] = function() { |
||
262 | return new EventDispatcher(); |
||
263 | }; |
||
264 | // URI decoder |
||
265 | $this->libContainer[URI::class] = function() { |
||
266 | return new URI(); |
||
267 | }; |
||
268 | } |
||
269 | |||
594 |