yiisoft / user

Convenient user identity management and access checking.
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
18 stars 8 forks source link

Make GuestIdentity extensible #41

Closed devanych closed 2 years ago

devanych commented 2 years ago
Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues #25

Makes the GuestIdentity NOT final, but the getId() method final. It could be expanded if necessary. I think that in this case extension would be the right solution.

roxblnfk commented 2 years ago

I think that in this case extension would be the right solution

Why not an interface?

devanych commented 2 years ago

Why not an interface?

  1. Because in this case, when expanding, children do not redefine the behavior of the parent in any way, as it should be with proper expansion. And all classes will be implementations of the same IdentityInterface.

  2. If you create the interface GuestIdentityInterface and inherit it from the IdentityInterface, then there is a problem. In IdentityInterface here is such a method:

public function getId(): ?string;

in GuestIdentityInterface we need such a method:

public function getId(): null;

Firstly, the PHP syntax will not allow this to be done, and secondly, making an interface with a single method that should always return null is generally some kind of crazy idea :)

But NOT the final class:

class GuestIdentity implements IdentityInterface
{
    final public function getId(): ?string
    {
        return null;
    }
}

Allows you to completely solve the issue without problems.

roxblnfk commented 2 years ago

@devanych i don't agree with you, but as always, it's too late.

samdark commented 2 years ago

It's never too late :)