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