Skip to content

allow null in equals #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2018
Merged

allow null in equals #71

merged 1 commit into from
May 9, 2018

Conversation

osavchenko
Copy link
Contributor

No description provided.

@mnapoli
Copy link
Member

mnapoli commented May 8, 2018

Thank you for the PR, I'm not sure how I feel about that. If we go that route then why not accept anything in equals() then? But it feels doing it "just because we can", which isn't a good reason to add features.

@osavchenko
Copy link
Contributor Author

For example, I have such method in my entity:

public function setType(DocumentType $type)
{
     $this->type = $type;
}

public function isPdf()
{
    return  DocumentType::PDF()->equals($this->getType());
}

But I can't set some initial value and when my entity is new and without value for $type - I get en error. So, I suggest to update this check.
Yes, I can write code like this:

public function isPdf()
{
    return  DocumentType::PDF() == $this->getType();
}

But here we have no strict check.

src/Enum.php Outdated
@@ -78,11 +78,12 @@ public function __toString()
*
* This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
*
* @param Enum|null $enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant with the code, could you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed

@mnapoli
Copy link
Member

mnapoli commented May 8, 2018

OK after thinking about it it's really a small thing and could improve DX so why not.

I've added a comment, once fixed I can merge.

Thanks.

@mnapoli
Copy link
Member

mnapoli commented May 9, 2018

Thanks!

@mnapoli mnapoli merged commit 8c5649e into myclabs:master May 9, 2018
@osavchenko osavchenko deleted the allow_null_in_equals branch May 9, 2018 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants