Skip to content

Commit

Permalink
Fixed some more code style
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 29, 2018
1 parent 0e99c34 commit 4190669
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 152 deletions.
12 changes: 7 additions & 5 deletions lib/Doctrine/DBAL/Id/TableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\LockMode;

/**
* Table ID Generator for those poor languages that are missing sequences.
Expand Down Expand Up @@ -120,12 +121,13 @@ public function nextValue($sequenceName)

try {
$platform = $this->conn->getDatabasePlatform();
$sql = "SELECT sequence_value, sequence_increment_by " .
"FROM " . $platform->appendLockHint($this->generatorTableName, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) . " " .
"WHERE sequence_name = ? " . $platform->getWriteLockSQL();
$stmt = $this->conn->executeQuery($sql, [$sequenceName]);
$sql = 'SELECT sequence_value, sequence_increment_by'
. ' FROM ' . $platform->appendLockHint($this->generatorTableName, LockMode::PESSIMISTIC_WRITE)
. ' WHERE sequence_name = ? ' . $platform->getWriteLockSQL();
$stmt = $this->conn->executeQuery($sql, [$sequenceName]);
$row = $stmt->fetch(FetchMode::ASSOCIATIVE);

if ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) {
if ($row !== false) {
$row = array_change_key_case($row, CASE_LOWER);

$value = $row['sequence_value'];
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Portability/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function connect()
// make use of c-level support for case handling
$this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']);
} else {
$this->case = ($params['fetch_case'] == ColumnCase::LOWER) ? CASE_LOWER : CASE_UPPER;
$this->case = ($params['fetch_case'] === ColumnCase::LOWER) ? CASE_LOWER : CASE_UPPER;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Portability/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
$row = $this->stmt->fetch($fetchMode);

$iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM);
$fixCase = ! is_null($this->case) && ($fetchMode == FetchMode::ASSOCIATIVE || $fetchMode == FetchMode::MIXED)
$fixCase = ! is_null($this->case)
&& ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED)
&& ($this->portability & Connection::PORTABILITY_FIX_CASE);

$row = $this->fixRow($row, $iterateRow, $fixCase);
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ public function getSQL()
* ->setParameter(':user_id', 1);
* </code>
*
* @param string|integer $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|integer|null $type One of the {@link \Doctrine\DBAL\ParameterType} constants.
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|int|null $type One of the {@link \Doctrine\DBAL\ParameterType} constants.
*
* @return $this This QueryBuilder instance.
*/
Expand Down
16 changes: 12 additions & 4 deletions tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ protected function setUp()

public function testInsert()
{
$ret = $this->_conn->insert('blob_table',
array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'),
array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT)
);
$ret = $this->_conn->insert('blob_table', [
'id' => 1,
'clobfield' => 'test',
'blobfield' => 'test',
'binaryfield' => 'test',
], [
ParameterType::INTEGER,
ParameterType::STRING,
ParameterType::LARGE_OBJECT,
ParameterType::LARGE_OBJECT,
]);

self::assertEquals(1, $ret);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public function testTransactionalReturnValue()
public function testQuote()
{
self::assertEquals(
$this->_conn->quote("foo", Type::STRING),
$this->_conn->quote("foo", ParameterType::STRING)
$this->_conn->quote('foo', Type::STRING),
$this->_conn->quote('foo', ParameterType::STRING)
);
}

Expand Down
46 changes: 19 additions & 27 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public function testFetchAllWithTypes()
$datetimeString = '2010-01-01 10:10:10';
$datetime = new \DateTime($datetimeString);

$sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?";
$data = $this->_conn->fetchAll($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME));
$sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?';
$data = $this->_conn->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]);

self::assertCount(1, $data);

Expand Down Expand Up @@ -227,8 +227,8 @@ public function testFetchAllWithMissingTypes()

public function testFetchBoth()
{
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch(FetchMode::MIXED);
$sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?';
$row = $this->_conn->executeQuery($sql, [1, 'foo'])->fetch(FetchMode::MIXED);

self::assertNotFalse($row);

Expand Down Expand Up @@ -265,8 +265,8 @@ public function testFetchAssocWithTypes()
$datetimeString = '2010-01-01 10:10:10';
$datetime = new \DateTime($datetimeString);

$sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?";
$row = $this->_conn->fetchAssoc($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME));
$sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?';
$row = $this->_conn->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]);

self::assertNotFalse($row);

Expand Down Expand Up @@ -306,8 +306,8 @@ public function testFetchArrayWithTypes()
$datetimeString = '2010-01-01 10:10:10';
$datetime = new \DateTime($datetimeString);

$sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?";
$row = $this->_conn->fetchArray($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME));
$sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?';
$row = $this->_conn->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]);

self::assertNotFalse($row);

Expand Down Expand Up @@ -351,13 +351,8 @@ public function testFetchColumnWithTypes()
$datetimeString = '2010-01-01 10:10:10';
$datetime = new \DateTime($datetimeString);

$sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?";
$column = $this->_conn->fetchColumn(
$sql,
array(1, $datetime),
1,
array(ParameterType::STRING, Type::DATETIME)
);
$sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?';
$column = $this->_conn->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]);

self::assertNotFalse($column);

Expand Down Expand Up @@ -402,18 +397,15 @@ public function testExecuteUpdateBindDateTimeType()
$datetime = new \DateTime('2010-02-02 20:20:20');

$sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)';
$affectedRows = $this->_conn->executeUpdate($sql,
array(
1 => 50,
2 => 'foo',
3 => $datetime,
),
array(
1 => ParameterType::INTEGER,
2 => ParameterType::STRING,
3 => Type::DATETIME,
)
);
$affectedRows = $this->_conn->executeUpdate($sql, [
1 => 50,
2 => 'foo',
3 => $datetime,
], [
1 => ParameterType::INTEGER,
2 => ParameterType::STRING,
3 => Type::DATETIME,
]);

self::assertEquals(1, $affectedRows);
self::assertEquals(1, $this->_conn->executeQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testConnectsWithValidCharsetOption($charset)

self::assertEquals(
$charset,
$connection->query("SHOW client_encoding")
$connection->query('SHOW client_encoding')
->fetch(FetchMode::COLUMN)
);
}
Expand Down
Loading

0 comments on commit 4190669

Please sign in to comment.