Conditions | 8 |
Paths | 19 |
Total Lines | 65 |
Code Lines | 28 |
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 |
||
129 | public static function dispatch($argv) |
||
130 | { |
||
131 | // Elimino el nombre de archivo del array de argumentos |
||
132 | array_shift($argv); |
||
133 | |||
134 | // obtiene el nombre de consola |
||
135 | $console_name = array_shift($argv); |
||
136 | if (!$console_name) { |
||
137 | throw new KumbiaException('No ha indicado la consola a ejecutar'); |
||
138 | } |
||
139 | |||
140 | // obtiene el nombre de comando a ejecutar |
||
141 | $command = array_shift($argv); |
||
142 | if (!$command) { |
||
143 | $command = 'main'; |
||
144 | } |
||
145 | |||
146 | // Obtiene los argumentos para la consola, el primer argumento |
||
147 | // es el array de parametros nombrados para terminal |
||
148 | $args = self::_getConsoleArgs($argv); |
||
149 | |||
150 | // verifica el path de aplicacion |
||
151 | if (isset($args[0]['path'])) { |
||
152 | $dir = realpath($args[0]['path']); |
||
153 | if (!$dir) { |
||
154 | throw new KumbiaException("La ruta \"{$args[0]['path']}\" es invalida"); |
||
155 | } |
||
156 | // elimina el parametro path del array |
||
157 | unset($args[0]['path']); |
||
158 | } else { |
||
159 | // obtiene el directorio de trabajo actual |
||
160 | $dir = getcwd(); |
||
161 | } |
||
162 | |||
163 | // define el path de la aplicacion |
||
164 | define('APP_PATH', rtrim($dir, '/') . '/'); |
||
165 | |||
166 | // lee la configuracion |
||
167 | $config = Config::read('config'); |
||
168 | |||
169 | // constante que indica si la aplicacion se encuentra en produccion |
||
170 | define('PRODUCTION', $config['application']['production']); |
||
171 | |||
172 | // crea la consola |
||
173 | $console = self::load($console_name); |
||
174 | |||
175 | // verifica que exista el comando en la consola |
||
176 | if (!method_exists($console, $command)) { |
||
177 | throw new KumbiaException("El comando \"$command\" no existe para la consola \"$console_name\""); |
||
178 | } |
||
179 | |||
180 | // si se intenta ejecutar |
||
181 | if ($command == 'initialize') { |
||
182 | throw new KumbiaException("El comando initialize es un comando reservado"); |
||
183 | } |
||
184 | |||
185 | // verifica los parametros para la accion de consola |
||
186 | $reflectionMethod = new ReflectionMethod($console, $command); |
||
187 | if (count($args) < $reflectionMethod->getNumberOfRequiredParameters()) { |
||
188 | throw new KumbiaException("Número de parametros erroneo para ejecutar el comando \"$command\" en la consola \"$console_name\""); |
||
189 | } |
||
190 | |||
191 | // ejecuta el comando |
||
192 | call_user_func_array(array($console, $command), $args); |
||
193 | } |
||
194 | |||
222 |