Skip to content

Conversation

@Harfusha
Copy link
Contributor

@Harfusha Harfusha commented Oct 8, 2025

Resolves #18954

@Harfusha
Copy link
Contributor Author

Harfusha commented Oct 8, 2025

Forgot to run phpcs, making fix

@Harfusha Harfusha changed the base branch from 5.x to 5.next October 8, 2025 12:27
@ADmad ADmad added ORM needs squashing The pull request should be squashed before merging labels Oct 8, 2025
{
// phpcs:ignore
/** @var T */
return $this->getTableLocator()->get($class, $options);
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@ADmad
Copy link
Member

ADmad commented Oct 10, 2025

Now that this contains only annotation changes, it can go in 5.x 🙂

@Harfusha Harfusha changed the base branch from 5.next to 5.x October 10, 2025 07:42
Copy link
Member

@dereuromark dereuromark left a 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.

@Harfusha
Copy link
Contributor Author

In vscode it works too

@markstory markstory merged commit 2375c76 into cakephp:5.x Oct 10, 2025
14 of 15 checks passed
@markstory
Copy link
Member

Thank you 🎉

ADmad pushed a commit that referenced this pull request Oct 12, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs squashing The pull request should be squashed before merging ORM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specific table aware TableLocator

5 participants