File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -80,15 +80,18 @@ public function __toString()
8080 }
8181
8282 /**
83- * Compares one Enum with another.
83+ * Determines if Enum should be considered equal with the variable passed as a parameter.
84+ * Returns false if an argument is an object of different class or not an object.
8485 *
8586 * This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
8687 *
87- * @return bool True if Enums are equal, false if not equal
88+ * @return bool
8889 */
89- final public function equals (Enum $ enum = null )
90+ final public function equals ($ variable = null )
9091 {
91- return $ enum !== null && $ this ->getValue () === $ enum ->getValue () && \get_called_class () === \get_class ($ enum );
92+ return $ variable instanceof self
93+ && $ this ->getValue () === $ variable ->getValue ()
94+ && \get_called_class () === \get_class ($ variable );
9295 }
9396
9497 /**
Original file line number Diff line number Diff line change @@ -224,11 +224,15 @@ public function testEquals()
224224 $ foo = new EnumFixture (EnumFixture::FOO );
225225 $ number = new EnumFixture (EnumFixture::NUMBER );
226226 $ anotherFoo = new EnumFixture (EnumFixture::FOO );
227+ $ objectOfDifferentClass = new \stdClass ();
228+ $ notAnObject = 'foo ' ;
227229
228230 $ this ->assertTrue ($ foo ->equals ($ foo ));
229231 $ this ->assertFalse ($ foo ->equals ($ number ));
230232 $ this ->assertTrue ($ foo ->equals ($ anotherFoo ));
231233 $ this ->assertFalse ($ foo ->equals (null ));
234+ $ this ->assertFalse ($ foo ->equals ($ objectOfDifferentClass ));
235+ $ this ->assertFalse ($ foo ->equals ($ notAnObject ));
232236 }
233237
234238 /**
You can’t perform that action at this time.
0 commit comments