How to create UnionType with 3+ sub-types? #7028
-
|
There are a few places I need to add union type declarations via - public $plugin = null;
+ public PluginInterface|string|null $plugin = null;However use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
$pluginType = new ObjectType('craft\base\PluginInterface');
$stringType = new StringType();
$nullType = new NullType();
// causes ShouldNotHappenException exception:
$unionType = new UnionType([$pluginType, $stringType, $nullType]);Is there a different way I could go about this with Rector? Or does this just need to be fixed in PHPStan first? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
At the moment it's limitation of PHPStan We go around it like this: |
Beta Was this translation helpful? Give feedback.
At the moment it's limitation of PHPStan
UnionTypeobject.We go around it like this:
https://github.com/rectorphp/rector-symfony/blob/91fd3f3882171c6f0c7e60c44e689e8d7d8ad0a4/config/sets/symfony/symfony6/symfony-return-types.php#L56-L63