-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow casts with a return type of static or this to reference themselves #1103
Conversation
Can you please add a test showing the behavour change? Thank you! |
Thanks for suggesting the tests @mfn, it made me realise a bug in my code :) I've added hopefully thorough tests for all the different cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR LGTM!
However, can you please undo the unrelated phpunit changes as outlined?
Thank you!
Supports ```php /** * @param $model * @param string $key * @param $value * @param array $attributes * @return static */ public function get($model, string $key, $value, array $attributes) { return new static($value); } ``` or ```php /** * @param $model * @param string $key * @param $value * @param array $attributes * @return $this */ public function get($model, string $key, $value, array $attributes) { return new static($value); } ```
@mfn All done :) |
@hailwood great! sorry forgot, please add a changelog (also next time: please don't delete the PR template, it's there for a reason to be reminded of such things, thank you!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🤗
@barryvdh LGTM for merge!
Thanks @mfn What would you put in the Changelog?
|
@hailwood yeah, sounds good to me! |
Right now a cast cannot specify that it returns static or this.
Allowing so would mean a new cast can extend the old one without having to redefine the get method (e.g. an Enum)
Presently if you specify static/this in the return type then those values are literally used which makes a property look like it returns an instance of the model itself.