I was going through PHPDocumentor, Netbeans and PHPStorm metadata specs and there isn't any solution for this yet.
1/ In most cases, the type analysis would work fine, e.g. in following case:
<?php
$x = new class { /**/ };
if (something) $a = wrongtype;;
else $a = $x;
$a->... // <-- this would assume $a is both "$x|wrongtype"
2/ For something like following:
<?php
$x = new class { /**/ };
$a = something( $a ); // <-- and you want to keep the type of $a
there is an option to create .phpstorm.metadata.php
with override(something(0), type(0));
3/ otherwise maybe just write the code in way, so the type analysis will work :D if you give me some edge case, we can improve the type analysis to handle it?