Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Description

Refs https://github.com/fern-demo/payroc-php-sdk/pull/4

Fixes a bug in the PHP SDK generator where sub-clients were incorrectly receiving $this->options (array) instead of $this->environment (Environments object) as their second constructor parameter in multi-URL environments.

Problem

The original logic was too restrictive when determining what to pass to sub-client constructors:

  • It checked if subpackage.service != null AND if the first endpoint had a baseUrl
  • This caused some sub-clients to receive $this->options when they expected Environments $environment
  • Result: Generated PHP code had type mismatches causing phpstan errors

Changes Made

RootClientGenerator.ts:

  • Simplified logic: When isMultiUrl is true, always pass $this->environment to all sub-clients
  • Removed unnecessary checks for individual endpoint baseUrls

SubPackageClientGenerator.ts:

  • Simplified logic: Use the already-computed hasBaseUrl flag instead of checking each nested subpackage's endpoints
  • When the current client has an environment field (isMultiUrl && hasBaseUrl), pass it to nested sub-clients

Testing

  • Lint checks passed (pnpm run check)
  • IMPORTANT: Seed tests need to be run to verify generated PHP code compiles correctly
  • Manual verification needed: Check that generated PHP SDKs with multi-URL environments now pass type checks

Review Checklist

Critical items to verify:

  1. Logic correctness: Confirm that when a client has an $environment field, it should pass that environment to ALL its sub-clients (not just those with specific endpoint configurations)
  2. Seed tests: Ensure PHP SDK seed tests pass, especially fixtures with multi-URL environments
  3. Generated code: Verify that the generated PHP code matches the pattern shown in the reference PR (all sub-clients receive environment consistently)
  4. Edge cases: Consider scenarios with nested subpackages and mixed endpoint configurations

Context:

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant