Problem/Motivation

  /**
   * The current user logged in using the Mink controlled browser.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $loggedInUser = FALSE;

According to the PHPDoc this variable should never be set to FALSE.

Steps to reproduce

Proposed resolution

Update the doc block only

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3555621

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

chi created an issue. See original summary.

srushti_k’s picture

Hi — I’m Srushti Kondhalkar (new to Drupal contributions).

I looked at this issue; the PHPDoc says @var \Drupal\user\UserInterface, but the property is initialized as FALSE.
I plan to reproduce and prepare a patch that changes the initial value to NULL so that the type matches.

Could someone please confirm if this approach is acceptable, or point me to the exact file path to update?

Thanks — I’ll follow up with a branch/merge request once I have the code.
— Srushti (srushti_k)

chi’s picture

The fix should just extend the declared type in PHPDoc block

@var \Drupal\user\UserInterface|false

I think adding the native typehint here is out of scope for this issue.

longwave’s picture

Would it be better to use null instead of false? There might be some BC concerns doing that though.

chi’s picture

Re: #4. It certainly would. And yes, there might be BC break if someone checks the property with strict comparison operator.

aryan singh made their first commit to this issue’s fork.

aryan singh’s picture

Status: Active » Needs review
longwave’s picture

Discussed briefly with @mondrake, I think it would be much better if we used typed properties:

  /**
   * The current user logged in using the Mink controlled browser.
   */
  protected UserInterface|false $loggedInUser = FALSE;

or even better if we could use

  /**
   * The current user logged in using the Mink controlled browser.
   */
  protected ?UserInterface $loggedInUser;
chi’s picture

Then, why not add typehints to other trait properties and methods?

longwave’s picture

Well, exactly - that's probably worth doing in bulk in a followup.

smustgrave’s picture

Version: 11.3.x-dev » 11.x-dev
Status: Needs review » Needs work

For #9

longwave’s picture

Status: Needs work » Needs review

As discussed in #10/11 not sure we should do that here, maybe let's just fix up the docs and then bulk-fix the properties later.

mondrake’s picture

Not sure it's worth changing this isolated case here.

My suggestion would be to do, for core/tests:

chi’s picture

Status: Needs review » Reviewed & tested by the community

Agree with #13. Here we just fix the bug in Docblock.

Changing native typehints is out of scope for this issue.

The MR looks right to me. Test failure seems unrelated.

mstrelan’s picture

NULL would indeed be better. For example, in \Drupal\Tests\system\FunctionalJavascript\OffCanvasTestBase::assertPageLoadComplete, we could update $this->loggedInUser && $this->loggedInUser->hasPermission() to just $this->loggedInUser?->hasPermission().

Core doesn't seem to have any cases where we are checking if the property is FALSE, only the loose empty check, but of course contrib would be the issue. I guess the same way would be to deprecate the $loggedInUser property and make a new $authenticatedUser property.

quietone’s picture

Issue summary: View changes

This search reports 22 pages for this->loggedInUser. Some of those are on 7.x branches and I don't see a way to exclude those from the search. So, not really all that helpful.

longwave’s picture

Version: 11.x-dev » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 10.6.x as a documentation fix.

Committed and pushed 422ac9c2aa6 to 11.x and ac5feee6fc6 to 11.3.x and 74bda5e0635 to 10.6.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 74bda5e0 on 10.6.x
    docs: #3555621 Wrong type for \Drupal\Tests\UiHelperTrait::$loggedInUser...

  • longwave committed ac5feee6 on 11.3.x
    docs: #3555621 Wrong type for \Drupal\Tests\UiHelperTrait::$loggedInUser...

  • longwave committed 422ac9c2 on 11.x
    docs: #3555621 Wrong type for \Drupal\Tests\UiHelperTrait::$loggedInUser...

Status: Fixed » Closed (fixed)

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