Skip to content

Commit

Permalink
Merge pull request #71 from osavchenko/allow_null_in_equals
Browse files Browse the repository at this point in the history
allow null in equals
  • Loading branch information
mnapoli authored May 9, 2018
2 parents ca4a819 + 0f87634 commit 8c5649e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function __toString()
*
* @return bool True if Enums are equal, false if not equal
*/
final public function equals(Enum $enum)
final public function equals(Enum $enum = null)
{
return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
return $enum !== null && $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function testEquals()
$this->assertTrue($foo->equals($foo));
$this->assertFalse($foo->equals($number));
$this->assertTrue($foo->equals($anotherFoo));
$this->assertFalse($foo->equals(null));
}

/**
Expand Down

0 comments on commit 8c5649e

Please sign in to comment.