Skip to content

Commit e15924c

Browse files
committed
Chore: Implement suggestions by CodeRabbit
- Remove redundant test function `testPrepareWithBindParam` - Remove deprecated test function about `PDO::FETCH_CLASS` - Complete function signature type hinting - Improve MapType::convertToPHPValue about accounting for `null` values
1 parent 8bf6a95 commit e15924c

File tree

3 files changed

+7
-48
lines changed

3 files changed

+7
-48
lines changed

src/Crate/DBAL/Types/ArrayType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
9595
* @return string
9696
* @throws \Doctrine\DBAL\Exception
9797
*/
98-
public function getArrayTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options)
98+
public function getArrayTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options): string
9999
{
100100
$type = array_key_exists('type', $options) ? $options['type'] : Types::STRING;
101101
return 'ARRAY ( ' . Type::getType($type)->getSQLDeclaration($field, $platform) . ' )';

src/Crate/DBAL/Types/MapType.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getBindingType()
6464

6565
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
6666
{
67-
if (!is_array($value) || (count($value) > 0 && !(array_keys($value) !== range(0, count($value) - 1)))) {
67+
if (!is_array($value) || (count($value) > 0 && array_keys($value) === range(0, count($value) - 1))) {
6868
return null;
6969
}
7070

@@ -73,7 +73,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): mixe
7373

7474
public function convertToPHPValue($value, AbstractPlatform $platform): mixed
7575
{
76-
return $value == null ?: (array) $value;
76+
if ($value === null) {
77+
return null;
78+
}
79+
return (array) $value;
7780
}
7881

7982
/**
@@ -100,7 +103,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
100103
* @return string
101104
* @throws \Doctrine\DBAL\Exception
102105
*/
103-
public function getMapTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options)
106+
public function getMapTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options): string
104107
{
105108
$type = array_key_exists('type', $options) ? $options['type'] : MapType::DYNAMIC;
106109

test/Crate/Test/DBAL/Functional/DataAccessTest.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,6 @@ public function testPrepareWithBindValue()
100100
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row);
101101
}
102102

103-
public function testPrepareWithBindParam()
104-
{
105-
$paramInt = 1;
106-
$paramStr = 'foo';
107-
108-
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
109-
$stmt = $this->_conn->prepare($sql);
110-
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
111-
112-
$stmt->bindValue(1, $paramInt, PDO::PARAM_INT);
113-
$stmt->bindValue(2, $paramStr, PDO::PARAM_STR);
114-
$result = $stmt->executeQuery();
115-
116-
$row = $result->fetchAssociative();
117-
$row = array_change_key_case($row, \CASE_LOWER);
118-
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row);
119-
}
120-
121103
public function testPrepareWithFetchAll()
122104
{
123105
$paramInt = 1;
@@ -436,32 +418,6 @@ public function testSetDefaultFetchMode()
436418
$this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result.");
437419
}
438420

439-
/**
440-
* @group DBAL-196
441-
*/
442-
public function testFetchAllSupportFetchClass()
443-
{
444-
$this->markTestSkipped("PDO::FETCH_CLASS is not supported by the CrateDB PDO driver");
445-
446-
$this->setupFixture();
447-
448-
$sql = "SELECT test_int, test_string, test_datetime FROM fetch_table";
449-
$stmt = $this->_conn->prepare($sql);
450-
$result = $stmt->executeQuery();
451-
452-
$results = $result->fetch(
453-
PDO::FETCH_CLASS,
454-
__NAMESPACE__.'\\MyFetchClass'
455-
);
456-
457-
$this->assertEquals(1, count($results));
458-
$this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);
459-
460-
$this->assertEquals(1, $results[0]->test_int);
461-
$this->assertEquals('foo', $results[0]->test_string);
462-
$this->assertStringStartsWith('2010-01-01T10:10:10', $results[0]->test_datetime);
463-
}
464-
465421
/**
466422
* @group DBAL-241
467423
*/

0 commit comments

Comments
 (0)