[TypeDeclaration] Skip ReturnTypeDeclarationRector when class parent extends is in 'vendor'#5308
[TypeDeclaration] Skip ReturnTypeDeclarationRector when class parent extends is in 'vendor'#5308TomasVotruba merged 14 commits intomasterfrom
Conversation
7cead9b to
bc1d6d6
Compare
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
| private function isParentInVendor(ClassMethod $classMethod): bool | ||
| { | ||
| $parent = $classMethod->getAttribute(AttributeKey::PARENT_NODE); | ||
| if (! $parent instanceof Class_) { | ||
| return false; | ||
| } | ||
|
|
||
| if (! $parent->extends instanceof FullyQualified) { | ||
| return false; | ||
| } | ||
|
|
||
| $parentName = $parent->extends->toString(); | ||
| $reflectionClass = new ReflectionClass($parentName); | ||
| if ($reflectionClass->isInternal()) { | ||
| return true; | ||
| } | ||
|
|
||
| $fileName = $reflectionClass->getFileName(); | ||
| return Strings::contains((string) $fileName, 'vendor'); | ||
| } |
There was a problem hiding this comment.
This logic should be extracted to packages/vendor-locker
There might be some useful class like Rector\VendorLocker\NodeVendorLocker\ClassMethodVendorLockResolver
There was a problem hiding this comment.
implemented with use VendorLockResolver->isReturnChangeVendorLockedIn()
| - | ||
| message: '#Class cognitive complexity is 32, keep it under 30#' | ||
| path: rules/type-declaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php |
There was a problem hiding this comment.
Crossing cognitive complexity treshold should not be ignored.
Instead, should be solved by a new service extraction.
It works well with duplicated method PHPStan rule. That way we keep small consistent services with specific work and without duplication.
# Failing Test for ReturnTypeDeclarationRector Based on https://getrector.org/demo/097c7e08-1673-4f6a-a6ce-8c26ecee1dfa Issue: #5205
0828425 to
451ee34
Compare
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
Thank you 👍 |
|
@samsonasik There is one pull-request that is related to this issue. Could you verify it was fixed or handle it? |
|
I will try. |
rectorphp/rector-src@5c8fa12 [Doc] Typo fix on sample code documentation on SimplifyForeachToCoalescingRector (#5308)
Closes #5210 Fixes #5205