File tree Expand file tree Collapse file tree 2 files changed +5
-1
lines changed
Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,9 @@ final public static function create(int $id): self
124124 */
125125 final public static function from (string $ property , $ value ): self
126126 {
127- return static ::create (array_flip (self ::getReflectionProperty ($ property )->getValue ())[$ value ]);
127+ $ id = 'id ' === $ property ? $ value : array_flip (self ::getReflectionProperty ($ property )->getValue ())[$ value ];
128+
129+ return static ::create ($ id );
128130 }
129131
130132 final public function getId (): int
Original file line number Diff line number Diff line change @@ -102,6 +102,8 @@ public function testFrom(): void
102102 {
103103 self ::assertSame ('yo ' , TestEnum::fromName ('yo ' )->getName ());
104104 self ::assertSame ('yo ' , TestEnum::from ('name ' , 'yo ' )->getName ());
105+
106+ self ::assertSame (TestEnum::one (), TestEnum::from ('id ' , 1 ));
105107 }
106108
107109 public function testUndefinedMethod (): void
You can’t perform that action at this time.
0 commit comments