|
7 | 7 | use PhpParser\Node\Expr; |
8 | 8 | use PhpParser\Node\Expr\BinaryOp\Concat; |
9 | 9 | use PHPStan\Analyser\Scope; |
10 | | -use PHPStan\Type\BooleanType; |
11 | 10 | use PHPStan\Type\Constant\ConstantArrayType; |
12 | 11 | use PHPStan\Type\Constant\ConstantIntegerType; |
13 | 12 | use PHPStan\Type\Constant\ConstantStringType; |
14 | | -use PHPStan\Type\ConstantScalarType; |
15 | | -use PHPStan\Type\FloatType; |
16 | | -use PHPStan\Type\IntegerType; |
17 | | -use PHPStan\Type\IntersectionType; |
18 | | -use PHPStan\Type\MixedType; |
19 | | -use PHPStan\Type\StringType; |
20 | 13 | use PHPStan\Type\Type; |
21 | | -use PHPStan\Type\UnionType; |
22 | 14 | use staabm\PHPStanDba\DbaException; |
23 | 15 | use staabm\PHPStanDba\Error; |
24 | 16 |
|
@@ -106,34 +98,8 @@ public function resolveQueryString(Expr $queryExpr, Scope $scope): ?string |
106 | 98 | } |
107 | 99 |
|
108 | 100 | $type = $scope->getType($queryExpr); |
109 | | - if ($type instanceof ConstantScalarType) { |
110 | | - return (string) $type->getValue(); |
111 | | - } |
112 | | - |
113 | | - $integerType = new IntegerType(); |
114 | | - if ($integerType->isSuperTypeOf($type)->yes()) { |
115 | | - return '1'; |
116 | | - } |
117 | | - |
118 | | - $booleanType = new BooleanType(); |
119 | | - if ($booleanType->isSuperTypeOf($type)->yes()) { |
120 | | - return '1'; |
121 | | - } |
122 | | - |
123 | | - if ($type->isNumericString()->yes()) { |
124 | | - return '1'; |
125 | | - } |
126 | 101 |
|
127 | | - $floatType = new FloatType(); |
128 | | - if ($floatType->isSuperTypeOf($type)->yes()) { |
129 | | - return '1.0'; |
130 | | - } |
131 | | - |
132 | | - if ($type instanceof MixedType || $type instanceof StringType || $type instanceof IntersectionType || $type instanceof UnionType) { |
133 | | - return null; |
134 | | - } |
135 | | - |
136 | | - throw new DbaException(sprintf('Unexpected expression type %s', \get_class($type))); |
| 102 | + return QuerySimulation::simulateParamValueType($type); |
137 | 103 | } |
138 | 104 |
|
139 | 105 | private function getQueryType(string $query): ?string |
@@ -166,17 +132,9 @@ public function resolveParameters(Type $parameterTypes): ?array |
166 | 132 | $placeholderName = ':'.$placeholderName; |
167 | 133 | } |
168 | 134 |
|
169 | | - if ($valueTypes[$i] instanceof ConstantScalarType) { |
170 | | - $parameters[$placeholderName] = $valueTypes[$i]->getValue(); |
171 | | - } else { |
172 | | - return null; |
173 | | - } |
| 135 | + $parameters[$placeholderName] = QuerySimulation::simulateParamValueType($valueTypes[$i]); |
174 | 136 | } elseif ($keyType instanceof ConstantIntegerType) { |
175 | | - if ($valueTypes[$i] instanceof ConstantScalarType) { |
176 | | - $parameters[$keyType->getValue()] = $valueTypes[$i]->getValue(); |
177 | | - } else { |
178 | | - return null; |
179 | | - } |
| 137 | + $parameters[$keyType->getValue()] = QuerySimulation::simulateParamValueType($valueTypes[$i]); |
180 | 138 | } |
181 | 139 | } |
182 | 140 |
|
|
0 commit comments