Repository: BenSampo/laravel-enum (php)

Issue:
Incorrect description out when uppercase key with numeric suffix
I've noticed an issue when my keys are in the following format, the generated description has a space between every character


```php
class MyEnum extends Enum {
    public const SOME_INTERESTING_KEY_1 = 10;
    public const SOME_INTERESTING_KEY_2 = 20;
}
```

```php
echo MyEnum::getDescription(20); 
```

The output is `S o m e  i n t e r e s t i n g  k e y 2`

Pull request:
Fixing issue for descriptions with uppercase keys and numeric suffix
- [x] Added or updated tests
- [ ] Added or updated the [README.md](../README.md)
- [x] Detailed changes in the [CHANGELOG.md](../CHANGELOG.md) unreleased section

**Related Issue/Intent**

Resolves #209

**Changes**

There is a check in the `getFriendlyKeyName` function which determines if a key is all uppercase, however this doesn't work if the key contains non-alpha characters so I've updated it to work in that scenario and added the additional test cases


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 751f517..d91eda3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,14 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-
 - Update doctrine/dbal requirement from ^2.9 to ^2.9|^3.0 [#208](https://github.com/BenSampo/laravel-enum/pull/208)
 - Allow passing iterables to Enum::in() [#212](https://github.com/BenSampo/laravel-enum/pull/212)
 
 ### Fixed
 
 - fix: `$model->getChanges()` triggered due to strict comparison [#187](https://github.com/BenSampo/laravel-enum/pull/187)
-
+- Fixed issue in `getFriendlyKeyName`when uppercase key contains non-alpha characters [#210](https://github.com/BenSampo/laravel-enum/pull/210)
 
 ## [3.2.0](https://github.com/BenSampo/laravel-enum/compare/v3.1.0...v3.2.0) - 2020-12-15
 
diff --git a/src/Enum.php b/src/Enum.php
index d792117..58f8162 100644
--- a/src/Enum.php
+++ b/src/Enum.php
@@ -443,7 +443,7 @@ abstract class Enum implements EnumContract, Castable, Arrayable, JsonSerializab
      */
     protected static function getFriendlyKeyName(string $key): string
     {
-        if (ctype_upper(str_replace('_', '', $key))) {
+        if (ctype_upper(preg_replace('/[^a-zA-Z]/', '', $key))) {
             $key = strtolower($key);
         }
 


Test patch:
diff --git a/tests/EnumTest.php b/tests/EnumTest.php
index 31d6ef0..761cc65 100644
--- a/tests/EnumTest.php
+++ b/tests/EnumTest.php
@@ -76,6 +76,8 @@ class EnumTest extends TestCase
         $this->assertSame('Uppercase', MixedKeyFormats::getDescription(MixedKeyFormats::UPPERCASE));
         $this->assertSame('Uppercase snake case', MixedKeyFormats::getDescription(MixedKeyFormats::UPPERCASE_SNAKE_CASE));
         $this->assertSame('Lowercase snake case', MixedKeyFormats::getDescription(MixedKeyFormats::lowercase_snake_case));
+        $this->assertSame('Uppercase snake case numeric suffix 2', MixedKeyFormats::getDescription(MixedKeyFormats::UPPERCASE_SNAKE_CASE_NUMERIC_SUFFIX_2));
+        $this->assertSame('Lowercase snake case numeric suffix 2', MixedKeyFormats::getDescription(MixedKeyFormats::lowercase_snake_case_numeric_suffix_2));
     }
 
     public function test_enum_get_random_key()
diff --git a/tests/Enums/MixedKeyFormats.php b/tests/Enums/MixedKeyFormats.php
index dd55c1f..fc9f9db 100644
--- a/tests/Enums/MixedKeyFormats.php
+++ b/tests/Enums/MixedKeyFormats.php
@@ -11,4 +11,6 @@ final class MixedKeyFormats extends Enum
     const UPPERCASE = 3;
     const UPPERCASE_SNAKE_CASE = 4;
     const lowercase_snake_case = 5;
+    const UPPERCASE_SNAKE_CASE_NUMERIC_SUFFIX_2 = 6;
+    const lowercase_snake_case_numeric_suffix_2 = 7;
 }