Repository navigation
Account for optional keys in get_flag_value() return type - #368
Conversation
When `$assoc_args` is an array shape and the flag is an optional key, the default is returned if the key is missing. Likewise, since get_flag_value() uses isset(), a nullable value also falls back to the default. Include the default type in both cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HsH4o5pKmm1Qd5cqwAm7vB
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe return type extension now accounts for optional keys in constant arrays. Tests cover optional and nullable values, required values, and calls with and without defaults. ChangesFlag value inference
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change addresses optional and nullable flag-value inference. The PR reports passing checks on PHPStan 2.3.0, while compatibility with the also-allowed 2.2.14 remains unconfirmed; no concrete failure is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
When
$assoc_argsis an array shape,GetFlagValueFunctionDynamicReturnTypeExtensionreturned the key's value type even if the key is optional, dropping the default. For example, with$link_typewas inferred as'json'|'xml'instead of'json'|'xml'|null, sonull !== $link_typechecks get reported as always true. This currently breaks PHPStan on wp-cli/embed-commandmain(run).Changes:
get_flag_value()usesisset(), a nullable value also falls back to the default, sonullis removed from the value type and the default added.tests/data/get_flag_value.phpcovering optional keys, an explicit default, and a nullable value; they fail without the fix.Verified locally with PHPStan 2.3.0:
composer phpunit -- --filter TestDynamicReturnTypeExtension,composer phpstan,composer phpcsandcomposer lintall pass. embed-commandmainanalyses cleanly with this extension.🤖 Generated with Claude Code
https://claude.ai/code/session_01HsH4o5pKmm1Qd5cqwAm7vB
Generated by Claude Code
Summary by CodeRabbit