Fix delegate lookup in Container::has#402
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #402 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 184 188 +4
===========================================
Files 11 11
Lines 500 509 +9
===========================================
+ Hits 500 509 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Yiisoft\Di\Container::has() so it respects configured delegate containers (PSR-11 behavior), and adds regression coverage for “delegate-only” entries while avoiding extra overhead when no delegates are configured.
Changes:
- Update
Container::has()to consult delegates (guarded by a newhasDelegatesflag). - Track whether any delegates are configured during
setDelegates(). - Add a unit test ensuring
has()andget()work for entries provided only by a delegate container.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Container.php | Makes has() consult delegate containers and adds a flag to avoid delegate lookup overhead when none are configured. |
| tests/Unit/ContainerTest.php | Adds regression test for delegate-provided entries being discoverable via has(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2942f68 to
2e93548
Compare
b3c4a46 to
8249691
Compare
8249691 to
fa0b795
Compare
vjik
reviewed
Jun 3, 2026
vjik
approved these changes
Jun 5, 2026
samdark
commented
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #401.
Tests
Benchmark note
With xdebug on and opcache off, the guarded fix keeps the no-delegate nonexistent lookup path at baseline: about 401 us for 200 nonexistent IDs versus about 405 us before the change. The unguarded variant measured about 463 us.