File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -80,15 +80,18 @@ public function __toString()
80
80
}
81
81
82
82
/**
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.
84
85
*
85
86
* This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
86
87
*
87
- * @return bool True if Enums are equal, false if not equal
88
+ * @return bool
88
89
*/
89
- final public function equals (Enum $ enum = null )
90
+ final public function equals ($ variable = null )
90
91
{
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 );
92
95
}
93
96
94
97
/**
Original file line number Diff line number Diff line change @@ -224,11 +224,15 @@ public function testEquals()
224
224
$ foo = new EnumFixture (EnumFixture::FOO );
225
225
$ number = new EnumFixture (EnumFixture::NUMBER );
226
226
$ anotherFoo = new EnumFixture (EnumFixture::FOO );
227
+ $ objectOfDifferentClass = new \stdClass ();
228
+ $ notAnObject = 'foo ' ;
227
229
228
230
$ this ->assertTrue ($ foo ->equals ($ foo ));
229
231
$ this ->assertFalse ($ foo ->equals ($ number ));
230
232
$ this ->assertTrue ($ foo ->equals ($ anotherFoo ));
231
233
$ this ->assertFalse ($ foo ->equals (null ));
234
+ $ this ->assertFalse ($ foo ->equals ($ objectOfDifferentClass ));
235
+ $ this ->assertFalse ($ foo ->equals ($ notAnObject ));
232
236
}
233
237
234
238
/**
You can’t perform that action at this time.
0 commit comments