Skip to content

Conversation

@kolorafa
Copy link
Contributor

@kolorafa kolorafa marked this pull request as ready for review September 24, 2025 15:15
@kolorafa
Copy link
Contributor Author

How to re-run those CI/CD checks?

As coding standard did fail to fetch phpstan binary 👀

@dereuromark
Copy link
Member

cc @rochamarcelo

@rochamarcelo
Copy link
Contributor

Looks good.

@kolorafa
Copy link
Contributor Author

@rochamarcelo You mean like changing
@return \Cake\Datasource\ResultSetInterface<array-key, mixed>
into
@return \Cake\Datasource\ResultSetInterface<array-key, TSubject>
?

@rochamarcelo
Copy link
Contributor

@kolorafa yes, also for \Cake\Datasource\EntityInterface|array

@markstory markstory added this to the 5.2.9 milestone Sep 27, 2025
@kolorafa
Copy link
Contributor Author

kolorafa commented Oct 6, 2025

Sorry for the delay.

Thinking if I should change
\Cake\ORM\ResultSetFactory<\Cake\Datasource\EntityInterface|array>

into
\Cake\ORM\ResultSetFactory<TSubject>
or
\Cake\ORM\ResultSetFactory<TSubject|array>

the same for
`\Cake\Datasource\ResultSetInterface<array-key, \Cake\Datasource\EntityInterface|mixed>

into
\Cake\Datasource\ResultSetInterface<array-key, TSubject>
or
\Cake\Datasource\ResultSetInterface<array-key, TSubject|mixed>

because in theory ResultSetInterface could contain any type/structure if formatters created and returing god-knowns-what $result = $formatter($result, $this); in line 747

@kolorafa
Copy link
Contributor Author

kolorafa commented Oct 6, 2025

Error: Parameter #1 $entity of method Cake\ORM\Table<array>::delete() expects Cake\Datasource\EntityInterface, array|Cake\Datasource\EntityInterface given.
Error: Parameter #1 $entity of method Cake\ORM\Table<array>::delete() expects Cake\Datasource\EntityInterface, array|Cake\Datasource\EntityInterface given.
Error: Parameter #1 $entity of method Cake\ORM\Table<array>::delete() expects Cake\Datasource\EntityInterface, array|Cake\Datasource\EntityInterface given.
Error: Property Cake\ORM\Query\SelectQuery<TSubject of array|Cake\Datasource\EntityInterface>::$resultSetFactory (Cake\ORM\ResultSetFactory<TSubject of array|Cake\Datasource\EntityInterface>) does not accept Cake\ORM\ResultSetFactory<array|Cake\Datasource\EntityInterface>.

The issue is because we allow "array" as a TSubject

* @template TSubject of \Cake\Datasource\EntityInterface|array
introduced in 2023-01-03

places that would need change/assert to allow arrays as a return values:

foreach ($query->all() as $assoc) {
$ok = $ok && $target->delete($assoc, $options);

foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) {
$success = $table->delete($related, $options);

foreach ($association->find()->where($conditions)->all()->toList() as $related) {
$success = $table->delete($related, $options);


Question, should I remove allowing array as a returned type, or update the code to assert/check if the deleted value is actually EntityInterface and throw CakeException if it's not?

Or better revert/skip last changes and skip them for now, as it might be better to introduce this change not in patch release but minor release?

@rochamarcelo
Copy link
Contributor

Ignore TSubject for now since it is causing more issues. Maybe we can use it in the future.

@kolorafa kolorafa force-pushed the selectquery-all-typehing-fix branch from fbafc02 to 28ed3f0 Compare October 6, 2025 15:23
@kolorafa
Copy link
Contributor Author

kolorafa commented Oct 6, 2025

Froce-pushed branch without the last commit.

I would also like those changes to be introduced, but I agree that it does generate issues that should be introduced in patch release.

So this PR only fixes the bad/missing second template for typehinting issue, and should be ready to merge.
Failing tests doesn't sound to be related to changes.

@kolorafa kolorafa force-pushed the selectquery-all-typehing-fix branch from 28ed3f0 to 9327269 Compare October 6, 2025 18:02
@kolorafa
Copy link
Contributor Author

kolorafa commented Oct 6, 2025

Rebased :)

@dereuromark dereuromark requested a review from markstory October 12, 2025 12:08
@dereuromark
Copy link
Member

@ADmad Does this look good to you?

@ADmad
Copy link
Member

ADmad commented Oct 12, 2025

@dereuromark If the IDEs and phpstan and are happy I am happy :)

@dereuromark dereuromark merged commit c6d6855 into cakephp:5.x Oct 12, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants