-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add TableLocator get by FQCN #18957
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
Add TableLocator get by FQCN #18957
Conversation
|
Forgot to run phpcs, making fix |
| { | ||
| // phpcs:ignore | ||
| /** @var T */ | ||
| return $this->getTableLocator()->get($class, $options); |
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.
Do we really need a new method? Can't use conditional return type with phpdoc?
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.
Tried it but it didnt work or phpstan was throwing errors
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.
Does PHPstan not have a way to do method signature overloads?
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.
I tried it in the single method for 2 hours, but i cannot figure it out.
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.
maybe something like this https://phpstan.org/r/e39d9eaf-51f5-4b6b-a5dc-b6511808d8a2
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.
Didnt know IDEs have support for ternary operators in return. I think it is working. Thanks for help :)
| * @param array<string, mixed> $options The options you want to build the table with. | ||
| * If a table has already been loaded the registry options will be ignored. | ||
| * @return \Cake\ORM\Table | ||
| * @return ($alias is class-string<T> ? T : \Cake\ORM\Table) |
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.
I wonder if this should be moved into phpstan-* tags instead of having a precedence on using these non-standard ones directly on param/return.
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.
When i move this to phpstan-* the feature stops working for VSCode
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.
I didnt know IDEs support this, that was main reason i did it in separate function
|
Now that this contains only annotation changes, it can go in |
dereuromark
left a comment
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.
I tested in PHPStorm, also seems to work fine out of the box.
I wonder if there are other similar cases where we could apply this.
|
In vscode it works too |
|
Thank you 🎉 |
* Add TableLocator get by FQCN * Add missing docblock, add phpcs ignore * Fix whitespace * Revert TableLocator, Add fetchTableByClass * Merge fetchTable and fetchTableByClass --------- Co-authored-by: Adam Halfar <halfar@seonet.cz>
Resolves #18954