Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead code cleanup #91

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Connection.php
Expand Up @@ -1110,7 +1110,7 @@ private function _bindTypedValues($stmt, array $params, array $types)
// Positional parameters
$typeOffset = array_key_exists(0, $types) ? -1 : 0;
$bindIndex = 1;
foreach ($params as $position => $value) {
foreach ($params as $value) {
$typeIndex = $bindIndex + $typeOffset;
if (isset($types[$typeIndex])) {
$type = $types[$typeIndex];
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/DB2Platform.php
Expand Up @@ -358,7 +358,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options

$sqls = parent::_getCreateTableSQL($tableName, $columns, $options);

foreach ($indexes as $index => $definition) {
foreach ($indexes AS $definition) {
$sqls[] = $this->getCreateIndexSQL($definition, $tableName);
}
return $sqls;
Expand All @@ -376,7 +376,7 @@ public function getAlterTableSQL(TableDiff $diff)
$columnSql = array();

$queryParts = array();
foreach ($diff->addedColumns AS $fieldName => $column) {
foreach ($diff->addedColumns AS $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
Expand Up @@ -154,7 +154,6 @@ public function getDropForeignKeySQL($foreignKey, $table)
public function getDropIndexSQL($index, $table=null)
{
if ($index instanceof \Doctrine\DBAL\Schema\Index) {
$index_ = $index;
$index = $index->getQuotedName($this);
} else if (!is_string($index)) {
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
Expand Down Expand Up @@ -284,7 +283,7 @@ public function getAlterTableSQL(TableDiff $diff)
$queryParts[] = 'RENAME TO ' . $diff->newName;
}

foreach ($diff->addedColumns AS $fieldName => $column) {
foreach ($diff->addedColumns AS $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Expand Up @@ -460,7 +460,7 @@ public function getAlterTableSQL(TableDiff $diff)
$queryParts[] = 'RENAME TO ' . $diff->newName;
}

foreach ($diff->addedColumns AS $fieldName => $column) {
foreach ($diff->addedColumns AS $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
Expand Down
7 changes: 1 addition & 6 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Expand Up @@ -354,7 +354,7 @@ protected function _getCreateTableSQL($table, array $columns, array $options = a
}

if (isset($indexes) && ! empty($indexes)) {
foreach ($indexes as $indexName => $index) {
foreach ($indexes AS $index) {
$sql[] = $this->getCreateIndexSQL($index, $table);
}
}
Expand Down Expand Up @@ -408,11 +408,6 @@ public function getCreateAutoincrementSql($name, $table, $start = 1)
$sql = array();

$indexName = $table . '_AI_PK';
$definition = array(
'primary' => true,
'columns' => array($name => true),
);

$idx = new \Doctrine\DBAL\Schema\Index($indexName, array($name), true, true);

$sql[] = 'DECLARE
Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/DBAL/SQLParserUtils.php
Expand Up @@ -141,7 +141,6 @@ static public function expandListParameters($query, $params, $types)
$paramsOrd = array();
foreach ($paramPos as $needle => $needlePos) {
$paramLen = strlen($needle);
$token = substr($needle,0,1);
$needle = substr($needle,1);
$value = $params[$needle];

Expand Down
18 changes: 9 additions & 9 deletions lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Expand Up @@ -551,7 +551,7 @@ public function renameTable($name, $newName)
protected function _getPortableDatabasesList($databases)
{
$list = array();
foreach ($databases as $key => $value) {
foreach ($databases as $value) {
if ($value = $this->_getPortableDatabaseDefinition($value)) {
$list[] = $value;
}
Expand All @@ -567,7 +567,7 @@ protected function _getPortableDatabaseDefinition($database)
protected function _getPortableFunctionsList($functions)
{
$list = array();
foreach ($functions as $key => $value) {
foreach ($functions as $value) {
if ($value = $this->_getPortableFunctionDefinition($value)) {
$list[] = $value;
}
Expand All @@ -583,7 +583,7 @@ protected function _getPortableFunctionDefinition($function)
protected function _getPortableTriggersList($triggers)
{
$list = array();
foreach ($triggers as $key => $value) {
foreach ($triggers as $value) {
if ($value = $this->_getPortableTriggerDefinition($value)) {
$list[] = $value;
}
Expand All @@ -599,7 +599,7 @@ protected function _getPortableTriggerDefinition($trigger)
protected function _getPortableSequencesList($sequences)
{
$list = array();
foreach ($sequences as $key => $value) {
foreach ($sequences as $value) {
if ($value = $this->_getPortableSequenceDefinition($value)) {
$list[] = $value;
}
Expand Down Expand Up @@ -631,7 +631,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns)
$eventManager = $this->_platform->getEventManager();

$list = array();
foreach ($tableColumns as $key => $tableColumn) {
foreach ($tableColumns as $tableColumn) {
$column = null;
$defaultPrevented = false;

Expand Down Expand Up @@ -722,7 +722,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null
protected function _getPortableTablesList($tables)
{
$list = array();
foreach ($tables as $key => $value) {
foreach ($tables as $value) {
if ($value = $this->_getPortableTableDefinition($value)) {
$list[] = $value;
}
Expand All @@ -738,7 +738,7 @@ protected function _getPortableTableDefinition($table)
protected function _getPortableUsersList($users)
{
$list = array();
foreach ($users as $key => $value) {
foreach ($users as $value) {
if ($value = $this->_getPortableUserDefinition($value)) {
$list[] = $value;
}
Expand All @@ -754,7 +754,7 @@ protected function _getPortableUserDefinition($user)
protected function _getPortableViewsList($views)
{
$list = array();
foreach ($views as $key => $value) {
foreach ($views as $value) {
if ($view = $this->_getPortableViewDefinition($value)) {
$viewName = strtolower($view->getQuotedName($this->_platform));
$list[$viewName] = $view;
Expand All @@ -771,7 +771,7 @@ protected function _getPortableViewDefinition($view)
protected function _getPortableTableForeignKeysList($tableForeignKeys)
{
$list = array();
foreach ($tableForeignKeys as $key => $value) {
foreach ($tableForeignKeys as $value) {
if ($value = $this->_getPortableTableForeignKeyDefinition($value)) {
$list[] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/Comparator.php
Expand Up @@ -255,7 +255,7 @@ private function detectColumnRenamings(TableDiff $tableDifferences)
}
}

foreach ($renameCandidates AS $candidate => $candidateColumns) {
foreach ($renameCandidates AS $candidateColumns) {
if (count($candidateColumns) == 1) {
list($removedColumn, $addedColumn) = $candidateColumns[0];
$removedColumnName = strtolower($removedColumn->getName());
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
Expand Up @@ -124,12 +124,11 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
{
$eventManager = $this->_platform->getEventManager();

$tableIndexRows = array();
$indexes = array();
foreach($tableIndexes AS $indexKey => $data) {
$data = array_change_key_case($data, \CASE_LOWER);
$unique = ($data['uniquerule'] == "D") ? false : true;
$primary = ($data['uniquerule'] == "P");
$unique = ($data['uniquerule'] == 'D') ? false : true;
$primary = ($data['uniquerule'] == 'P');

$indexName = strtolower($data['name']);
if ($primary) {
Expand All @@ -140,7 +139,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)

$data = array(
'name' => $indexName,
'columns' => explode("+", ltrim($data['colnames'], '+')),
'columns' => explode('+', ltrim($data['colnames'], '+')),
'unique' => $unique,
'primary' => $primary
);
Expand Down
10 changes: 2 additions & 8 deletions lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
Expand Up @@ -143,17 +143,11 @@ protected function _getPortableTableColumnDefinition($tableColumn)
}

$length = ((int) $length == 0) ? null : (int) $length;
$def = array(
'type' => $type,
'length' => $length,
'unsigned' => (bool) $unsigned,
'fixed' => (bool) $fixed
);

$options = array(
'length' => $length,
'unsigned' => (bool)$unsigned,
'fixed' => (bool)$fixed,
'unsigned' => (bool) $unsigned,
'fixed' => (bool) $fixed,
'default' => isset($tableColumn['default']) ? $tableColumn['default'] : null,
'notnull' => (bool) ($tableColumn['null'] != 'YES'),
'scale' => null,
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
Expand Up @@ -199,7 +199,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableForeignKeysList($tableForeignKeys)
{
$list = array();
foreach ($tableForeignKeys as $key => $value) {
foreach ($tableForeignKeys as $value) {
$value = \array_change_key_case($value, CASE_LOWER);
if (!isset($list[$value['constraint_name']])) {
if ($value['delete_rule'] == "NO ACTION") {
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Schema/Schema.php
Expand Up @@ -123,8 +123,7 @@ public function getTables()
*/
public function getTable($tableName)
{
$tableName = strtolower($tableName);
if (!isset($this->_tables[$tableName])) {
if (false === $this->hasTable($tableName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

throw SchemaException::tableDoesNotExist($tableName);
}

Expand Down Expand Up @@ -214,7 +213,10 @@ public function renameTable($oldTableName, $newTableName)
public function dropTable($tableName)
{
$tableName = strtolower($tableName);
$table = $this->getTable($tableName);
if (false === $this->hasTable($tableName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!$this->hasTable()) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm for this syntax but I don't know the CS for Doctrine. Do they use ! or false === ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they use !, at least in most places (with spaces around it, contrary to Symfony)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum ok good to know :)

throw SchemaException::tableDoesNotExist($tableName);
}

unset($this->_tables[$tableName]);
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SchemaException.php
Expand Up @@ -21,7 +21,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException
*/
static public function tableDoesNotExist($tableName)
{
return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
return new self("There is no table with name '$tableName' in the schema.", self::TABLE_DOESNT_EXIST);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/DBAL/Schema/Table.php
Expand Up @@ -273,7 +273,10 @@ public function changeColumn($columnName, array $options)
public function dropColumn($columnName)
{
$columnName = strtolower($columnName);
$column = $this->getColumn($columnName);
if (false === $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}

unset($this->_columns[$columnName]);
return $this;
}
Expand Down
14 changes: 11 additions & 3 deletions tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php
Expand Up @@ -77,11 +77,19 @@ public function testDropTable()
$table = new Table($tableName);
$schema = new Schema(array($table));

$this->assertTrue($schema->hasTable("foo"));
$this->assertTrue($schema->hasTable($tableName));

$schema->dropTable("foo");
$schema->dropTable($tableName);

$this->assertFalse($schema->hasTable("foo"));
$this->assertFalse($schema->hasTable($tableName));
}

public function testDropInvalidTable()
{
$this->setExpectedException('Doctrine\DBAL\Schema\SchemaException');

$schema = new Schema();
$schema->dropTable('foo');
}

public function testCreateTable()
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/TableTest.php
Expand Up @@ -87,6 +87,14 @@ public function testDropColumn()
$this->assertFalse($table->hasColumn("bar"));
}

public function testDropInvalidColumn()
{
$this->setExpectedException('Doctrine\DBAL\Schema\SchemaException');

$table = new Table('foo');
$table->dropColumn('bar');
}

public function testGetUnknownColumnThrowsException()
{
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
Expand Down