diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a35432..238a008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [11.1.2] - 2025.10.28 +### Fixed +- Enum with invalid PHP constant value +- README.md with multiline description in operations + ## [11.1.1] - 2025.09.23 ### Fixed - Acessing nullable enum with `?->value` instead of `->value?->value` diff --git a/src/Generator/EnumGenerator.php b/src/Generator/EnumGenerator.php index 8521e0d..373f62a 100644 --- a/src/Generator/EnumGenerator.php +++ b/src/Generator/EnumGenerator.php @@ -16,7 +16,7 @@ class EnumGenerator extends MutatorAccessorClassGeneratorAbstract public static function getCaseName(string $value): string { - $sanitized = preg_replace('[^A-Z0-9_]', '', strtoupper(str_replace([' ', '-', '/', '.'], '_', $value))); + $sanitized = preg_replace('/[^A-Z0-9_]/', '', strtoupper(str_replace([' ', '-', '/', '.'], '_', $value))); if (is_numeric($sanitized)) { return 'V_' . $sanitized; @@ -76,9 +76,14 @@ private function generateEnumConsts(Field $root): array $statements = []; foreach ($root->getEnumValues() as $value) { + $caseName = self::getCaseName((string)$value); + if (empty($caseName)) { + continue; + } + $statements[] = $this ->builder - ->enumCase(self::getCaseName((string)$value)) + ->enumCase($caseName) ->setValue($value); } diff --git a/src/Generator/MutatorAccessorClassGeneratorAbstract.php b/src/Generator/MutatorAccessorClassGeneratorAbstract.php index 864decf..7547460 100644 --- a/src/Generator/MutatorAccessorClassGeneratorAbstract.php +++ b/src/Generator/MutatorAccessorClassGeneratorAbstract.php @@ -117,11 +117,13 @@ protected function generateEnumStatements(Field $field): array if (!empty($enumValues)) { foreach ($enumValues as $enumValue) { if (is_string($enumValue)) { - $constName = SchemaNaming::getEnumConstName($field, $enumValue); - $statements[] = $this->builder->constant( - $constName, - $this->builder->val($enumValue) - ); + $constName = SchemaNaming::getEnumConstName($field, $enumValue); + if (preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $constName)) { + $statements[] = $this->builder->constant( + $constName, + $this->builder->val($enumValue) + ); + } } } } diff --git a/template/README.md.twig b/template/README.md.twig index eac3490..f2c9f2b 100644 --- a/template/README.md.twig +++ b/template/README.md.twig @@ -44,7 +44,7 @@ $result = $client->{{ exampleOperation.name }}($request); ### {{ tag }} Endpoints: {% for operation in operations %} -- **{{ operation.name }}**{% if operation.description is not empty %} - {{ operation.description }}{% endif %} +- **{{ operation.name }}**{% if operation.description is not empty %} - {{ operation.description | trim | split('\n') | first }}{% endif %} {% endfor %}