Skip to content

Commit

Permalink
implement case-expression inference (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Feb 17, 2023
1 parent 5ae4471 commit a5322f9
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 0 deletions.
152 changes: 152 additions & 0 deletions .phpstan-dba-mysqli.cache

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

11 changes: 11 additions & 0 deletions src/SqlAst/QueryScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use SqlFtw\Sql\Expression\BoolValue;
use SqlFtw\Sql\Expression\CaseExpression;
use SqlFtw\Sql\Expression\ExpressionNode;
use SqlFtw\Sql\Expression\FunctionCall;
use SqlFtw\Sql\Expression\Identifier;
Expand Down Expand Up @@ -112,6 +114,15 @@ public function getType($expression): Type
throw new ShouldNotHappenException('Unable to resolve column '.$expression->getName());
}

if ($expression instanceof CaseExpression) {
$resultTypes = [];
foreach ($expression->getResults() as $result) {
$resultTypes[] = $this->getType($result);
}

return TypeCombinator::union(...$resultTypes);
}

if ($expression instanceof FunctionCall) {
foreach ($this->extensions as $extension) {
if (!$extension->isFunctionSupported($expression)) {
Expand Down
139 changes: 139 additions & 0 deletions tests/default/config/.phpunit-phpstan-dba-mysqli.cache

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

Loading

0 comments on commit a5322f9

Please sign in to comment.