Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 7 additions & 2 deletions src/Generator/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 7 additions & 5 deletions src/Generator/MutatorAccessorClassGeneratorAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion template/README.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down