Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 0 additions & 208 deletions .phpstan-dba-mysqli.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/QueryReflection/BasePdoQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use staabm\PHPStanDba\TypeMapping\TypeMapper;

/**
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: list<string>}
* @phpstan-type ColumnMeta array{name: string, table: string, native_type: string, len: int, flags: list<string>, pdo_type: int}
*/
abstract class BasePdoQueryReflector
{
Expand Down
8 changes: 8 additions & 0 deletions src/QueryReflection/PdoQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ protected function simulateQuery(string $queryString)
throw new ShouldNotHappenException('Failed to get column meta for column index '.$columnIndex);
}

/*
* Native type may not be set, for example in case of JSON column.
* @phpstan-ignore-next-line
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not updated the ColumnMeta to represent the actual state of PDO.getColumnMeta return value as just ignoring this line was so much easier... 🤡

*/
if (!isset($columnMeta['native_type'])) {
$columnMeta['native_type'] = \PDO::PARAM_INT === $columnMeta['pdo_type'] ? 'INT' : 'STRING';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to pdo_mysql src, native_type can be missing from the return value:
https://github.com/php/php-src/blob/14319c203cb13a7cc0644fb4276d6e62338fda5e/ext/pdo_mysql/mysql_statement.c#L806-L808

and in that case, we may fallback to the pdo_type, problem is, according to my understanding of the sources, this can be either INT or STR... https://github.com/php/php-src/blob/14319c203cb13a7cc0644fb4276d6e62338fda5e/ext/pdo_mysql/mysql_statement.c#L811-L827.

}

$flags = $this->emulateFlags($columnMeta['native_type'], $columnMeta['table'], $columnMeta['name']);
foreach ($flags as $flag) {
$columnMeta['flags'][] = $flag;
Expand Down
4 changes: 4 additions & 0 deletions src/TypeMapping/PgsqlTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
Expand Down Expand Up @@ -73,10 +74,13 @@ public function mapToPHPStanType(string $type, array $flags, int $length): Type
// fallbacks
if (null === $phpstanType) {
$phpstanType = match (strtoupper($type)) {
'BOOL' => new BooleanType(),
'BIT',
'INT2',
'INT4',
'INT8' => new IntegerType(),
'JSON',
'JSONB',
'DATE',
'TEXT',
'TIME',
Expand Down
Loading