[TypeDeclaration] Skip trait methods on ParamTypeByMethodCallType rules#8189
Merged
Conversation
Trait methods can be used in classes that implement an interface contract. Adding a param type inferred from a local call would break the signature when the trait is composed into such a class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trait methods may be composed into classes that implement an interface contract. A param type inferred from a call inside the trait itself is not safe to add: once the trait is used in a class where the method must match a wider contract signature, the added type breaks it.
Skip
ClassMethodnodes whose scope is inside a trait.trait SomeTrait { - public function go($value) + public function go(array $value) // wrong, breaks contract when trait used in class implementing an interface { $this->use($value); } private function use(array $value): void { } }The skip lives in the shared
AbstractParamTypeByMethodCallTypeRector::shouldSkipClassMethod(), so it covers all four rules built on it:ArrayParamTypeByMethodCallTypeRectorObjectParamTypeByMethodCallTypeRectorScalarParamTypeByMethodCallTypeRectorParamTypeByMethodCallTypeRector