1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Add a how to fix section for MixedAssignment

This commit is contained in:
Matthew Brown 2020-03-16 09:30:51 -04:00 committed by GitHub
parent 4232bfb6e6
commit f22f5e38f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1263,6 +1263,28 @@ cannot infer a type more specific than `mixed`.
$a = $_GET['foo'];
```
#### How to fix
The above example can be fixed in a few ways by adding an `assert` call:
```php
$a = $_GET['foo'];
assert(is_string($a));
```
or by adding an explicit cast:
```php
$a = (string) $_GET['foo'];
```
or by adding a docblock
```php
/** @var string */
$a = (string) $_GET['foo'];
```
### MixedFunctionCall
Emitted when calling a function on a value whose type Psalm cannot infer.