-
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Using DBAL's (4.x) prepare() method does not seem to properly narrow the result type.
#197 shows that the prepare method is properly supported, so I'm not entirely sure why this isn't working
public function temp(): void
{
$sql = <<<SQL
SELECT
product.productId
FROM
product
SQL;
$data = $this->connection->fetchAssociative($sql);
\PHPStan\dumpType($data); // Works fine
$stmt = $this->connection->prepare($sql);
$result = $stmt->executeQuery();
$data = $result->fetchAssociative();
\PHPStan\dumpType($stmt);
\PHPStan\dumpType($result);
\PHPStan\dumpType($data);
} 143 Dumped type: array{productId: int<0, 4294967295>}|false
149 Dumped type: Doctrine\DBAL\Statement
150 Dumped type: Doctrine\DBAL\Result
151 Dumped type: array<string, mixed>|false
<?php // phpstan-dba-bootstrap.php
use staabm\PHPStanDba\QueryReflection\PdoMysqlQueryReflector;
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
use staabm\PHPStanDba\QueryReflection\QueryReflection;
use Webmozart\Assert\Assert;
use YourSurprise\CRM\Kernel;
require_once __DIR__ . '/vendor/autoload.php';
$kernel = new Kernel($_ENV['APP_ENV'], (bool)($_ENV['APP_DEBUG'] ?? false));
$kernel->boot();
$pdo = $kernel->getContainer()->get('database_connection')->getNativeConnection();
Assert::isInstanceOf($pdo, \PDO::class);
$config = new RuntimeConfiguration()
->debugMode(true)
->analyzeWriteQueries(true);
$reflector = new PdoMysqlQueryReflector($pdo);
QueryReflection::setupReflector(
$reflector,
$config
);Metadata
Metadata
Assignees
Labels
No labels