From 0f8763429fc07dec6448c3d751be753dd601689d Mon Sep 17 00:00:00 2001 From: Oleksandr Savchenko Date: Tue, 8 May 2018 10:33:48 +0300 Subject: [PATCH] allow null in equals --- src/Enum.php | 4 ++-- tests/EnumTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Enum.php b/src/Enum.php index 5f4a12a..f3aa212 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -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); } /** diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 4b28038..ffb6583 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -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)); } /**