Skip to content

Commit 3996639

Browse files
authored
Remove ignore-next-line (#335)
* Remove ignore-next-line * Added getColumnMeta() stub * Update PdoStatement.stub * Update PdoQueryReflector.php * Update PdoQueryReflector.php * Update PdoQueryReflector.php * Update PdoQueryReflector.php * Update src/QueryReflection/PdoQueryReflector.php * Update PdoQueryReflector.php
1 parent 6fb8770 commit 3996639

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

config/PdoStatement.stub

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ class PDOStatement implements Traversable, IteratorAggregate
1717
* @return false|T
1818
*/
1919
public function fetchObject($class = \stdclass::class, array $ctorArgs = array()) {}
20+
21+
/**
22+
* @return array{name: string, table: string, native_type: string, len: int, flags: array<int, string>, precision: int<0, max>, pdo_type: PDO::PARAM_* }|false
23+
*/
24+
public function getColumnMeta(int $column) {}
2025
}

src/QueryReflection/PdoQueryReflector.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use function strtoupper;
1919

2020
/**
21-
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: list<string>}
21+
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: array<int, string>, precision: int<0, max>, pdo_type: PDO::PARAM_* }
2222
*/
2323
final class PdoQueryReflector implements QueryReflector
2424
{
@@ -47,7 +47,7 @@ final class PdoQueryReflector implements QueryReflector
4747
private const MAX_CACHE_SIZE = 50;
4848

4949
/**
50-
* @var array<string, PDOException|list<ColumnMeta>|null>
50+
* @var array<string, PDOException|array<int<0, max>, ColumnMeta>|null>
5151
*/
5252
private array $cache = [];
5353

@@ -165,22 +165,13 @@ private function simulateQuery(string $queryString)
165165
$columnIndex = 0;
166166
while ($columnIndex < $columnCount) {
167167
// see https://github.com/php/php-src/blob/master/ext/pdo_mysql/mysql_statement.c
168+
/** @var ColumnMeta|false */
168169
$columnMeta = $stmt->getColumnMeta($columnIndex);
169170

170171
if (false === $columnMeta) {
171172
throw new ShouldNotHappenException('Failed to get column meta for column index '.$columnIndex);
172173
}
173174

174-
if (
175-
!\array_key_exists('name', $columnMeta)
176-
|| !\array_key_exists('table', $columnMeta)
177-
|| !\array_key_exists('native_type', $columnMeta)
178-
|| !\array_key_exists('flags', $columnMeta)
179-
|| !\array_key_exists('len', $columnMeta)
180-
) {
181-
throw new ShouldNotHappenException();
182-
}
183-
184175
$flags = $this->emulateMysqlFlags($columnMeta['native_type'], $columnMeta['table'], $columnMeta['name']);
185176
foreach ($flags as $flag) {
186177
$columnMeta['flags'][] = $flag;
@@ -191,7 +182,6 @@ private function simulateQuery(string $queryString)
191182
++$columnIndex;
192183
}
193184

194-
// @phpstan-ignore-next-line
195185
return $this->cache[$queryString];
196186
}
197187

0 commit comments

Comments
 (0)