We have a problem with SubscriberInterface::getStatus() and setStatus(). They are documented as taking bool, which seems intuitive and sensible because it matches UserInterface::isActive() so you can write code like this from Subscriber::fillFromAccount():

    $this->setStatus($account->isActive());

However there are also constants SubscriberInterface::INACTIVE and ACTIVE and this is what the code uses in the majority of cases - hence there are warnings for code that seems very reasonable.

    $this->assertFalse($subscriber->getStatus());
CommentFileSizeAuthor
#3 simplenews.subs-status.3103733-3.patch4.08 KBadamps

Comments

AdamPS created an issue. See original summary.

adamps’s picture

Issue summary: View changes

There is a potential reason to have an integer status: so that we can extend the field to add a new value, for example, "unconfirmed". However there are two problems with that.

  • BC: lots of existing code assumes there are just two possibilities. True we are alpha and can make non-BC changes but we shouldn't do so without good reasons.
  • If a subscriber is also a user then the subscriber status field is missing from the UI, and synchronised from the user account status, which is a boolean - see Subscriber::fillFromAccount(). This code wouldn't really work if the two fields have different legal values.

Therefore I propose that we stick with the commented interface and make the field a boolean throughout. We have two options for the constants INACTIVE/ACTIVE:

  1. Remove them entirely.
  2. Change the values to TRUE/FALSE and deprecate.

Seeing as we are right now at the perfect time to make non-BC changes, I prefer option 1.

adamps’s picture

StatusFileSize
new4.08 KB

Or we can use bool on the functions but integer internally, which matches User.php and is fully BC. Here's a patch that tries that.

  • AdamPS committed d3bf72e on 8.x-2.x
    Issue #3103733 by AdamPS: Mix up over subscriber status: boolean or 0/1
    
adamps’s picture

Status: Active » Needs review
Issue tags: +Plan to commit

That gets the tests working so I've checked it in. I'm happy to make further changes if anyone has any review comments.

adamps’s picture

Status: Needs review » Fixed
Issue tags: -Plan to commit

Status: Fixed » Closed (fixed)

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