-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with special characters in constant/enum-case names
- Loading branch information
Showing
7 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Renderer/resources/PhpEnumTest.testCaseWithSpecialCharacters.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php declare(strict_types=1); | ||
|
||
final class Test | ||
{ | ||
public const _2m = '2m'; | ||
public const _s_2m = '>2m'; | ||
|
||
|
||
private function __construct( | ||
public string $value, | ||
) {} | ||
|
||
public static function from(string $value): self | ||
{ | ||
$self = self::tryFrom($value); | ||
if ($self) { | ||
return $self; | ||
} | ||
throw new \ValueError('Enum not found: ' . $value); | ||
} | ||
|
||
public static function tryFrom(string $value): ?self | ||
{ | ||
if ($value === self::_2m) { | ||
return new self($value); | ||
} | ||
if ($value === self::_s_2m) { | ||
return new self($value); | ||
} | ||
return null; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return (string)$this->value; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Renderer/resources/PhpEnumTest.testCaseWithSpecialCharactersNative.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php declare(strict_types=1); | ||
|
||
enum Test: string | ||
{ | ||
case _2m = '2m'; | ||
case _s_2m = '>2m'; | ||
} |