|
8 | 8 | use PhpParser\Node\Arg; |
9 | 9 | use PhpParser\Node\Expr; |
10 | 10 | use PhpParser\Node\Expr\Cast\String_ as CastString_; |
11 | | -use PhpParser\Node\Expr\ConstFetch; |
12 | 11 | use PhpParser\Node\Expr\FuncCall; |
13 | 12 | use PhpParser\Node\Expr\MethodCall; |
| 13 | +use PhpParser\Node\Expr\Ternary; |
14 | 14 | use PhpParser\Node\Identifier; |
15 | 15 | use PhpParser\Node\Scalar\InterpolatedString; |
16 | 16 | use PhpParser\Node\Scalar\String_; |
@@ -192,51 +192,68 @@ private function processNullToStrictStringOnNodePosition( |
192 | 192 |
|
193 | 193 | $argValue = $args[$position]->value; |
194 | 194 |
|
195 | | - if ($argValue instanceof ConstFetch && $this->valueResolver->isNull($argValue)) { |
| 195 | + if ($this->valueResolver->isNull($argValue)) { |
196 | 196 | $args[$position]->value = new String_(''); |
197 | 197 | $funcCall->args = $args; |
198 | 198 |
|
199 | 199 | return $funcCall; |
200 | 200 | } |
201 | 201 |
|
202 | | - $type = $this->nodeTypeResolver->getType($argValue); |
203 | | - if ($type->isString()->yes()) { |
| 202 | + if ($this->shouldSkipValue($argValue, $scope, $isTrait)) { |
204 | 203 | return null; |
205 | 204 | } |
206 | 205 |
|
207 | | - $nativeType = $this->nodeTypeResolver->getNativeType($argValue); |
208 | | - if ($nativeType->isString()->yes()) { |
209 | | - return null; |
| 206 | + $parameter = $parametersAcceptor->getParameters()[$position] ?? null; |
| 207 | + if ($parameter instanceof ExtendedNativeParameterReflection && $parameter->getType() instanceof UnionType) { |
| 208 | + $parameterType = $parameter->getType(); |
| 209 | + if (! $this->isValidUnionType($parameterType)) { |
| 210 | + return null; |
| 211 | + } |
210 | 212 | } |
211 | 213 |
|
212 | | - if ($this->shouldSkipType($type)) { |
213 | | - return null; |
| 214 | + if ($argValue instanceof Ternary && ! $this->shouldSkipValue($argValue->else, $scope, $isTrait)) { |
| 215 | + if ($this->valueResolver->isNull($argValue->else)) { |
| 216 | + $argValue->else = new String_(''); |
| 217 | + } else { |
| 218 | + $argValue->else = new CastString_($argValue->else); |
| 219 | + } |
| 220 | + |
| 221 | + $args[$position]->value = $argValue; |
| 222 | + $funcCall->args = $args; |
| 223 | + return $funcCall; |
214 | 224 | } |
215 | 225 |
|
216 | | - if ($argValue instanceof InterpolatedString) { |
217 | | - return null; |
| 226 | + $args[$position]->value = new CastString_($argValue); |
| 227 | + $funcCall->args = $args; |
| 228 | + |
| 229 | + return $funcCall; |
| 230 | + } |
| 231 | + |
| 232 | + private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait): bool |
| 233 | + { |
| 234 | + $type = $this->nodeTypeResolver->getType($expr); |
| 235 | + if ($type->isString()->yes()) { |
| 236 | + return true; |
218 | 237 | } |
219 | 238 |
|
220 | | - if ($this->isAnErrorType($argValue, $nativeType, $scope)) { |
221 | | - return null; |
| 239 | + $nativeType = $this->nodeTypeResolver->getNativeType($expr); |
| 240 | + if ($nativeType->isString()->yes()) { |
| 241 | + return true; |
222 | 242 | } |
223 | 243 |
|
224 | | - if ($this->shouldSkipTrait($argValue, $type, $isTrait)) { |
225 | | - return null; |
| 244 | + if ($this->shouldSkipType($type)) { |
| 245 | + return true; |
226 | 246 | } |
227 | 247 |
|
228 | | - $parameter = $parametersAcceptor->getParameters()[$position] ?? null; |
229 | | - if ($parameter instanceof ExtendedNativeParameterReflection && $parameter->getType() instanceof UnionType) { |
230 | | - $parameterType = $parameter->getType(); |
231 | | - if (! $this->isValidUnionType($parameterType)) { |
232 | | - return null; |
233 | | - } |
| 248 | + if ($expr instanceof InterpolatedString) { |
| 249 | + return true; |
234 | 250 | } |
235 | 251 |
|
236 | | - $args[$position]->value = new CastString_($argValue); |
237 | | - $funcCall->args = $args; |
| 252 | + if ($this->isAnErrorType($expr, $nativeType, $scope)) { |
| 253 | + return true; |
| 254 | + } |
238 | 255 |
|
239 | | - return $funcCall; |
| 256 | + return $this->shouldSkipTrait($expr, $type, $isTrait); |
240 | 257 | } |
241 | 258 |
|
242 | 259 | private function isValidUnionType(Type $type): bool |
|
0 commit comments