Skip to content

Commit a5322f9

Browse files
authored
implement case-expression inference (#522)
1 parent 5ae4471 commit a5322f9

File tree

5 files changed

+455
-0
lines changed

5 files changed

+455
-0
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SqlAst/QueryScope.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use PHPStan\Type\MixedType;
1313
use PHPStan\Type\NullType;
1414
use PHPStan\Type\Type;
15+
use PHPStan\Type\TypeCombinator;
1516
use SqlFtw\Sql\Expression\BoolValue;
17+
use SqlFtw\Sql\Expression\CaseExpression;
1618
use SqlFtw\Sql\Expression\ExpressionNode;
1719
use SqlFtw\Sql\Expression\FunctionCall;
1820
use SqlFtw\Sql\Expression\Identifier;
@@ -112,6 +114,15 @@ public function getType($expression): Type
112114
throw new ShouldNotHappenException('Unable to resolve column '.$expression->getName());
113115
}
114116

117+
if ($expression instanceof CaseExpression) {
118+
$resultTypes = [];
119+
foreach ($expression->getResults() as $result) {
120+
$resultTypes[] = $this->getType($result);
121+
}
122+
123+
return TypeCombinator::union(...$resultTypes);
124+
}
125+
115126
if ($expression instanceof FunctionCall) {
116127
foreach ($this->extensions as $extension) {
117128
if (!$extension->isFunctionSupported($expression)) {

tests/default/config/.phpunit-phpstan-dba-mysqli.cache

Lines changed: 139 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)