Problem/Motivation
DebugClassLoader reports methods that lack a native return type. For example:
Method "Drupal\Core\Form\FormInterface::buildForm()" might add "array" as a native return type declaration in the future. Do the same in implementation "Drupal\simple_oauth\Form\OpenIdConnectSettingsForm" now to avoid errors or add an explicit @return annotation to suppress this message.
On Drupal 11.4, it flags UserIdentityProvider::getUserEntityByIdentifier() and two jsonSerialize() methods. On Drupal 12, it flags 170 methods in 33 classes. TokenAuthUser has 102 of them. These deprecations fail the "phpunit (next major)" job in #3603030: Automated Drupal 12 compatibility fixes for simple_oauth 6.1.x-dev.
Steps to reproduce
Run the "phpunit (next major)" CI job.
Proposed resolution
Add accurate @return annotations to flagged methods in classes that are public API in 6.1.x. This removes the class-loader warnings without changing method signatures.
Add native return types to SimpleOauthAuthenticationProvider, OpenIdConnectSettingsForm and DisallowSimpleOauthRequests. These classes are marked @internal.
TokenAuthUser is also @internal, but it gets @return annotations. Most of its methods return the value from the decorated User. Fluent methods such as addRole() return the decorated User, not the TokenAuthUser. A native static type on those methods throws a TypeError.
Five warnings come from core traits: RedundantEditableConfigNamesTrait::getEditableConfigNames() and the CacheableDependencyTrait methods on ScopeEntity. Drupal 12 does not change these traits. Core ignores the same warnings for its own classes. Suppress these five warnings using two narrowly scoped patterns in a project .deprecation-ignore.txt. Set DRUPAL_DEPRECATION_FILTER_CONFIG in .gitlab-ci.yml so PHPUnit uses that file on Drupal 11.5 and later.
Add native return types to the other classes in the next major version.
Test-only MR !250 applies this branch on top of #3603030: Automated Drupal 12 compatibility fixes for simple_oauth 6.1.x-dev. Its "phpunit (next major)" job reports no return type deprecations from simple_oauth classes.
Remaining tasks
- Review the MR.
- Coordinate
TokenAuthUserchanges with #3507076: Decoupled TokenUserInterface from Oauth2TokenInterface. - Open a follow-up for native return types in the next major version.
- Remove the
.deprecation-ignore.txtentries when core adds return types to the traits.
User interface changes
None.
API changes
No public API signature changes in 6.1.x. Native return declarations are added only to internal classes. DebugClassLoader can warn subclasses that override these methods without a return type. Its vendor-prefix and version checks decide when it does.
Data model changes
None.
Issue fork simple_oauth-3611031
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
Comment #3
vidit.anjaria commentedComment #4
pfrillingAssigning myself to work on in Sprint20
Comment #5
pfrillingI rebased onto 6.1.x and fixed the linting errors to get the pipeline green.
Comment #6
vidit.anjaria commentedComment #7
pfrillingMoving to needs work and will look into fixing all return type deprecations from https://www.drupal.org/project/simple_oauth/issues/3603030#comment-16833189
Comment #9
pfrillingI opened draft MR !250 to test this on Drupal 12. It stacks this branch on top of the #3603030: Automated Drupal 12 compatibility fixes for simple_oauth 6.1.x-dev branch, so it picks up the consumers patch and the attribute discovery fixes. It is test only and should not be merged.
Results from the "phpunit (next major)" job:
Five of the 170 come from the core traits
RedundantEditableConfigNamesTraitandCacheableDependencyTrait. Core ignores the same messages for its own classes, so I added them to a project.deprecation-ignore.txt. On Drupal 11.5 and later, PHPUnit only reads that file whenDRUPAL_DEPRECATION_FILTER_CONFIGpoints at it, so I set it in.gitlab-ci.yml. Without it, those five remain.The job still fails on deprecations that are out of scope here: consumers' own return types, annotation-based plugin discovery and procedural hooks. The last two are the follow-ups proposed in #3603030: Automated Drupal 12 compatibility fixes for simple_oauth 6.1.x-dev.
I also updated the issue summary.
Drafted with help from an LLM