diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index e53f8292996..781462c3b05 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -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]; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 4164d70faff..3fed0d4dfc6 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -59,7 +59,7 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions ); - foreach ($this->_userDefinedFunctions AS $fn => $data) { + foreach ($this->_userDefinedFunctions as $fn => $data) { $pdo->sqliteCreateFunction($fn, $data['callback'], $data['numArgs']); } diff --git a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php index 7f5caa3b91e..deb66b34926 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php @@ -64,7 +64,7 @@ public function postConnect(ConnectionEventArgs $args) if (count($this->_defaultSessionVars)) { array_change_key_case($this->_defaultSessionVars, \CASE_UPPER); $vars = array(); - foreach ($this->_defaultSessionVars AS $option => $value) { + foreach ($this->_defaultSessionVars as $option => $value) { $vars[] = $option." = '".$value."'"; } $sql = "ALTER SESSION SET ".implode(" ", $vars); diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 79fa95c202c..05285a7f4aa 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1024,7 +1024,7 @@ public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXE $options['primary'] = array(); if (($createFlags&self::CREATE_INDEXES) > 0) { - foreach ($table->getIndexes() AS $index) { + foreach ($table->getIndexes() as $index) { /* @var $index Index */ if ($index->isPrimary()) { $options['primary'] = $index->getColumns(); @@ -1036,7 +1036,7 @@ public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXE $columnSql = array(); $columns = array(); - foreach ($table->getColumns() AS $column) { + foreach ($table->getColumns() as $column) { /* @var \Doctrine\DBAL\Schema\Column $column */ if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) { @@ -1078,7 +1078,7 @@ public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXE if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) { $options['foreignKeys'] = array(); - foreach ($table->getForeignKeys() AS $fkConstraint) { + foreach ($table->getForeignKeys() as $fkConstraint) { $options['foreignKeys'][] = $fkConstraint; } } @@ -1094,7 +1094,7 @@ public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXE $sql = $this->_getCreateTableSQL($tableName, $columns, $options); if ($this->supportsCommentOnStatement()) { - foreach ($table->getColumns() AS $column) { + foreach ($table->getColumns() as $column) { if ($this->getColumnComment($column)) { $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column)); } @@ -1146,7 +1146,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $sql[] = $query; if (isset($options['foreignKeys'])) { - foreach ((array) $options['foreignKeys'] AS $definition) { + foreach ((array) $options['foreignKeys'] as $definition) { $sql[] = $this->getCreateForeignKeySQL($definition, $tableName); } } @@ -1217,7 +1217,7 @@ public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constra $query .= ' FOREIGN KEY'; $foreignColumns = array(); - foreach ($constraint->getForeignColumns() AS $column) { + foreach ($constraint->getForeignColumns() as $column) { $foreignColumns[] = $column; } @@ -1460,18 +1460,18 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) $sql = array(); if ($this->supportsForeignKeyConstraints()) { - foreach ($diff->removedForeignKeys AS $foreignKey) { + foreach ($diff->removedForeignKeys as $foreignKey) { $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); } - foreach ($diff->changedForeignKeys AS $foreignKey) { + foreach ($diff->changedForeignKeys as $foreignKey) { $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); } } - foreach ($diff->removedIndexes AS $index) { + foreach ($diff->removedIndexes as $index) { $sql[] = $this->getDropIndexSQL($index, $tableName); } - foreach ($diff->changedIndexes AS $index) { + foreach ($diff->changedIndexes as $index) { $sql[] = $this->getDropIndexSQL($index, $tableName); } @@ -1488,18 +1488,18 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) $sql = array(); if ($this->supportsForeignKeyConstraints()) { - foreach ($diff->addedForeignKeys AS $foreignKey) { + foreach ($diff->addedForeignKeys as $foreignKey) { $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); } - foreach ($diff->changedForeignKeys AS $foreignKey) { + foreach ($diff->changedForeignKeys as $foreignKey) { $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); } } - foreach ($diff->addedIndexes AS $index) { + foreach ($diff->addedIndexes as $index) { $sql[] = $this->getCreateIndexSQL($index, $tableName); } - foreach ($diff->changedIndexes AS $index) { + foreach ($diff->changedIndexes as $index) { $sql[] = $this->getCreateIndexSQL($index, $tableName); } diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 198be839299..1b1ccc39a0a 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -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; @@ -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; } @@ -384,7 +384,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'ADD COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); } - foreach ($diff->removedColumns AS $column) { + foreach ($diff->removedColumns as $column) { if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { continue; } @@ -392,7 +392,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this); } - foreach ($diff->changedColumns AS $columnDiff) { + foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; } @@ -403,7 +403,7 @@ public function getAlterTableSQL(TableDiff $diff) . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); } - foreach ($diff->renamedColumns AS $oldColumnName => $column) { + foreach ($diff->renamedColumns as $oldColumnName => $column) { if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php index 5c99ba3b4e9..83349eee4c5 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php @@ -61,7 +61,7 @@ private function isReservedWord($word) } $keywordLists = array(); - foreach ($this->keywordLists AS $keywordList) { + foreach ($this->keywordLists as $keywordList) { if ($keywordList->isKeyword($word)) { $keywordLists[] = $keywordList->getName(); } diff --git a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php index a05302e4c98..32c7a833337 100644 --- a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php @@ -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.'); @@ -210,13 +209,13 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $sql[] = $query; if (isset($options['indexes']) && !empty($options['indexes'])) { - foreach ($options['indexes'] AS $index) { + foreach ($options['indexes'] as $index) { $sql[] = $this->getCreateIndexSQL($index, $tableName); } } if (isset($options['foreignKeys'])) { - foreach ((array) $options['foreignKeys'] AS $definition) { + foreach ((array) $options['foreignKeys'] as $definition) { $sql[] = $this->getCreateForeignKeySQL($definition, $tableName); } } @@ -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; } @@ -292,7 +291,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); } - foreach ($diff->removedColumns AS $column) { + foreach ($diff->removedColumns as $column) { if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { continue; } @@ -300,7 +299,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this); } - foreach ($diff->changedColumns AS $columnDiff) { + foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; } @@ -311,7 +310,7 @@ public function getAlterTableSQL(TableDiff $diff) $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); } - foreach ($diff->renamedColumns AS $oldColumnName => $column) { + foreach ($diff->renamedColumns as $oldColumnName => $column) { if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index c4e685dba9b..26699472d74 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -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; } @@ -470,7 +470,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } - foreach ($diff->removedColumns AS $column) { + foreach ($diff->removedColumns as $column) { if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { continue; } @@ -478,7 +478,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'DROP ' . $column->getQuotedName($this); } - foreach ($diff->changedColumns AS $columnDiff) { + foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; } @@ -491,7 +491,7 @@ public function getAlterTableSQL(TableDiff $diff) . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } - foreach ($diff->renamedColumns AS $oldColumnName => $column) { + foreach ($diff->renamedColumns as $oldColumnName => $column) { if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 0c290a5bfaa..264e75bed36 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -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); } } @@ -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 @@ -573,7 +568,7 @@ public function getAlterTableSQL(TableDiff $diff) $columnSql = array(); $fields = array(); - foreach ($diff->addedColumns AS $column) { + foreach ($diff->addedColumns as $column) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { continue; } @@ -588,7 +583,7 @@ public function getAlterTableSQL(TableDiff $diff) } $fields = array(); - foreach ($diff->changedColumns AS $columnDiff) { + foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; } @@ -603,7 +598,7 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')'; } - foreach ($diff->renamedColumns AS $oldColumnName => $column) { + foreach ($diff->renamedColumns as $oldColumnName => $column) { if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) { continue; } @@ -612,7 +607,7 @@ public function getAlterTableSQL(TableDiff $diff) } $fields = array(); - foreach ($diff->removedColumns AS $column) { + foreach ($diff->removedColumns as $column) { if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 1512236996f..4f0a7b3cf20 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -403,7 +403,7 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; } - foreach ($diff->changedColumns AS $columnDiff) { + foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; } @@ -532,7 +532,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $sql[] = $query; if (isset($options['indexes']) && ! empty($options['indexes'])) { - foreach ($options['indexes'] AS $index) { + foreach ($options['indexes'] as $index) { $sql[] = $this->getCreateIndexSQL($index, $tableName); } } diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 35a4a40243c..cca40ae6de9 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -138,7 +138,7 @@ public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0) return $rows; } - foreach ($rows AS $num => $row) { + foreach ($rows as $num => $row) { $rows[$num] = $this->fixRow($row, $iterateRow, $fixCase); } @@ -156,7 +156,7 @@ protected function fixRow($row, $iterateRow, $fixCase) } if ($iterateRow) { - foreach ($row AS $k => $v) { + foreach ($row as $k => $v) { if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) && $v === '') { $row[$k] = null; } else if (($this->portability & Connection::PORTABILITY_RTRIM) && is_string($v)) { diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 04cb03fb9af..b6c31c75f7c 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -374,7 +374,7 @@ public function add($sqlPartName, $sqlPart, $append = false) if ($append) { if ($sqlPartName == "orderBy" || $sqlPartName == "groupBy" || $sqlPartName == "select" || $sqlPartName == "set") { - foreach ($sqlPart AS $part) { + foreach ($sqlPart as $part) { $this->sqlParts[$sqlPartName][] = $part; } } else if ($isArray && is_array($sqlPart[key($sqlPart)])) { diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index cc980ea3fdf..371f7efbcf1 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -88,7 +88,7 @@ static public function expandListParameters($query, $params, $types) $isPositional = is_int(key($params)); $arrayPositions = array(); $bindIndex = -1; - foreach ($types AS $name => $type) { + foreach ($types as $name => $type) { ++$bindIndex; if ($type === Connection::PARAM_INT_ARRAY || $type == Connection::PARAM_STR_ARRAY) { if ($isPositional) { @@ -107,7 +107,7 @@ static public function expandListParameters($query, $params, $types) if ($isPositional) { $paramOffset = 0; $queryOffset = 0; - foreach ($paramPos AS $needle => $needlePos) { + foreach ($paramPos as $needle => $needlePos) { if (!isset($arrayPositions[$needle])) { continue; } @@ -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]; diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index c4113cbd231..a67ac18dbf0 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -98,7 +98,7 @@ public function getQuotedName(AbstractPlatform $platform) { $keywords = $platform->getReservedKeywordsList(); $parts = explode(".", $this->_name); - foreach ($parts AS $k => $v) { + foreach ($parts as $k => $v) { $parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v; } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 4c598ad5c51..68a4ce1c502 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -213,7 +213,7 @@ public function listTables() $tableNames = $this->listTableNames(); $tables = array(); - foreach ($tableNames AS $tableName) { + foreach ($tableNames as $tableName) { $tables[] = $this->listTableDetails($tableName); } @@ -299,7 +299,7 @@ public function dropTable($table) */ public function dropIndex($index, $table) { - if($index instanceof Index) { + if ($index instanceof Index) { $index = $index->getQuotedName($this->_platform); } @@ -524,7 +524,7 @@ public function alterTable(TableDiff $tableDiff) { $queries = $this->_platform->getAlterTableSQL($tableDiff); if (is_array($queries) && count($queries)) { - foreach ($queries AS $ddlQuery) { + foreach ($queries as $ddlQuery) { $this->_execSql($ddlQuery); } } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; @@ -673,14 +673,14 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn); protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null) { $result = array(); - foreach($tableIndexRows AS $tableIndex) { + foreach ($tableIndexRows as $tableIndex) { $indexName = $keyName = $tableIndex['key_name']; - if($tableIndex['primary']) { + if ($tableIndex['primary']) { $keyName = 'primary'; } $keyName = strtolower($keyName); - if(!isset($result[$keyName])) { + if ( ! isset($result[$keyName])) { $result[$keyName] = array( 'name' => $indexName, 'columns' => array($tableIndex['column_name']), @@ -695,7 +695,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null $eventManager = $this->_platform->getEventManager(); $indexes = array(); - foreach($result AS $indexKey => $data) { + foreach ($result as $indexKey => $data) { $index = null; $defaultPrevented = false; @@ -707,7 +707,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null $index = $eventArgs->getIndex(); } - if (!$defaultPrevented) { + if ( ! $defaultPrevented) { $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']); } @@ -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; } @@ -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; } @@ -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; @@ -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; } @@ -799,7 +799,7 @@ protected function _execSql($sql) public function createSchema() { $sequences = array(); - if($this->_platform->supportsSequences()) { + if ($this->_platform->supportsSequences()) { $sequences = $this->listSequences(); } $tables = $this->listTables(); diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index b4cd0184ece..5c030fb11d3 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -61,7 +61,7 @@ public function compare(Schema $fromSchema, Schema $toSchema) $foreignKeysToTable = array(); - foreach ( $toSchema->getTables() AS $tableName => $table ) { + foreach ( $toSchema->getTables() as $tableName => $table ) { if ( !$fromSchema->hasTable($tableName) ) { $diff->newTables[$tableName] = $table; } else { @@ -73,13 +73,13 @@ public function compare(Schema $fromSchema, Schema $toSchema) } /* Check if there are tables removed */ - foreach ( $fromSchema->getTables() AS $tableName => $table ) { + foreach ( $fromSchema->getTables() as $tableName => $table ) { if ( !$toSchema->hasTable($tableName) ) { $diff->removedTables[$tableName] = $table; } // also remember all foreign keys that point to a specific table - foreach ($table->getForeignKeys() AS $foreignKey) { + foreach ($table->getForeignKeys() as $foreignKey) { $foreignTable = strtolower($foreignKey->getForeignTableName()); if (!isset($foreignKeysToTable[$foreignTable])) { $foreignKeysToTable[$foreignTable] = array(); @@ -88,13 +88,13 @@ public function compare(Schema $fromSchema, Schema $toSchema) } } - foreach ($diff->removedTables AS $tableName => $table) { + foreach ($diff->removedTables as $tableName => $table) { if (isset($foreignKeysToTable[$tableName])) { $diff->orphanedForeignKeys = array_merge($diff->orphanedForeignKeys, $foreignKeysToTable[$tableName]); } } - foreach ( $toSchema->getSequences() AS $sequenceName => $sequence) { + foreach ( $toSchema->getSequences() as $sequenceName => $sequence) { if (!$fromSchema->hasSequence($sequenceName)) { $diff->newSequences[] = $sequence; } else { @@ -104,7 +104,7 @@ public function compare(Schema $fromSchema, Schema $toSchema) } } - foreach ($fromSchema->getSequences() AS $sequenceName => $sequence) { + foreach ($fromSchema->getSequences() as $sequenceName => $sequence) { if (!$toSchema->hasSequence($sequenceName)) { $diff->removedSequences[] = $sequence; } @@ -180,8 +180,8 @@ public function diffTable(Table $table1, Table $table2) $table1Indexes = $table1->getIndexes(); $table2Indexes = $table2->getIndexes(); - foreach ($table2Indexes AS $index2Name => $index2Definition) { - foreach ($table1Indexes AS $index1Name => $index1Definition) { + foreach ($table2Indexes as $index2Name => $index2Definition) { + foreach ($table1Indexes as $index1Name => $index1Definition) { if ($this->diffIndex($index1Definition, $index2Definition) === false) { unset($table1Indexes[$index1Name]); unset($table2Indexes[$index2Name]); @@ -196,12 +196,12 @@ public function diffTable(Table $table1, Table $table2) } } - foreach ($table1Indexes AS $index1Name => $index1Definition) { + foreach ($table1Indexes as $index1Name => $index1Definition) { $tableDifferences->removedIndexes[$index1Name] = $index1Definition; $changes++; } - foreach ($table2Indexes AS $index2Name => $index2Definition) { + foreach ($table2Indexes as $index2Name => $index2Definition) { $tableDifferences->addedIndexes[$index2Name] = $index2Definition; $changes++; } @@ -209,8 +209,8 @@ public function diffTable(Table $table1, Table $table2) $fromFkeys = $table1->getForeignKeys(); $toFkeys = $table2->getForeignKeys(); - foreach ($fromFkeys AS $key1 => $constraint1) { - foreach ($toFkeys AS $key2 => $constraint2) { + foreach ($fromFkeys as $key1 => $constraint1) { + foreach ($toFkeys as $key2 => $constraint2) { if($this->diffForeignKey($constraint1, $constraint2) === false) { unset($fromFkeys[$key1]); unset($toFkeys[$key2]); @@ -225,12 +225,12 @@ public function diffTable(Table $table1, Table $table2) } } - foreach ($fromFkeys AS $key1 => $constraint1) { + foreach ($fromFkeys as $key1 => $constraint1) { $tableDifferences->removedForeignKeys[] = $constraint1; $changes++; } - foreach ($toFkeys AS $key2 => $constraint2) { + foreach ($toFkeys as $key2 => $constraint2) { $tableDifferences->addedForeignKeys[] = $constraint2; $changes++; } @@ -247,15 +247,15 @@ public function diffTable(Table $table1, Table $table2) private function detectColumnRenamings(TableDiff $tableDifferences) { $renameCandidates = array(); - foreach ($tableDifferences->addedColumns AS $addedColumnName => $addedColumn) { - foreach ($tableDifferences->removedColumns AS $removedColumnName => $removedColumn) { + foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) { + foreach ($tableDifferences->removedColumns as $removedColumnName => $removedColumn) { if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) { $renameCandidates[$addedColumn->getName()][] = array($removedColumn, $addedColumn, $addedColumnName); } } } - foreach ($renameCandidates AS $candidate => $candidateColumns) { + foreach ($renameCandidates as $candidateColumns) { if (count($candidateColumns) == 1) { list($removedColumn, $addedColumn) = $candidateColumns[0]; $removedColumnName = strtolower($removedColumn->getName()); diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 4e41effa53f..c694979c58a 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -113,7 +113,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTablesList($tables) { $tableNames = array(); - foreach ($tables AS $tableRow) { + foreach ($tables as $tableRow) { $tableRow = array_change_key_case($tableRow, \CASE_LOWER); $tableNames[] = $tableRow['name']; } @@ -124,12 +124,11 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) { $eventManager = $this->_platform->getEventManager(); - $tableIndexRows = array(); $indexes = array(); - foreach($tableIndexes AS $indexKey => $data) { + 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) { @@ -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 ); diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 5a8e6c37199..9fea46e375d 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -52,7 +52,7 @@ public function __construct($indexName, array $columns, $isUnique=false, $isPrim $this->_isUnique = $isUnique; $this->_isPrimary = $isPrimary; - foreach($columns AS $column) { + foreach ($columns as $column) { $this->_addColumn($column); } } diff --git a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php index 27d2053f11c..ec03c4295a0 100644 --- a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php @@ -107,7 +107,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null) { $result = array(); - foreach ($tableIndexRows AS $tableIndex) { + foreach ($tableIndexRows as $tableIndex) { $indexName = $keyName = $tableIndex['index_name']; if (strpos($tableIndex['index_description'], 'primary key') !== false) { $keyName = 'primary'; @@ -125,7 +125,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null $eventManager = $this->_platform->getEventManager(); $indexes = array(); - foreach ($result AS $indexKey => $data) { + foreach ($result as $indexKey => $data) { $index = null; $defaultPrevented = false; diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 1d478aaccc4..94eb772a832 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -52,7 +52,7 @@ protected function _getPortableUserDefinition($user) protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) { - foreach($tableIndexes AS $k => $v) { + foreach($tableIndexes as $k => $v) { $v = array_change_key_case($v, CASE_LOWER); if($v['key_name'] == 'PRIMARY') { $v['primary'] = true; @@ -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, diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 3bbefb6b8ae..e0036dee78d 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -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") { @@ -219,7 +219,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) } $result = array(); - foreach($list AS $constraint) { + foreach($list as $constraint) { $result[] = new ForeignKeyConstraint( array_values($constraint['local']), $constraint['foreignTable'], array_values($constraint['foreign']), $constraint['name'], diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 80ac9a7f03e..f144efdbabe 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -194,7 +194,7 @@ protected function _getPortableTableDefinition($table) protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) { $buffer = array(); - foreach ($tableIndexes AS $row) { + foreach ($tableIndexes as $row) { $colNumbers = explode(' ', $row['indkey']); $colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )'; $columnNameSql = "SELECT attnum, attname FROM pg_attribute @@ -204,7 +204,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) $indexColumns = $stmt->fetchAll(); // required for getting the order of the columns right. - foreach ($colNumbers AS $colNum) { + foreach ($colNumbers as $colNum) { foreach ($indexColumns as $colRow) { if ($colNum == $colRow['attnum']) { $buffer[] = array( diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 373134def91..14761c26d1f 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -65,10 +65,10 @@ public function __construct(array $tables=array(), array $sequences=array(), Sch } $this->_schemaConfig = $schemaConfig; - foreach ($tables AS $table) { + foreach ($tables as $table) { $this->_addTable($table); } - foreach ($sequences AS $sequence) { + foreach ($sequences as $sequence) { $this->_addSequence($sequence); } } @@ -123,8 +123,7 @@ public function getTables() */ public function getTable($tableName) { - $tableName = strtolower($tableName); - if (!isset($this->_tables[$tableName])) { + if ( ! $this->hasTable($tableName)) { throw SchemaException::tableDoesNotExist($tableName); } @@ -161,7 +160,7 @@ public function hasSequence($sequenceName) public function getSequence($sequenceName) { $sequenceName = strtolower($sequenceName); - if(!$this->hasSequence($sequenceName)) { + if ( ! $this->hasSequence($sequenceName)) { throw SchemaException::sequenceDoesNotExist($sequenceName); } return $this->_sequences[$sequenceName]; @@ -214,7 +213,9 @@ public function renameTable($oldTableName, $newTableName) public function dropTable($tableName) { $tableName = strtolower($tableName); - $table = $this->getTable($tableName); + if ( ! $this->hasTable($tableName)) { + throw SchemaException::tableDoesNotExist($tableName); + } unset($this->_tables[$tableName]); return $this; } @@ -302,10 +303,10 @@ public function visit(Visitor $visitor) { $visitor->acceptSchema($this); - foreach ($this->_tables AS $table) { + foreach ($this->_tables as $table) { $table->visit($visitor); } - foreach ($this->_sequences AS $sequence) { + foreach ($this->_sequences as $sequence) { $sequence->visit($visitor); } } @@ -317,10 +318,10 @@ public function visit(Visitor $visitor) */ public function __clone() { - foreach ($this->_tables AS $k => $table) { + foreach ($this->_tables as $k => $table) { $this->_tables[$k] = clone $table; } - foreach ($this->_sequences AS $k => $sequence) { + foreach ($this->_sequences as $k => $sequence) { $this->_sequences[$k] = clone $sequence; } } diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index 64033c1e8d3..5b963fb8d4e 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -125,36 +125,36 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) $sql = array(); if ($platform->supportsForeignKeyConstraints() && $saveMode == false) { - foreach ($this->orphanedForeignKeys AS $orphanedForeignKey) { + foreach ($this->orphanedForeignKeys as $orphanedForeignKey) { $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName()); } } if ($platform->supportsSequences() == true) { - foreach ($this->changedSequences AS $sequence) { + foreach ($this->changedSequences as $sequence) { $sql[] = $platform->getAlterSequenceSQL($sequence); } if ($saveMode === false) { - foreach ($this->removedSequences AS $sequence) { + foreach ($this->removedSequences as $sequence) { $sql[] = $platform->getDropSequenceSQL($sequence); } } - foreach ($this->newSequences AS $sequence) { + foreach ($this->newSequences as $sequence) { $sql[] = $platform->getCreateSequenceSQL($sequence); } } $foreignKeySql = array(); - foreach ($this->newTables AS $table) { + foreach ($this->newTables as $table) { $sql = array_merge( $sql, $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES) ); if ($platform->supportsForeignKeyConstraints()) { - foreach ($table->getForeignKeys() AS $foreignKey) { + foreach ($table->getForeignKeys() as $foreignKey) { $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table); } } @@ -162,12 +162,12 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) $sql = array_merge($sql, $foreignKeySql); if ($saveMode === false) { - foreach ($this->removedTables AS $table) { + foreach ($this->removedTables as $table) { $sql[] = $platform->getDropTableSQL($table); } } - foreach ($this->changedTables AS $tableDiff) { + foreach ($this->changedTables as $tableDiff) { $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff)); } diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index a8cb93d735e..85d410aa11d 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -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); } /** diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 9e912991de1..f2fada0adc2 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -80,7 +80,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) // fetch primary $stmt = $this->_conn->executeQuery( "PRAGMA TABLE_INFO ('$tableName')" ); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); - foreach($indexArray AS $indexColumnRow) { + foreach($indexArray as $indexColumnRow) { if($indexColumnRow['pk'] == "1") { $indexBuffer[] = array( 'key_name' => 'primary', @@ -92,7 +92,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) } // fetch regular indexes - foreach($tableIndexes AS $tableIndex) { + foreach($tableIndexes as $tableIndex) { // Ignore indexes with reserved names, e.g. autoindexes if (strpos($tableIndex['name'], 'sqlite_') !== 0) { $keyName = $tableIndex['name']; diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 59274f50ac8..66efe12c5dd 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -89,15 +89,15 @@ public function __construct($tableName, array $columns=array(), array $indexes=a $this->_setName($tableName); $this->_idGeneratorType = $idGeneratorType; - foreach ($columns AS $column) { + foreach ($columns as $column) { $this->_addColumn($column); } - foreach ($indexes AS $idx) { + foreach ($indexes as $idx) { $this->_addIndex($idx); } - foreach ($fkConstraints AS $constraint) { + foreach ($fkConstraints as $constraint) { $this->_addForeignKeyConstraint($constraint); } @@ -135,7 +135,7 @@ public function setPrimaryKey(array $columns, $indexName = false) { $primaryKey = $this->_createIndex($columns, $indexName ?: "primary", true, true); - foreach ($columns AS $columnName) { + foreach ($columns as $columnName) { $column = $this->getColumn($columnName); $column->setNotnull(true); } @@ -184,7 +184,7 @@ public function addUniqueIndex(array $columnNames, $indexName = null) */ public function columnsAreIndexed(array $columnsNames) { - foreach ($this->getIndexes() AS $index) { + foreach ($this->getIndexes() as $index) { /* @var $index Index */ if ($index->spansColumns($columnsNames)) { return true; @@ -207,7 +207,7 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim throw SchemaException::indexNameInvalid($indexName); } - foreach ($columnNames AS $columnName => $indexColOptions) { + foreach ($columnNames as $columnName => $indexColOptions) { if (is_numeric($columnName) && is_string($indexColOptions)) { $columnName = $indexColOptions; } @@ -273,7 +273,9 @@ public function changeColumn($columnName, array $options) public function dropColumn($columnName) { $columnName = strtolower($columnName); - $column = $this->getColumn($columnName); + if ( ! $this->hasColumn($columnName)) { + throw SchemaException::columnDoesNotExist($columnName, $this->_name); + } unset($this->_columns[$columnName]); return $this; } @@ -330,7 +332,7 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC if ($foreignTable instanceof Table) { $foreignTableName = $foreignTable->getName(); - foreach ($foreignColumnNames AS $columnName) { + foreach ($foreignColumnNames as $columnName) { if ( ! $foreignTable->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName()); } @@ -339,7 +341,7 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC $foreignTableName = $foreignTable; } - foreach ($localColumnNames AS $columnName) { + foreach ($localColumnNames as $columnName) { if ( ! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } @@ -388,7 +390,7 @@ protected function _addColumn(Column $column) protected function _addIndex(Index $indexCandidate) { // check for duplicates - foreach ($this->_indexes AS $existingIndex) { + foreach ($this->_indexes as $existingIndex) { if ($indexCandidate->isFullfilledBy($existingIndex)) { return $this; } @@ -402,7 +404,7 @@ protected function _addIndex(Index $indexCandidate) } // remove overruled indexes - foreach ($this->_indexes AS $idxKey => $existingIndex) { + foreach ($this->_indexes as $idxKey => $existingIndex) { if ($indexCandidate->overrules($existingIndex)) { unset($this->_indexes[$idxKey]); } @@ -458,7 +460,7 @@ public function hasForeignKey($constraintName) public function getForeignKey($constraintName) { $constraintName = strtolower($constraintName); - if(!$this->hasForeignKey($constraintName)) { + if ( ! $this->hasForeignKey($constraintName)) { throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name); } @@ -478,7 +480,7 @@ public function getColumns() if ($this->hasPrimaryKey()) { $pkCols = $this->getPrimaryKey()->getColumns(); } - foreach ($this->getForeignKeys() AS $fk) { + foreach ($this->getForeignKeys() as $fk) { /* @var $fk ForeignKeyConstraint */ $fkCols = array_merge($fkCols, $fk->getColumns()); } @@ -512,7 +514,7 @@ public function hasColumn($columnName) public function getColumn($columnName) { $columnName = strtolower($this->trimQuotes($columnName)); - if (!$this->hasColumn($columnName)) { + if ( ! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } @@ -524,7 +526,7 @@ public function getColumn($columnName) */ public function getPrimaryKey() { - if (!$this->hasPrimaryKey()) { + if ( ! $this->hasPrimaryKey()) { return null; } return $this->getIndex($this->_primaryKeyName); @@ -557,7 +559,7 @@ public function hasIndex($indexName) public function getIndex($indexName) { $indexName = strtolower($indexName); - if (!$this->hasIndex($indexName)) { + if ( ! $this->hasIndex($indexName)) { throw SchemaException::indexDoesNotExist($indexName, $this->_name); } return $this->_indexes[$indexName]; @@ -603,15 +605,15 @@ public function visit(Visitor $visitor) { $visitor->acceptTable($this); - foreach ($this->getColumns() AS $column) { + foreach ($this->getColumns() as $column) { $visitor->acceptColumn($this, $column); } - foreach ($this->getIndexes() AS $index) { + foreach ($this->getIndexes() as $index) { $visitor->acceptIndex($this, $index); } - foreach ($this->getForeignKeys() AS $constraint) { + foreach ($this->getForeignKeys() as $constraint) { $visitor->acceptForeignKey($this, $constraint); } } @@ -621,13 +623,13 @@ public function visit(Visitor $visitor) */ public function __clone() { - foreach ($this->_columns AS $k => $column) { + foreach ($this->_columns as $k => $column) { $this->_columns[$k] = clone $column; } - foreach ($this->_indexes AS $k => $index) { + foreach ($this->_indexes as $k => $index) { $this->_indexes[$k] = clone $index; } - foreach ($this->_fkConstraints AS $k => $fk) { + foreach ($this->_fkConstraints as $k => $fk) { $this->_fkConstraints[$k] = clone $fk; $this->_fkConstraints[$k]->setLocalTable($this); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index f59a7ea5845..c3fb948d754 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -141,16 +141,16 @@ public function clearQueries() public function getQueries() { $sql = array(); - foreach ($this->constraints AS $fkConstraint) { + foreach ($this->constraints as $fkConstraint) { $localTable = $this->constraints[$fkConstraint]; $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); } - foreach ($this->sequences AS $sequence) { + foreach ($this->sequences as $sequence) { $sql[] = $this->platform->getDropSequenceSQL($sequence); } - foreach ($this->tables AS $table) { + foreach ($this->tables as $table) { $sql[] = $this->platform->getDropTableSQL($table); } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 9bf0a27cf73..8a01c4b6127 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -102,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $keywords = array(); - foreach ($keywordLists AS $keywordList) { + foreach ($keywordLists as $keywordList) { if (!isset($this->keywordListClasses[$keywordList])) { throw new \InvalidArgumentException( "There exists no keyword list with name '" . $keywordList . "'. ". @@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->write("No reserved keywords violations have been found!", true); } else { $output->write('There are ' . count($violations) . ' reserved keyword violations in your database schema:', true); - foreach ($violations AS $violation) { + foreach ($violations as $violation) { $output->write(' - ' . $violation, true); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index be9399881a6..a0ea8795988 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -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() diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index c4159d7321d..d2a7cf7136a 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -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");