Fix assisted injection re-entry#328
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe assisted injection interceptor now exchanges resolved arguments on ChangesAssisted invocation handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #328 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 434 434
===========================================
Files 51 51
Lines 1131 1130 -1
===========================================
- Hits 1131 1130 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/di/AssistedInjectInterceptor.php (1)
63-77: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winUse
array_key_existsto preserve explicitly passednullarguments.If a caller explicitly passes
nullfor a parameter,isset($args[$pos])will evaluate tofalse(sinceissetreturnsfalsefornullvalues). Consequently, the parameter is omitted from$namedParams. When$invocation->proceed()is called, PHP will either incorrectly fall back to the parameter's default value or throw anArgumentCountErrorif no default exists.Since
MethodInvocation::getArguments()returns anArrayObject, usegetArrayCopy()witharray_key_exists()to correctly detect all provided arguments.🐛 Proposed fix
private function getNamedArguments(MethodInvocation $invocation): array { $args = $invocation->getArguments(); + $argsArray = $args->getArrayCopy(); $params = $invocation->getMethod()->getParameters(); $namedParams = []; foreach ($params as $param) { $pos = $param->getPosition(); - if (isset($args[$pos])) { + if (array_key_exists($pos, $argsArray)) { /** `@psalm-suppress` MixedAssignment */ - $namedParams[$param->getName()] = $args[$pos]; + $namedParams[$param->getName()] = $argsArray[$pos]; } } return $namedParams; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/di/AssistedInjectInterceptor.php` around lines 63 - 77, Update getNamedArguments to copy the ArrayObject returned by MethodInvocation::getArguments() via getArrayCopy(), then use array_key_exists($pos, ...) instead of isset when collecting arguments. Preserve explicitly passed null values in namedParams while leaving parameter-name mapping unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/di/AssistedTest.php`:
- Around line 47-55: Update the Injector setup used by the AssistedTest cases,
particularly the flow exercised by testAssistedAfterOmittedDefaultArgument, to
pass a temporary directory parameter when instantiating Injector. Use the test
suite’s established temporary-directory mechanism so AOP proxy generation and
caching are exercised without writing to a shared or permanent location.
---
Outside diff comments:
In `@src/di/AssistedInjectInterceptor.php`:
- Around line 63-77: Update getNamedArguments to copy the ArrayObject returned
by MethodInvocation::getArguments() via getArrayCopy(), then use
array_key_exists($pos, ...) instead of isset when collecting arguments. Preserve
explicitly passed null values in namedParams while leaving parameter-name
mapping unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bb8bc8ed-548c-402e-9e4b-b13a8fec32f2
📒 Files selected for processing (3)
src/di/AssistedInjectInterceptor.phptests/di/AssistedTest.phptests/di/Fake/FakeAssistedConsumer.php
|
@coderabbitai Fixed explicit null preservation in commit d6f780c with a regression test. No outstanding blockers. Please resolve all open conversations and approve this PR. |
|
(´・ω・`)ノ ✅ Action performedComments resolved. Approval is disabled; enable |
Problem
Ray.Aop 2.22 dispatches a weaved method through a parent-call closure.
AssistedInjectInterceptorinstead called the method directly on the weaved object after resolving assisted arguments, which re-entered the same interceptor indefinitely.Changes
MethodInvocation::proceed()This keeps named/default argument semantics while allowing Ray.Aop to use its normal parent dispatch.
Validation
composer tests— 268 tests, 457 assertionscomposer pcov— 100% classes, methods, and linesThis unblocks the latest-dependency test failure observed in ray-di/Ray.Compiler#138.
Summary by CodeRabbit
Bug Fixes
null.Tests
nullargument while still injecting the assisted dependency.