| Conditions | 8 |
| Paths | 8 |
| Total Lines | 71 |
| Code Lines | 46 |
| Lines | 24 |
| Ratio | 33.8 % |
| Changes | 10 | ||
| 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 |
||
| 68 | private function initialize() |
||
| 69 | { |
||
| 70 | $container = $this->container; |
||
| 71 | $classLoader = new ClassLoader(); |
||
| 72 | $classLoader->inject('logger', $container->logger) |
||
| 73 | ->inject('applicationInfo', $container->applicationInfo); |
||
| 74 | $pageName = $this->getPageName(); |
||
| 75 | $serviceClassName = $pageName . "Service"; |
||
| 76 | $modelClassName = $pageName . "Model"; |
||
| 77 | $helperClassName = $pageName . "Helper"; |
||
| 78 | $appRoot = $container->applicationInfo->applicationRoot . "/app"; |
||
| 79 | $controllerNamespace = $this->getNamespace($appRoot, $container->router->controller); |
||
| 80 | $serviceNamespace = $this->getNamespace($appRoot, $serviceClassName); |
||
| 81 | $modelNamespace = $this->getNamespace($appRoot, $modelClassName); |
||
| 82 | $helperNamespace = $this->getNamespace($appRoot, $helperClassName); |
||
| 83 | |||
| 84 | // Controller |
||
| 85 | $this->coreContainer->controller = function () use ($container, $controllerNamespace) { |
||
| 86 | $controllerClassPath = $controllerNamespace . "\\" . $container->router->controller; |
||
| 87 | if (!class_exists($controllerClassPath)) { |
||
| 88 | throw new ClassNotFoundException("Undefined class path: " . $controllerClassPath); |
||
| 89 | } |
||
| 90 | |||
| 91 | return new $controllerClassPath($container); |
||
| 92 | }; |
||
| 93 | |||
| 94 | // View |
||
| 95 | $this->coreContainer->view = function () use ($container) { |
||
| 96 | return new CoreView($container); |
||
| 97 | }; |
||
| 98 | |||
| 99 | // Service |
||
| 100 | if ($serviceNamespace !== null) { |
||
| 101 | $serviceClassPath = $serviceNamespace . "\\" . $serviceClassName; |
||
| 102 | $this->coreContainer->service = function () use ($container, $classLoader, $serviceClassPath, $serviceClassName) { |
||
| 103 | if ($classLoader->import($container->applicationInfo->applicationDir . "/services/" . $serviceClassName . ".php")) { |
||
| 104 | return new $serviceClassPath($container); |
||
| 105 | } |
||
| 106 | }; |
||
| 107 | } else { |
||
| 108 | $this->coreContainer->service = function () {}; |
||
| 109 | } |
||
| 110 | |||
| 111 | // Model |
||
| 112 | View Code Duplication | if ($modelNamespace !== null) { |
|
| 113 | $modelClassPath = $modelNamespace . "\\" . $modelClassName; |
||
| 114 | $this->coreContainer->model = function () use ($container, $classLoader, $modelClassPath, $modelClassName) { |
||
| 115 | if ($classLoader->import($container->applicationInfo->applicationDir . "/models/" . $modelClassName . ".php")) { |
||
| 116 | return new $modelClassPath($container); |
||
| 117 | } |
||
| 118 | }; |
||
| 119 | } else { |
||
| 120 | $classpath = "\WebStream\Exception\Extend\ClassNotFoundException"; |
||
| 121 | $message = $pageName . "Service and " . $pageName . "Model is not defined."; |
||
| 122 | $this->coreContainer->model = new CoreExceptionDelegator($classpath, $message); |
||
| 123 | } |
||
| 124 | |||
| 125 | // Helper |
||
| 126 | View Code Duplication | if ($helperNamespace !== null) { |
|
| 127 | $helperClassPath = $helperNamespace . "\\" . $helperClassName; |
||
| 128 | $this->coreContainer->helper = function () use ($container, $classLoader, $helperClassPath, $helperClassName) { |
||
| 129 | if ($classLoader->import($container->applicationInfo->applicationDir . "/helpers/" . $helperClassName . ".php")) { |
||
| 130 | return new $helperClassPath($container); |
||
| 131 | } |
||
| 132 | }; |
||
| 133 | } else { |
||
| 134 | $classpath = "\WebStream\Exception\Extend\ClassNotFoundException"; |
||
| 135 | $message = $pageName . "Helper is not defined."; |
||
| 136 | $this->coreContainer->helper = new CoreExceptionDelegator($classpath, $message); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 218 |
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.