Permalink
Browse files

Refactoring duplicated code into a method.

  • Loading branch information...
markstory committed Oct 29, 2009
1 parent 2a8858e commit f299283dc4915646339718e74ff6b3d84abdad3a
Showing with 17 additions and 15 deletions.
  1. +17 −15 cake/libs/model/datasources/dbo_source.php
@@ -2459,16 +2459,7 @@ function buildColumn($column) {
if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default']) && $column['default'] === '') {
$column['default'] = null;
}
-
- foreach ($this->fieldParameters as $paramName => $value) {
- if (isset($column[$paramName]) && $value['position'] == 'beforeDefault') {
- $val = $column[$paramName];
- if ($value['quote']) {
- $val = $this->value($val);
- }
- $out .= ' ' . $value['value'] . $value['join'] . $val;
- }
- }
+ $out = $this->_buildFieldParameters($out, $column, 'beforeDefault');
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
@@ -2483,18 +2474,29 @@ function buildColumn($column) {
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
+ $out = $this->_buildFieldParameters($out, $column, 'afterDefault');
+ return $out;
+ }
+/**
+ * Build the field parameters, in a position
+ *
+ * @param string $columnString The partially built column string
+ * @param array $columnData The array of column data.
+ * @param string $position The position type to use. 'beforeDefault' or 'afterDefault' are common
+ * @return string a built column with the field parameters added.
+ **/
+ function _buildFieldParameters($columnString, $columnData, $position) {
foreach ($this->fieldParameters as $paramName => $value) {
- if (isset($column[$paramName]) && $value['position'] == 'afterDefault') {
- $val = $column[$paramName];
+ if (isset($columnData[$paramName]) && $value['position'] == $position) {
+ $val = $columnData[$paramName];
if ($value['quote']) {
$val = $this->value($val);
}
- $out .= ' ' . $value['value'] . $value['join'] . $val;
+ $columnString .= ' ' . $value['value'] . $value['join'] . $val;
}
}
-
- return $out;
+ return $columnString;
}
/**

0 comments on commit f299283

Please sign in to comment.