Skip to content

Commit

Permalink
Refactoring duplicated code into a method.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 29, 2009
1 parent 2a8858e commit f299283
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -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'];
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit f299283

Please sign in to comment.