Skip to content

Revert "fix(state): update generic template type variable in ProviderInterface" #7094

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Apr 16, 2025

Reverts #7083

@nesl247
Copy link
Contributor

nesl247 commented Apr 22, 2025

So is this supposed to mean that we're not allowed to return multidimensional arrays from the provider? It's only expected to return an array of objects? Is there a reason for that? Having to built a DTO just to use a provider seems like overkill in some scenarios. Especially if it's not something we need documented.

@soyuka soyuka merged commit b1eeb98 into 4.1 May 6, 2025
218 of 221 checks passed
@soyuka soyuka deleted the revert-7083-provider-interface-phpstan branch May 6, 2025 12:34
@soyuka
Copy link
Member Author

soyuka commented May 6, 2025

@nesl247 the processor can return this, working with arrays in a provider makes things more complicated,

I'd love to see some use case of using an array

@nesl247
Copy link
Contributor

nesl247 commented May 6, 2025

@soyuka with this merged we no longer can return an array without phpstan complaining.

Our use case for arrays is data that we return that doesn't have a defined type due to difficulties, came from a third party, is legacy, or came directly from the database (insights) or a combination. In some of these cases we could make a Dto, but it would take a lot of work for no real benefit. It would take a lot less time to add the phpstan-ignore that we currently do, but would like to get rid of.

@soyuka
Copy link
Member Author

soyuka commented May 7, 2025

Use an stdClass (PDO can also return objects). My concern is that we assume from here:

$data = $this->provider->provide($operation, $uriVariables, $context);

That $data is an object, there may be missing checks in our code therefore there's no guarantee that it will actually work. We're quite low with PHPStan's level therefore it doesn't complain in our code base (I merged #7083 too soon).

Could you probably create a baseline on your phpstan and just ignore this error?

@nesl247
Copy link
Contributor

nesl247 commented May 8, 2025

I know PDO can return objects we just don't prefer to use it that way. And most of what we return isn't directly from the database, it's just a few cases.

Is the stance that api platform will only support objects going forward, or that arrays should work too but can't be guaranteed yet, and any issues we find would need to be reported and solved?

Asking so it's clear to us what direction to go in. If it's that objects are the only thing that will be supported, it should be made more clear in the documentation.

I'm not complaining either way, just asking for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants