| Conditions | 5 |
| Paths | 14 |
| Total Lines | 80 |
| 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 |
||
| 24 | public function run() |
||
| 25 | { |
||
| 26 | // DI Container |
||
| 27 | $container = new FactoryDefault(); |
||
| 28 | |||
| 29 | // Initialize app |
||
| 30 | $app = new PhalconApplication($container); |
||
| 31 | |||
| 32 | // Set serverCache service |
||
| 33 | $container->setShared('serverCache', (new ApcuCache())->init()); |
||
| 34 | |||
| 35 | // Env configuration |
||
| 36 | $configLoader = new EnvironmentLoader(); |
||
| 37 | $configLoader->setDI($container); |
||
| 38 | $configLoader->load(); |
||
| 39 | |||
| 40 | if ('development' === getenv('APP_ENV')) { |
||
| 41 | $debug = new Debug(); |
||
| 42 | $debug->listen(); |
||
| 43 | } |
||
| 44 | |||
| 45 | // Create EventsManager Manager |
||
| 46 | $webEventsManager = new EventsManager($container); |
||
| 47 | $eventsManager = $webEventsManager->getEventsManager(); |
||
| 48 | |||
| 49 | // Save Events Manager to DI Container |
||
| 50 | $container->setShared('eventsManager', $eventsManager); |
||
| 51 | |||
| 52 | // Bind Events Manager to Application |
||
| 53 | $app->setEventsManager($container->get('eventsManager')); |
||
| 54 | |||
| 55 | // Router |
||
| 56 | $webRouter = new Router($container, $eventsManager); |
||
| 57 | $container->setShared('router', $webRouter->getRouter()); |
||
| 58 | |||
| 59 | // Register Web Modules |
||
| 60 | $this->registerWebApplicationModules($app); |
||
| 61 | |||
| 62 | // Annotations |
||
| 63 | $annotationsManager = new AnnotationsManager($container); |
||
| 64 | $container->setShared('annotations', $annotationsManager->getAnnotations()); |
||
| 65 | |||
| 66 | // ACL |
||
| 67 | $aclManager = new AclManager($container, $eventsManager); |
||
| 68 | $container->setShared('acl', $aclManager->getAcl()); |
||
| 69 | |||
| 70 | // Default View |
||
| 71 | $webView = new View(); |
||
| 72 | $webView->setEventsManager($eventsManager); |
||
| 73 | $container->setShared('view', $webView); |
||
| 74 | |||
| 75 | // Url |
||
| 76 | $url = new Url(); |
||
| 77 | $url->setBaseUri('/'); |
||
| 78 | $container->setShared('url', $url); |
||
| 79 | |||
| 80 | // Assets Build Resolver |
||
| 81 | $assetsHelper = new AssetsHelper($container); |
||
| 82 | $container->setShared('assetsHelper', $assetsHelper); |
||
| 83 | |||
| 84 | // @TODO Move it to another place |
||
| 85 | // Tag |
||
| 86 | Tag::setTitleSeparator(' - '); |
||
| 87 | Tag::setTitle('Yona CMS'); |
||
| 88 | |||
| 89 | try { |
||
| 90 | // Handle request |
||
| 91 | $response = $app->handle($_SERVER['REQUEST_URI']); |
||
| 92 | $response->send(); |
||
| 93 | } catch (AccessDeniedException $e) { |
||
| 94 | // Access Denied |
||
| 95 | $this->handleAccessDenied($app); |
||
| 96 | } catch (Dispatcher\Exception $e) { |
||
| 97 | // 404 Not Found |
||
| 98 | $this->notFoundError($app); |
||
| 99 | } catch (\Exception $e) { |
||
| 100 | // 503 Server Error |
||
| 101 | $this->serviceUnavailableError($app, $e); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 154 |