diff --git a/composer.json b/composer.json index 545f1db..c9f05e0 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "symfony/config": "^6.0", "symplify/autowire-array-parameter": "^11.0", "symplify/package-builder": "^11.0", - "thecodingmachine/safe": "^2.2" + "thecodingmachine/safe": "^2.2", + "jawira/case-converter": "^3.5" }, "require-dev": { "pestphp/pest": "^1.21", diff --git a/src/Fixes/UpperSnakeCaseNameFixer.php b/src/Fixes/UpperSnakeCaseNameFixer.php index 9636cac..2c24a48 100644 --- a/src/Fixes/UpperSnakeCaseNameFixer.php +++ b/src/Fixes/UpperSnakeCaseNameFixer.php @@ -5,7 +5,7 @@ namespace Worksome\Graphlint\Fixes; use GraphQL\Language\AST\NameNode; -use Illuminate\Support\Str; +use Jawira\CaseConverter\Convert; use Worksome\Graphlint\ProblemDescriptor; use Worksome\Graphlint\Utils\NodeNameResolver; @@ -30,12 +30,6 @@ public function fix(ProblemDescriptor $problemDescriptor): void return; } - $upperCase = Str::of($name) - ->replace('_', ' ') - ->title() - ->snake() - ->upper(); - - $node->value = $upperCase->__toString(); + $node->value = (new Convert($name))->toMacro(); } } diff --git a/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php b/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php index b55dc71..617a306 100644 --- a/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php +++ b/src/Inspections/UpperSnakeCaseEnumCaseDefinitionInspection.php @@ -5,7 +5,7 @@ namespace Worksome\Graphlint\Inspections; use GraphQL\Language\AST\EnumValueDefinitionNode; -use Illuminate\Support\Str; +use Jawira\CaseConverter\Convert; use Worksome\Graphlint\Fixes\UpperSnakeCaseNameFixer; use Worksome\Graphlint\InspectionDescription; use Worksome\Graphlint\ProblemsHolder; @@ -35,7 +35,7 @@ public function visitEnumValueDefinition( return; } - $upperCase = Str::of($name)->replace('_', ' ')->title()->snake()->upper()->__toString(); + $upperCase = (new Convert($name))->toMacro(); if ($name === $upperCase) { return; diff --git a/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/camel_case_multi_word_enum_case.graphql.inc b/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/camel_case_multi_word_enum_case.graphql.inc new file mode 100644 index 0000000..59eb420 --- /dev/null +++ b/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/camel_case_multi_word_enum_case.graphql.inc @@ -0,0 +1,7 @@ +enum Status { + inProgress +} +----- +enum Status { + IN_PROGRESS +} diff --git a/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/pascal_case_multi_word_enum_case.graphql.inc b/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/pascal_case_multi_word_enum_case.graphql.inc new file mode 100644 index 0000000..dae7129 --- /dev/null +++ b/test-resources/Inspections/UpperSnakeCaseEnumCaseDefinitionInspectionTest/pascal_case_multi_word_enum_case.graphql.inc @@ -0,0 +1,7 @@ +enum Status { + InProgress +} +----- +enum Status { + IN_PROGRESS +}