Conditions | 9 |
Paths | 11 |
Total Lines | 52 |
Code Lines | 26 |
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 |
||
33 | public function create($params, $controller) |
||
34 | { |
||
35 | // nombre de archivo |
||
36 | $file = APP_PATH . 'controllers'; |
||
37 | |||
38 | // limpia el path de controller |
||
39 | $clean_path = trim($controller, '/'); |
||
40 | |||
41 | // obtiene el path |
||
42 | $path = explode('/', $clean_path); |
||
43 | |||
44 | // obtiene el nombre de controlador |
||
45 | $controller_name = array_pop($path); |
||
46 | |||
47 | // si se agrupa el controlador en un directorio |
||
48 | if (count($path)) { |
||
49 | $dir = implode('/', $path); |
||
50 | $file .= "/$dir"; |
||
51 | if (!is_dir($file) && !FileUtil::mkdir($file)) { |
||
52 | throw new KumbiaException("No se ha logrado crear el directorio \"$file\""); |
||
53 | } |
||
54 | } |
||
55 | $file .= "/{$controller_name}_controller.php"; |
||
56 | |||
57 | // si no existe o se sobreescribe |
||
58 | if (!is_file($file) || |
||
59 | Console::input("El controlador existe, ¿desea sobrescribirlo? (s/n): ", array('s', 'n')) == 's') { |
||
60 | |||
61 | // nombre de clase |
||
62 | $class = Util::camelcase($controller_name); |
||
63 | |||
64 | // codigo de controlador |
||
65 | ob_start(); |
||
66 | include __DIR__ . '/generators/controller.php'; |
||
67 | $code = '<?php' . PHP_EOL . ob_get_clean(); |
||
68 | |||
69 | // genera el archivo |
||
70 | if (file_put_contents($file, $code)) { |
||
71 | echo "-> Creado controlador $controller_name en: $file" . PHP_EOL; |
||
72 | } else { |
||
73 | throw new KumbiaException("No se ha logrado crear el archivo \"$file\""); |
||
74 | } |
||
75 | |||
76 | // directorio para vistas |
||
77 | $views_dir = APP_PATH . "views/$clean_path"; |
||
78 | |||
79 | //si el directorio no existe |
||
80 | if (!is_dir($views_dir)) { |
||
81 | if (FileUtil::mkdir($views_dir)) { |
||
82 | echo "-> Creado directorio para vistas: $views_dir" . PHP_EOL; |
||
83 | } else { |
||
84 | throw new KumbiaException("No se ha logrado crear el directorio \"$views_dir\""); |
||
85 | } |
||
136 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.