| Conditions | 1 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 45 |
| 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 |
||
| 32 | public function getContainer() |
||
| 33 | { |
||
| 34 | $container = new Container(); |
||
| 35 | |||
| 36 | // LoggerAdapter |
||
| 37 | $container->logger = function () { |
||
|
|
|||
| 38 | $instance = Logger::getInstance(); |
||
| 39 | $instance->setOutputter([ |
||
| 40 | new FileOutputter($instance->getConfig()->logPath) |
||
| 41 | ]); |
||
| 42 | |||
| 43 | return new LoggerAdapter($instance); |
||
| 44 | }; |
||
| 45 | // Request |
||
| 46 | $container->request = function () use (&$container) { |
||
| 47 | $request = new Request(); |
||
| 48 | $request->inject('logger', $container->logger); |
||
| 49 | |||
| 50 | return $request->getContainer(); |
||
| 51 | }; |
||
| 52 | // Response |
||
| 53 | $container->response = function () use (&$container) { |
||
| 54 | $response = new Response(); |
||
| 55 | $response->inject('logger', $container->logger); |
||
| 56 | |||
| 57 | return $response; |
||
| 58 | }; |
||
| 59 | // Session |
||
| 60 | $container->session = function () use (&$container) { |
||
| 61 | $session = new Session(); |
||
| 62 | $session->inject('logger', $container->logger); |
||
| 63 | |||
| 64 | return $session; |
||
| 65 | }; |
||
| 66 | // Router |
||
| 67 | $container->router = function () use (&$container) { |
||
| 68 | // Router |
||
| 69 | $config = \Spyc::YAMLLoad($container->applicationInfo->applicationRoot . $container->applicationInfo->routeConfigPath); |
||
| 70 | $router = new Router($config, $container->request); |
||
| 71 | $router->inject('logger', $container->logger) |
||
| 72 | ->inject('applicationInfo', $container->applicationInfo); |
||
| 73 | $router->resolve(); |
||
| 74 | |||
| 75 | return $router->getRoutingResult(); |
||
| 76 | }; |
||
| 77 | // CoreDelegator |
||
| 78 | $container->coreDelegator = function () use (&$container) { |
||
| 79 | return new CoreDelegator($container); |
||
| 80 | }; |
||
| 81 | // AnnotationDelegator |
||
| 82 | $container->annotationDelegator = function () use (&$container) { |
||
| 83 | return new AnnotationDelegator($container); |
||
| 84 | }; |
||
| 85 | // twig |
||
| 86 | $container->twig = function () { |
||
| 87 | Twig_Autoloader::register(); |
||
| 88 | }; |
||
| 89 | // Application Info |
||
| 90 | $applicationRoot = $this->getApplicationRoot(); |
||
| 91 | $container->applicationInfo = function () use ($applicationRoot) { |
||
| 92 | $info = new Container(); |
||
| 93 | $info->applicationRoot = $applicationRoot; |
||
| 94 | $info->applicationDir = "app"; |
||
| 95 | $info->sharedDir = "_shared"; |
||
| 96 | $info->publicDir = "_public"; |
||
| 97 | $info->cacheDir = "_cache"; |
||
| 98 | $info->cachePrefix = "webstream-cache-"; |
||
| 99 | $info->routeConfigPath = "/config/routes.yml"; |
||
| 100 | $info->validateRuleDir = "core/WebStream/Validate/Rule/"; |
||
| 101 | |||
| 102 | return $info; |
||
| 103 | }; |
||
| 104 | |||
| 105 | return $container; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.