| Conditions | 16 |
| Paths | 150 |
| Total Lines | 75 |
| Code Lines | 41 |
| 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 |
||
| 92 | public function __construct(Array $config) |
||
| 93 | { |
||
| 94 | # start sessions |
||
| 95 | if (!isset($_SESSION)) |
||
| 96 | session_start(); |
||
| 97 | |||
| 98 | if (!array_key_exists('environment', $config)) |
||
| 99 | throw new \InvalidArgumentException("The 'environment' key was not defined"); |
||
| 100 | |||
| 101 | if (!array_key_exists('dev_mode', $config['environment'])) |
||
| 102 | throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
||
| 103 | |||
| 104 | $this->devMode = $config["environment"]["dev_mode"]; |
||
| 105 | |||
| 106 | if (!array_key_exists('modules', $config)) |
||
| 107 | throw new \InvalidArgumentException("The 'modules' key was not defined"); |
||
| 108 | |||
| 109 | $this->modules = $config["modules"]; |
||
| 110 | |||
| 111 | # setting module path |
||
| 112 | $this->modulePath = (!array_key_exists('module_path', $config['environment'])) |
||
| 113 | ? 'module' |
||
| 114 | : $config['environment']['module_path']; |
||
| 115 | |||
| 116 | # setting development or production environment |
||
| 117 | if ($this->devMode) |
||
| 118 | { |
||
| 119 | ini_set('display_errors', 1); |
||
| 120 | error_reporting(-1); |
||
| 121 | } |
||
| 122 | else |
||
| 123 | { |
||
| 124 | ini_set('display_errors', 0); |
||
| 125 | error_reporting(0); |
||
| 126 | } |
||
| 127 | |||
| 128 | # register autoloading functions for each module |
||
| 129 | $this->autoload($this->modules); |
||
| 130 | |||
| 131 | if (!array_key_exists('router', $config)) |
||
| 132 | throw new \InvalidArgumentException("The 'router' key was not defined"); |
||
| 133 | |||
| 134 | if (!array_key_exists('routes', $config["router"])) |
||
| 135 | throw new \InvalidArgumentException("The 'routes' key was not defined"); |
||
| 136 | |||
| 137 | $this->router = new Router($config["router"]["routes"]); |
||
| 138 | |||
| 139 | if (!array_key_exists('base_path', $config['environment'])) |
||
| 140 | throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
||
| 141 | |||
| 142 | $this->router->setBasePath($config["environment"]["base_path"]); |
||
|
|
|||
| 143 | |||
| 144 | # load routes from config |
||
| 145 | foreach ($config["router"]["routes"] as $name => $route) |
||
| 146 | { |
||
| 147 | if ($route instanceof \Zend\Router\Http\RouteInterface) |
||
| 148 | $this->getRouter()->addZendRoute($name, $route); |
||
| 149 | else |
||
| 150 | $this->getRouter()->addRoute($route); |
||
| 151 | } |
||
| 152 | |||
| 153 | # load routes from each module |
||
| 154 | foreach ($this->modules as $module) |
||
| 155 | { |
||
| 156 | if (file_exists($this->modulePath . "/$module/config/module.config.php")) |
||
| 157 | { |
||
| 158 | $module_config_file = require($this->modulePath . "/$module/config/module.config.php"); |
||
| 159 | |||
| 160 | if (!array_key_exists('router', $module_config_file)) |
||
| 161 | throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
||
| 162 | |||
| 163 | if (!array_key_exists('routes', $module_config_file["router"])) |
||
| 164 | throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
||
| 165 | |||
| 166 | $this->getRouter()->addRoute($module_config_file["router"]["routes"]); |
||
| 167 | } |
||
| 255 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.