Conditions | 17 |
Paths | 270 |
Total Lines | 83 |
Code Lines | 46 |
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 |
||
99 | public function __construct(Array $config) |
||
100 | { |
||
101 | # start sessions |
||
102 | if (!isset($_SESSION)) |
||
103 | session_start(); |
||
104 | |||
105 | if (!array_key_exists('environment', $config)) |
||
106 | throw new \InvalidArgumentException("The 'environment' key was not defined"); |
||
107 | |||
108 | if (!array_key_exists('dev_mode', $config['environment'])) |
||
109 | throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
||
110 | |||
111 | $this->devMode = $config["environment"]["dev_mode"]; |
||
112 | |||
113 | if (!array_key_exists('modules', $config)) |
||
114 | throw new \InvalidArgumentException("The 'modules' key was not defined"); |
||
115 | |||
116 | $this->modules = $config["modules"]; |
||
117 | |||
118 | # setting module path |
||
119 | $this->modulePath = (!array_key_exists('module_path', $config['environment'])) |
||
120 | ? 'module' |
||
121 | : $config['environment']['module_path']; |
||
122 | |||
123 | # setting development or production environment |
||
124 | if ($this->devMode) |
||
125 | { |
||
126 | ini_set('display_errors', 1); |
||
127 | error_reporting(-1); |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | ini_set('display_errors', 0); |
||
132 | error_reporting(0); |
||
133 | } |
||
134 | |||
135 | if (!array_key_exists('router', $config)) |
||
136 | throw new \InvalidArgumentException("The 'router' key was not defined"); |
||
137 | |||
138 | if (!array_key_exists('routes', $config["router"])) |
||
139 | throw new \InvalidArgumentException("The 'routes' key was not defined"); |
||
140 | |||
141 | $this->router = new Router($config["router"]["routes"]); |
||
142 | |||
143 | if (!array_key_exists('base_path', $config['environment'])) |
||
144 | throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
||
145 | |||
146 | $this->basePath = $config["environment"]["base_path"]; |
||
147 | |||
148 | # load routes from config |
||
149 | foreach ($config["router"]["routes"] as $name => $route) |
||
150 | { |
||
151 | if ($route instanceof \Zend\Router\Http\RouteInterface) |
||
152 | $this->router->addZendRoute($name, $route); |
||
153 | else |
||
154 | $this->router->addRoute($route); |
||
155 | } |
||
156 | |||
157 | # register autoloading functions for each module |
||
158 | foreach ($this->modules as $module) |
||
159 | { |
||
160 | \Drone\Loader\ClassMap::$path = $this->basePath . |
||
161 | DIRECTORY_SEPARATOR . $this->modulePath . |
||
162 | DIRECTORY_SEPARATOR . $module . |
||
163 | DIRECTORY_SEPARATOR . 'source'; |
||
164 | |||
165 | spl_autoload_register("Drone\Loader\ClassMap::autoload"); |
||
166 | } |
||
167 | |||
168 | # load routes from each module |
||
169 | foreach ($this->modules as $module) |
||
170 | { |
||
171 | if (file_exists($this->modulePath . "/$module/config/module.config.php")) |
||
172 | { |
||
173 | $module_config_file = require($this->modulePath . "/$module/config/module.config.php"); |
||
174 | |||
175 | if (!array_key_exists('router', $module_config_file)) |
||
176 | throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
||
177 | |||
178 | if (!array_key_exists('routes', $module_config_file["router"])) |
||
179 | throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
||
180 | |||
181 | $this->getRouter()->addRoute($module_config_file["router"]["routes"]); |
||
182 | } |
||
250 | } |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.