Problem/Motivation

The return type for UserPermissionsForm::permissionsByProvider() is documented as string[][].
This seems to be wrong, the array has an additional depth level and can contain boolean and nulls, not only strings.

Steps to reproduce

Proposed resolution

We can use @phpstan-type to define a custom type describing what the array can contain.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3549362

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
prudloff’s picture

Issue summary: View changes
prudloff’s picture

Issue summary: View changes
mstrelan’s picture

Added some comments, I think at least we need to update the return description. Maybe add @see \Drupal\user\PermissionHandlerInterface::getPermissions explaining that's what a permission looks like.

quietone’s picture

Version: 11.2.x-dev » 11.x-dev

Hi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.

The MR should be on 11.x as well.

mstrelan’s picture

I put up an alternative more advanced solution using @phpstan-type and @phpstan-import-type in MR !13352. Not sure if core is ready for this though so feel free to run with the original if that's desired.

smustgrave’s picture

Can we close 1 MR here?

dcam’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

I'd roll with the @phpstan-type solution. It looks good to me. I'm setting this to Needs Work because the proposed resolution section of the issue summary needs to be updated with the newer solution.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

I updated the summary.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

I do believe the feedback for this one has been addressed, correct me if I'm wrong.

benjifisher’s picture

Status: Reviewed & tested by the community » Needs review

First of all, I apologize for getting the @return comment wrong in #3216341: Provide a module-specific permissions form.

It looks as though this will be the first use of @phpstan-type (and @phpstan-import-type) in Drupal core, unless some other pending MR gets merged first. That is a good thing! It also means that we should give some thought to coding standards for these constructs. We do not have to spell out the standards in this issue, but we should set a good example.

The MR adds @phpstan-type and @phpstan-import-type in the main doc blocks for the interface/class. That seems like a good place for it. Are there any other reasonable options? We might define/import the type definition closer to where it is used, but that can get messy as functions are added or removed, since more than one function can use the same type.

I made a couple of suggestions on the MR, adding line breaks to keep the lines short. I think the multi-line versions are more readable. I also added a space before the opening { and a trailing comma before the closing }. Back to NR to consider those suggestions.

My only other question is whether it is helpful to define PermissionInfoList instead of using array<string, PermissionInfo> directly. Adding a level of indirection is not always the right thing to do.

benjifisher’s picture

smustgrave’s picture

Thank you for sharing that @benjifisher @prudloff what do you think about the suggestions? Definitely a fan of the 2nd one as it makes it easier to read.

smustgrave’s picture

@benjifisher is the first suggestion because * @phpstan-import-type PermissionInfoList from \Drupal\user\PermissionHandlerInterface is over 80 characters?

benjifisher’s picture

is the first suggestion because ... is over 80 characters?

Yes.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems both suggestions were accepted yay! Going to mark thanks all!

benjifisher’s picture

+1 for RTBC

longwave’s picture

Version: main » 11.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 4385ef7c598 to main and f155b8c6855 to 11.x and 0883f86a720 to 11.4.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 0883f86a on 11.4.x
    docs: #3549362 Wrong return type in UserPermissionsForm::...

  • longwave committed f155b8c6 on 11.x
    docs: #3549362 Wrong return type in UserPermissionsForm::...

  • longwave committed 4385ef7c on main
    docs: #3549362 Wrong return type in UserPermissionsForm::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.