Skip to content

Commit ef2836b

Browse files
committed
Fix phpstan issues
1 parent 69f3768 commit ef2836b

4 files changed

Lines changed: 26 additions & 61 deletions

File tree

src/ClickHouseMetadataProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Doctrine\DBAL\Schema\Metadata\PrimaryKeyConstraintColumnRow;
2626
use Doctrine\DBAL\Schema\Metadata\TableColumnMetadataRow;
2727
use Doctrine\DBAL\Schema\Metadata\TableMetadataRow;
28+
use Doctrine\DBAL\Schema\Metadata\ViewMetadataRow;
2829

2930
use function implode;
3031
use function sprintf;
@@ -252,7 +253,7 @@ public function getAllViews(): iterable
252253
$sql = "SELECT name, create_table_query FROM system.tables WHERE database = ? AND engine = 'View' ORDER BY name";
253254

254255
foreach ($this->connection->iterateNumeric($sql, [$this->databaseName]) as $row) {
255-
yield new ClickHouseViewMetadataRow(null, $row[0], $row[1]);
256+
yield new ViewMetadataRow(null, $row[0], $row[1]);
256257
}
257258
}
258259

src/ClickHousePlatform.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ public function getCommentOnColumnSQL(string $tableName, string $columnName, str
486486
*/
487487
protected function _getCreateTableSQL(string $name, array $columns, array $options = []): array
488488
{
489+
/** @var array{
490+
* engine: string|null,
491+
* uniqueConstraints: array|null,
492+
* indexes: array|null,
493+
* indexGranularity: int|null,
494+
* eventDateProviderColumn: string|null,
495+
* eventDateColumn: string|null,
496+
* primary: array|null,
497+
* samplingExpression: string|null,
498+
* versionColumn: string|null,
499+
* } $options
500+
*/
489501
$engine = !empty($options['engine']) ? $options['engine'] : 'ReplacingMergeTree';
490502
$engineOptions = '';
491503

@@ -544,7 +556,7 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
544556
!($columns[$options['eventDateProviderColumn']]['type'] instanceof DecimalType) &&
545557
(
546558
!($columns[$options['eventDateProviderColumn']]['type'] instanceof StringType) ||
547-
$columns[$options['eventDateProviderColumn']]['fixed']
559+
$columns[$options['eventDateProviderColumn']]['fixed'] // @phpstan-ignore offsetAccess.notFound
548560
)
549561
) {
550562
throw new \Exception(
@@ -656,7 +668,7 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
656668
$sql[] = sprintf(
657669
'CREATE TABLE %s (%s) ENGINE = %s%s',
658670
$name,
659-
$this->getColumnDeclarationListSQL($columns),
671+
$this->getColumnDeclarationListSQL(array_values($columns)),
660672
$engine,
661673
$engineOptions
662674
);

src/ClickHouseViewMetadataRow.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/MetadataProviderTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
use Doctrine\DBAL\Schema\Metadata\TableMetadataRow;
2626
use FOD\DBALClickHouse\ClickHouseMetadataProvider;
2727
use FOD\DBALClickHouse\ClickHousePlatform;
28-
use FOD\DBALClickHouse\ClickHouseViewMetadataRow;
2928
use PHPUnit\Framework\TestCase;
3029

3130
/**
3231
* ClickHouse DBAL test class. Testing work with public methods of FOD\DBALClickHouse\ClickHouseMetadataProvider class
3332
*/
34-
class MetadataProviderTest extends TestCase
33+
class ClickHouseMetadataProviderTest extends TestCase
3534
{
3635
private ClickHouseMetadataProvider $metadataProvider;
3736
private Connection $connection;
@@ -40,9 +39,9 @@ public function setUp(): void
4039
{
4140
$this->connection = CreateConnectionTest::createConnection();
4241
$platform = $this->connection->getDatabasePlatform();
43-
42+
4443
$this->metadataProvider = new ClickHouseMetadataProvider($this->connection, $platform);
45-
44+
4645
// Create test tables for testing
4746
$this->createTestTables();
4847
}
@@ -108,7 +107,7 @@ public function testGetAllTableNames(): void
108107
$this->assertNull($row->getSchemaName());
109108
$this->assertIsString($row->getTableName());
110109
$this->assertEmpty($row->getOptions());
111-
110+
112111
if ($row->getTableName() === 'test_metadata_table') {
113112
$testTableFound = true;
114113
}
@@ -136,7 +135,7 @@ public function testGetTableColumnsForAllTables(): void
136135
$this->assertNull($row->getSchemaName());
137136
$this->assertSame('test_metadata_table', $row->getTableName());
138137
$this->assertNotNull($row->getColumn());
139-
138+
140139
$column = $row->getColumn();
141140
$this->assertIsString($column->getName());
142141
$this->assertNotNull($column->getType());
@@ -164,7 +163,7 @@ public function testGetTableColumnsForTable(): void
164163
$this->assertNull($row->getSchemaName());
165164
$this->assertSame('test_metadata_table', $row->getTableName());
166165
$this->assertNotNull($row->getColumn());
167-
166+
168167
$column = $row->getColumn();
169168
$columnNames[] = $column->getName();
170169
}
@@ -279,7 +278,7 @@ public function testGetTableOptionsForAllTables(): void
279278
$this->assertNull($row->getSchemaName());
280279
$this->assertIsString($row->getTableName());
281280
$this->assertIsArray($row->getOptions());
282-
281+
283282
if ($row->getTableName() === 'test_metadata_table') {
284283
$testTable = $row;
285284
}
@@ -310,7 +309,7 @@ public function testGetTableOptionsForTable(): void
310309
$this->assertInstanceOf(TableMetadataRow::class, $row);
311310
$this->assertNull($row->getSchemaName());
312311
$this->assertSame('test_metadata_table', $row->getTableName());
313-
312+
314313
$options = $row->getOptions();
315314
$this->assertArrayHasKey('engine', $options);
316315
$this->assertSame('MergeTree', $options['engine']);
@@ -326,11 +325,10 @@ public function testGetAllViews(): void
326325
// Find our test view
327326
$testView = null;
328327
foreach ($results as $row) {
329-
$this->assertInstanceOf(ClickHouseViewMetadataRow::class, $row);
328+
$this->assertInstanceOf(ViewMetadataRow::class, $row);
330329
$this->assertNull($row->getSchemaName());
331330
$this->assertIsString($row->getViewName());
332-
$this->assertIsString($row->getSql());
333-
331+
334332
if ($row->getViewName() === 'test_metadata_view') {
335333
$testView = $row;
336334
}

0 commit comments

Comments
 (0)