Skip to content

fix(AppFramework): Adjust types so PHPStan understands them#58098

Draft
provokateurin wants to merge 1 commit intomasterfrom
fix/appframework/types-phpstan
Draft

fix(AppFramework): Adjust types so PHPStan understands them#58098
provokateurin wants to merge 1 commit intomasterfrom
fix/appframework/types-phpstan

Conversation

@provokateurin
Copy link
Member

@provokateurin provokateurin added this to the Nextcloud 34 milestone Feb 5, 2026
@provokateurin provokateurin requested a review from a team as a code owner February 5, 2026 11:46
@provokateurin provokateurin requested review from leftybournes and salmart-dev and removed request for a team February 5, 2026 11:46
@provokateurin provokateurin mentioned this pull request Feb 5, 2026
5 tasks
@nickvergessen
Copy link
Member

* @template S of Http::STATUS_*
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-covariant T of array|int|float|string|bool|object|null|\stdClass|\JsonSerializable
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that not the same as mixed 🙃 ?

Also, \stdClass|\JsonSerializable is redundant with object, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this is the correct type. It only allows what can be serialized to JSON.

Copy link
Contributor

Choose a reason for hiding this comment

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

But how can a var be \stdClass without being object? And same for JsonSerializable. For me either object or \stdClass|\JsonSerializable should be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://www.php.net/manual/en/language.types.mixed.php The only thing refused in this union is resource.

use OCP\AppFramework\OCSController;

/**
* @psalm-import-type DataResponseType from DataResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no generic equivalent to this psalm instruction?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not that phpstan doesn't understand this, it seems to have problems with the template-covariant referencing the alias.

* @template-extends BaseResponse<Http::STATUS_*, DataResponseType, array<string, mixed>>
* @template-covariant T of array|int|float|string|bool|object|null|\stdClass|\JsonSerializable
* @template-covariant H of array<string, mixed>
* @template-extends BaseResponse<Http::STATUS_*, array|int|float|string|bool|object|null|\stdClass|\JsonSerializable, array<string, mixed>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @template-extends BaseResponse<Http::STATUS_*, array|int|float|string|bool|object|null|\stdClass|\JsonSerializable, array<string, mixed>>
* @template-extends BaseResponse<Http::STATUS_*, T, array<string, mixed>>

Is that not the same type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Back when this was added it didn't work with psalm, but yes that is how it is supposed to be.

@provokateurin
Copy link
Member Author

One so higher levels more adjustments are needed, so I'll wait until I have found all problems.

@provokateurin provokateurin marked this pull request as draft February 5, 2026 14:10
auto-merge was automatically disabled February 5, 2026 14:10

Pull request was converted to draft

Signed-off-by: provokateurin <kate@provokateurin.de>
@provokateurin provokateurin force-pushed the fix/appframework/types-phpstan branch from c979a7d to 4f81b36 Compare February 5, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants