Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove duplicated code.
  • Loading branch information
markstory committed May 20, 2013
1 parent 74ad900 commit d9a6f37
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/Cake/Database/Schema/MysqlSchema.php
Expand Up @@ -279,17 +279,7 @@ public function constraintSql(Table $table, $name) {
$out = 'UNIQUE KEY ';
}
$out .= $this->_driver->quoteIdentifier($name);

$columns = array_map(
[$this->_driver, 'quoteIdentifier'],
$data['columns']
);
foreach ($data['columns'] as $i => $column) {
if (isset($data['length'][$column])) {
$columns[$i] .= sprintf('(%d)', $data['length'][$column]);
}
}
return $out . ' (' . implode(', ', $columns) . ')';
return $this->_keySql($out, $data);
}

/**
Expand All @@ -308,7 +298,17 @@ public function indexSql(Table $table, $name) {
$out = 'FULLTEXT KEY ';
}
$out .= $this->_driver->quoteIdentifier($name);
return $this->_keySql($out, $data);
}

/**
* Helper method for generating key SQL snippets.
*
* @param string $prefix The key prefix
* @param array $data Key data.
* @return string
*/
protected function _keySql($prefix, $data) {
$columns = array_map(
[$this->_driver, 'quoteIdentifier'],
$data['columns']
Expand All @@ -318,7 +318,7 @@ public function indexSql(Table $table, $name) {
$columns[$i] .= sprintf('(%d)', $data['length'][$column]);
}
}
return $out . ' (' . implode(', ', $columns) . ')';
return $prefix . ' (' . implode(', ', $columns) . ')';
}

}

0 comments on commit d9a6f37

Please sign in to comment.