Skip to content

fix(php): make generated docs examples parse - #2054

Merged
abnegate merged 2 commits into
mainfrom
fix/php-example-terminate-client
Oct 15, 2026
Merged

abnegate merged 2 commits into
mainfrom
fix/php-example-terminate-client

Conversation

@abnegate

@abnegate abnegate commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

What

Generated PHP docs examples that failed to parse:

  1. Unterminated client chain. The template only put the ; on the last auth setter. Operations with no security schemes got ->setEndpoint(...) with no terminator, so the $service = new Service($client); line after it was a parse error. This hit every example in appwrite-labs/sdk-for-manager, because that spec declares no per-operation security (Hansi caught it on appwrite-labs/sdk-for-manager#47). The template now puts the terminator on setEndpoint() when there are no setters. It also drops the if [(x)]|length > 0 / for node in [(x)] wrapper, which was always true and only ever looped once.
  2. Object arrays rendered as JSON. PHP::getParamExample() pasted string array examples verbatim, so [{"$id":"one",...}] landed in PHP source. It now JSON-decodes them through jsonToAssoc(), matching what the TYPE_OBJECT branch already did.
  3. .phpunit.cache/ in the generated .gitignore. The generated phpunit.xml sets cacheDirectory=".phpunit.cache", but the cache was never ignored.
  4. jsonToAssoc() hardening. Lists now render without '0' => keys, and quotes and backslashes in strings and keys are escaped.

Test

GenerationTest::testPhpExamplesParse runs php -l on the code block of every generated PHP example, for client, server and console. Before the fix it failed on 25 examples, and after on 0.

Verified

  • GenerationTest passes except testAmbiguousConditionalResponsesFailGeneration and testUnsupportedTypedConditionsFailRatherThanStringify. Those two error identically on unmodified main on my machine: they run in separate processes, and my local php.ini has a broken yaml.so entry whose startup warning breaks them. CI is the authority for those two.
  • phpcs, rector --dry-run and djlint pass on the changed files.

Not verified

  • PHP e2e (PHP85Test) locally: CI runs it. Example output changes only under docs/examples, so SDK runtime behaviour shouldn't move.

🤖 Generated with Claude Code

abnegate and others added 2 commits October 15, 2026 16:53
Examples for operations without auth setters never terminated the
client chain, so the next statement was a parse error. This hit every
example in sdk-for-manager, whose spec declares no per-operation
security. Object array examples given as JSON strings were also pasted
in verbatim as JSON, and string values were not escaped.

The test lints every generated PHP example so either class of break
fails generation tests instead of shipping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generated phpunit.xml sets cacheDirectory to .phpunit.cache, but
the generated .gitignore did not ignore it, so running the tests left
it untracked and regeneration dropped any hand-added ignore rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hansi-codes

hansi-codes Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change correctly excludes PHPUnit's configured cache directory and introduces no merge blocker.

The PHP generator now emits parseable documentation examples for operations with and without security setters, and converts JSON array examples into escaped PHP array literals. Generation tests lint example code blocks across client, server, and console platforms, and generated PHP SDKs now ignore PHPUnit's cache directory.

Latest changes: The newest commit adds .phpunit.cache/ to the generated PHP SDK's .gitignore.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/SDK/Language/PHP.php Converts string-form JSON array examples into PHP literals and renders lists and escaped strings and keys.
templates/php/docs/example.md.twig Simplifies security-scheme iteration and ensures client setup is terminated when there are no security setters.
tests/generation/GenerationTest.php Lints generated PHP documentation example code blocks across platforms.
templates/php/.gitignore Ignores the generated PHPUnit cache directory.

Reviewed the commits since 012458b · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate merged commit 11d207c into main Oct 15, 2026
61 checks passed
@abnegate
abnegate deleted the fix/php-example-terminate-client branch October 15, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant