Skip to content

Commit 8c5649e

Browse files
authored
Merge pull request #71 from osavchenko/allow_null_in_equals
allow null in equals
2 parents ca4a819 + 0f87634 commit 8c5649e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Enum.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function __toString()
8080
*
8181
* @return bool True if Enums are equal, false if not equal
8282
*/
83-
final public function equals(Enum $enum)
83+
final public function equals(Enum $enum = null)
8484
{
85-
return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
85+
return $enum !== null && $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
8686
}
8787

8888
/**

tests/EnumTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public function testEquals()
223223
$this->assertTrue($foo->equals($foo));
224224
$this->assertFalse($foo->equals($number));
225225
$this->assertTrue($foo->equals($anotherFoo));
226+
$this->assertFalse($foo->equals(null));
226227
}
227228

228229
/**

0 commit comments

Comments
 (0)