Add type declaration to untyped scalar params on interfaces

Created on 27 March 2024, 2 months ago
Updated 3 April 2024, about 2 months ago

Problem/Motivation

According to #3050720-46: [Meta] Implement strict typing in existing code β†’ we can safely add missing param types to interfaces.

Steps to reproduce

N/A

Proposed resolution

Use rector to add scalar types to untyped params based on their phpdoc @param type. We can address non-scalar params separately.

See AddParamTypeFromPhpDocRector based on existing MixedTypeRector.

Also see rector.php config.

Remaining tasks

  • Fix issues
  • Contribute the rector rule(s)
  • ???
  • Profit

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mstrelan
  • Merge request !7202Add string type to untyped string params β†’ (Open) created by mstrelan
  • Pipeline finished with Canceled
    2 months ago
    Total: 42s
    #130172
  • πŸ‡¦πŸ‡ΊAustralia mstrelan
  • Pipeline finished with Failed
    2 months ago
    Total: 288s
    #130175
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    we can safely add missing param types to classes and interfaces.

    If I'm understanding the comment properly, it's safe with regards to sub classing, but any calling code could throw an exception, right?

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    If I'm understanding the comment properly, it's safe with regards to sub classing, but any calling code could throw an exception, right?

    I think you're right, so in that case we'd want to limit this to interfaces only.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Added another MR that applies only to interfaces and converts all scalar param types based on their phpdoc. Rescoping issue.

  • Pipeline finished with Failed
    2 months ago
    #130198
  • Pipeline finished with Failed
    2 months ago
    Total: 632s
    #130215
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    mstrelan β†’ changed the visibility of the branch 3436327-string-type-rector to hidden.

  • Status changed to Needs work 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Not too many failures, mostly due to mocking things. Probably a lot of these params need to be nullable.

  • First commit to issue fork.
  • Pipeline finished with Canceled
    2 months ago
    Total: 462s
    #130585
  • Pipeline finished with Failed
    2 months ago
    Total: 466s
    #130599
  • Pipeline finished with Failed
    2 months ago
    #130611
  • Pipeline finished with Failed
    2 months ago
    Total: 610s
    #130637
  • Pipeline finished with Success
    2 months ago
    #130649
  • Status changed to Needs review 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Fixed the broken tests, and everything is clear...I think this is ready for review!

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    Great stuff! I think we need to remove the rector bits from the MR before it's ready to commit, but they are worth keeping around until then.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Wow! 🀩 Super impressive. Lots of changes to review tho. Would it be helpful to break this down into bite-sized chunks?

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I did an IRL test with redirect.module looking at \Drupal\Core\Plugin\ContainerFactoryPluginInterface::create which we added the string type declaration to the $plugin_id param. The implementation \Drupal\redirect\Plugin\Action\DeleteRedirect::create does not have param types but I was able to delete a redirect with bulk actions. I then added static return type to the function on the interface and got a fatal error. Removed the return type and added it to the concrete class and it worked fine.

    I also had a play with expanding this to included non-scalar types, union types and nullable types but ran in to a number of issues. For example arrays would always be represented with generics syntax. Objects would not add namespaces correctly so I skipped them. Union types had the same issues, although I was somewhat able to get them working for scalar types. Finally nullable types worked ok except they were represented as a union type instead of the usual nullable syntax we use.

    Would it be helpful to break this down into bite-sized chunks?

    Happy to split it in to something that's logical if we think that's going to be useful, although @catch mentioned in #3050720-47 that one big issue might be ok. So if there are any suggestion for how this should be split let me know and I'll see what I can do.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I think if there are tricky/non-scriptable things we should split them off, but for anything scriptable and straightforward it's probably OK to do one big bang here. However, I have not actually tried to review the MR yet!

  • Status changed to Needs work about 2 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024