File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,17 @@ public static function search($value)
165165 return array_search ($ value , static ::toArray (), true );
166166 }
167167
168+ /**
169+ * Returns the key's value
170+ *
171+ * @param $key
172+ * @return mixed
173+ */
174+ public static function findValue ($ key )
175+ {
176+ return static ::toArray ()[$ key ] ?? null ;
177+ }
178+
168179 /**
169180 * Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
170181 *
Original file line number Diff line number Diff line change @@ -189,6 +189,18 @@ public function testIsValidKey()
189189 $ this ->assertFalse (EnumFixture::isValidKey ('BAZ ' ));
190190 }
191191
192+ /**
193+ * findValue($key)
194+ */
195+ public function testFindValue ()
196+ {
197+ $ enums = EnumFixture::toArray ();
198+
199+ foreach ($ enums as $ key => $ value ) {
200+ $ this ->assertEquals ($ value , EnumFixture::findValue ($ key ));
201+ }
202+ }
203+
192204 /**
193205 * search()
194206 * @see https://github.com/myclabs/php-enum/issues/13
You can’t perform that action at this time.
0 commit comments