ReturnTypeFromStrictTernaryRector: Support complex ternaries#4515
ReturnTypeFromStrictTernaryRector: Support complex ternaries#4515TomasVotruba merged 14 commits intorectorphp:mainfrom
Conversation
...ypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector/Fixture/short_ternary.php.inc
Outdated
Show resolved
Hide resolved
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture; | ||
|
|
||
| final class SkipPhpdocs |
There was a problem hiding this comment.
this test fails to skip right now. If I understood the "strict" rules correctly, they should not rely on phpdoc, right?
if so, any idea how to achieve that?
There was a problem hiding this comment.
You can compare type vs native type, like in ExprAnalyzer:
rector-src/src/NodeAnalyzer/ExprAnalyzer.php
Lines 42 to 52 in f056974
There was a problem hiding this comment.
thanks. I added a native type check and now I am wondering why ternary_var_call.php.inc is failling.
rector type resolving tells me the native type of the ternary is MixedType but running the same code directly in PHPStan returns a correct native type..
There was a problem hiding this comment.
I dropped the failling test for now, as I don't see it important enough to block the actual useful change
rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php
Show resolved
Hide resolved
| continue; | ||
| } | ||
|
|
||
| $onlyStmt = $classMethod->stmts[0] ?? null; |
There was a problem hiding this comment.
before this PR this rector only supported call-methods with a single line.
I wided the scope to call-likes with a single return
|
should be ready for review/merge @samsonasik |
rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php
Outdated
Show resolved
Hide resolved
|
Looks good, thank you 👍 |
idea is to allow ReturnTypeFromStrictTernaryRector to infer the native return type on complex typed expressions