From f299283dc4915646339718e74ff6b3d84abdad3a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 01:47:25 -0400 Subject: [PATCH] Refactoring duplicated code into a method. --- cake/libs/model/datasources/dbo_source.php | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 141364da8b9..d956c4a51b6 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/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; } /**