Conditions | 33 |
Paths | 186 |
Total Lines | 74 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
33 | public static function create($model, $action = NULL) |
||
34 | { |
||
35 | |||
36 | $model_name = Util::smallcase(get_class($model)); |
||
37 | if (!$action) |
||
38 | $action = ltrim(Router::get('route'), '/'); |
||
39 | |||
40 | echo '<form action="', PUBLIC_PATH . $action, '" method="post" id="', $model_name, '" class="scaffold">' , PHP_EOL; |
||
41 | $pk = $model->primary_key[0]; |
||
42 | echo '<input id="', $model_name, '_', $pk, '" name="', $model_name, '[', $pk, ']" class="id" value="', $model->$pk , '" type="hidden">' , PHP_EOL; |
||
43 | |||
44 | $fields = array_diff($model->fields, $model->_at, $model->_in, $model->primary_key); |
||
45 | |||
46 | foreach ($fields as $field) { |
||
47 | |||
48 | $tipo = trim(preg_replace('/(\(.*\))/', '', $model->_data_type[$field])); //TODO: recoger tamaño y otros valores |
||
49 | $alias = $model->get_alias($field); |
||
50 | $formId = $model_name . '_' . $field; |
||
51 | $formName = $model_name . '[' . $field . ']'; |
||
52 | |||
53 | if (in_array($field, $model->not_null)) { |
||
54 | echo "<label for=\"$formId\" class=\"required\">$alias *</label>" , PHP_EOL; |
||
55 | } else |
||
56 | echo "<label for=\"$formId\">$alias</label>" , PHP_EOL; |
||
57 | |||
58 | switch ($tipo) { |
||
59 | case 'tinyint': case 'smallint': case 'mediumint': |
||
60 | case 'integer': case 'int': case 'bigint': |
||
61 | case 'float': case 'double': case 'precision': |
||
62 | case 'real': case 'decimal': case 'numeric': |
||
63 | case 'year': case 'day': case 'int unsigned': // Números |
||
64 | |||
65 | if (strripos($field, '_id', -3)) { |
||
66 | echo Form::dbSelect($model_name . '.' . $field, NULL, NULL, 'Seleccione', NULL, $model->$field); |
||
67 | break; |
||
68 | } else { |
||
69 | echo "<input id=\"$formId\" type=\"number\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL; |
||
70 | break; |
||
71 | } |
||
72 | |||
73 | case 'date': // Usar el js de datetime |
||
74 | echo "<input id=\"$formId\" type=\"date\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL; |
||
75 | break; |
||
76 | case 'datetime': case 'timestamp': |
||
77 | echo "<input id=\"$formId\" type=\"datetime\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL; |
||
78 | |||
79 | //echo '<script type="text/javascript" src="/javascript/kumbia/jscalendar/calendar.js"></script> |
||
80 | //<script type="text/javascript" src="/javascript/kumbia/jscalendar/calendar-setup.js"></script> |
||
81 | //<script type="text/javascript" src="/javascript/kumbia/jscalendar/calendar-es.js"></script>'.PHP_EOL; |
||
82 | //echo date_field_tag("$formId"); |
||
83 | break; |
||
84 | |||
85 | case 'enum': case 'set': case 'bool': |
||
86 | $enumList = explode(",", str_replace("'", "", substr($model->_data_type[$field], 5, (strlen($model->_data_type[$field])-6)))); |
||
87 | echo "<select id=\"$formId\" class=\"select\" name=\"$formName\" >", PHP_EOL; |
||
88 | foreach($enumList as $value) |
||
89 | echo "<option value=\"{$value}\">$value</option>", PHP_EOL; |
||
90 | echo '</select>', PHP_EOL; |
||
91 | break; |
||
92 | |||
93 | case 'text': case 'mediumtext': case 'longtext': |
||
94 | case 'blob': case 'mediumblob': case 'longblob': // Usar textarea |
||
95 | echo "<textarea id=\"$formId\" name=\"$formName\">{$model->$field}</textarea>" , PHP_EOL; |
||
96 | break; |
||
97 | |||
98 | default: //text,tinytext,varchar, char,etc se comprobara su tamaño |
||
99 | echo "<input id=\"$formId\" type=\"text\" name=\"$formName\" value=\"{$model->$field}\">" , PHP_EOL; |
||
100 | //break; |
||
101 | } |
||
102 | } |
||
103 | //echo radio_field_tag("actuacion", array("U" => "una", "D" => "dos", "N" => "Nada"), "value: N"); |
||
104 | echo '<input type="submit" value="Enviar" />' , PHP_EOL; |
||
105 | echo '</form>' , PHP_EOL; |
||
106 | } |
||
107 | |||
109 |