Skip to content

Reject an unbound multibinding target at compile time - #152

Merged
koriym merged 9 commits into
1.xfrom
fix-148
Nov 24, 2026
Merged

koriym merged 9 commits into
1.xfrom
fix-148

Conversation

@koriym

@koriym koriym commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #148

MultiBinder::addBinding()->to(X::class) / ->toProvider(P::class) without binding X / P compiled, then threw Unbound when the Map was read under CompiledInjector. Ray\Di\Injector resolves it only through just-in-time binding, which Ray.Di 2.24 deprecates in favour of an explicit binding (ray-di/Ray.Di#337).

  • compile() now throws Unbound for such a target, so the failure surfaces at build time and a passing compile leaves no JIT dependency.
  • Bind the target explicitly: $this->bind(X::class).
  • The target class is private in Ray.Di's LazyTo / LazyProvider (unchanged from 2.19 to 2.24), so it is read with ReflectionProperty.

Summary by CodeRabbit

  • Bug Fixes
    • Compilation now reports an Unbound error when a multibinding target declared with to() or toProvider() has not been bound. The error identifies the missing target, including when it has only a qualified binding.
  • Documentation
    • Updated the unreleased changelog and error guide to describe this behavior and explain that multibinding targets must have an unnamed binding.

LazyTo and LazyProvider resolve their target through the injector when
the Map is read. Ray\Di\Injector binds a concrete class just in time;
CompiledInjector has no script for it and threw Unbound at runtime.

Compiler now adds an untargeted binding for each LazyTo/LazyProvider
target before building the container, so the target is compiled (and
woven) like any bound class. A target that is already bound is left as
is. The target class is private in Ray.Di, so it is read by reflection.

Fixes #148
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The compiler now checks lazy multibinding targets before compilation proceeds. If a target is not bound by the module, compilation throws Unbound. Tests cover direct, provider, and qualified-only targets. Documentation and Composer constraints describe the binding requirement and package compatibility conflicts.

Changes: Multibinding target validation

Layer / File(s) Summary
Validate lazy multibinding targets
src/Compiler.php
Compiler::compile checks targets from LazyTo and LazyProvider bindings against the module container. It throws Unbound with the target’s --suffixed key when the key is absent.
Cover and document unbound targets
tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php, tests/MultiBindingTest.php, docs/error/Unbound.md, CHANGELOG.md, composer.json
Tests cover direct, provider, and qualified-only targets. Documentation and the changelog describe the compile-time exception and binding requirement. Composer conflict rules specify affected bear/qiq-module and madapaja/twig-module versions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • ray-di/Ray.Compiler#148 — The issue describes runtime Unbound errors for unbound multibinding targets; this change rejects those targets during compilation.
Merge Risk: Minimal · up to cb921

This change makes compile() fail early when a multibinding target is not bound explicitly. It is documented, tested, and guarded by Composer conflicts for the known incompatible package versions. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Reject an unbound multibinding target at compile time" matches the main change. The PR makes compile() throw Unbound when a MultiBinder to() or toProvider() target lacks an explicit binding…
Linked Issues check Passed Issue #148 asks that unbound multibinding targets added with to() / toProvider() stop failing at runtime with Unbound. It offers two outcomes: document explicit binding as the contract, or compile the…
Out of Scope Changes check Passed All changes connect to #148 or to the compatibility conflicts that the PR description explicitly reports. The src/Compiler.php check enforces explicit binding of multibinding targets. The test module …
Full details: Title check

Explanation

The title "Reject an unbound multibinding target at compile time" matches the main change. The PR makes compile() throw Unbound when a MultiBinder to() or toProvider() target lacks an explicit binding, as described in the Compiler.php change, the new tests, and the Unbound.md docs. The title is specific and does not use vague terms.

Full details: Linked Issues check

Explanation

Issue #148 asks that unbound multibinding targets added with to() / toProvider() stop failing at runtime with Unbound. It offers two outcomes: document explicit binding as the contract, or compile the targets. The PR takes the first outcome. The previous review found that src/Compiler.php adds assertMultiBindingTargetsBound(), called from compile(). It reads the private 'class' property of LazyTo / LazyProvider with ReflectionProperty and throws Unbound when no '<target>-' binding exists. A passing compile therefore leaves no just-in-time dependency. CHANGELOG.md and docs/error/Unbound.md document the rule and the required $this->bind(X::class). tests/MultiBindingTest.php covers to() and toProvider() cases, using tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php. The issue notes that rejecting unbound targets affects the BEAR.QiqModule usage. The PR states this trade-off, and the issue does not require preserving that usage. For the incremental change from e1199d4 to cb9215c, the diff of src/Compiler.php returned no content, so the previous conclusion is preserved. The composer.json diff could not be read because blobs are missing from the checkout. This does not affect the core requirement, because composer.json only declares conflicts. The Ray.Di manual is outside this repository and is not covered.

Full details: Out of Scope Changes check

Explanation

All changes connect to #148 or to the compatibility conflicts that the PR description explicitly reports. The src/Compiler.php check enforces explicit binding of multibinding targets. The test module and MultiBindingTest cases exercise that check. The CHANGELOG.md and docs/error/Unbound.md entries document the new compile-time failure. The composer.json conflict constraints for bear/qiq-module and madapaja/twig-module match the PR description. The composer.json diff itself could not be read because blobs are missing from the checkout, so its exact content rests on the raw summary and PR description. No unrelated behavior change appears in the available evidence.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e1199d4 and cb9215c.

Files selected for processing: 5

  • CHANGELOG.md
  • composer.json
  • docs/error/Unbound.md
  • tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php
  • tests/MultiBindingTest.php
Files skipped from review as they are similar to previous changes: 1

  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (946bb52) to head (cb9215c).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #152   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       118       124    +6     
===========================================
  Files             12        12           
  Lines            302       312   +10     
===========================================
+ Hits             302       312   +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ing it

Ray.Di 2.24 deprecates just-in-time binding of an unbound concrete class
and asks for an explicit binding (ray-di/Ray.Di#337), and promises that
a passing compile leaves no JIT dependency. Compiling an unbound
LazyTo/LazyProvider target would accept the deprecated form only under
CompiledInjector. Compiler now throws Unbound for such a target before
compiling, so the failure surfaces at build time.
@koriym koriym changed the title Compile multibinding targets that the module does not bind Reject an unbound multibinding target at compile time Nov 23, 2026
@koriym

koriym commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review — merged 1.x (CHANGELOG conflict) and added a composer conflict with bear/qiq-module 2.1.0–2.1.2 in the merge commit 46dacfc; docs/error/Unbound.md gained a multibinding section in 286c158.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
Analysis chain

Script executed:

#!/bin/bash
for name in CHANGELOG.md Unbound.md composer.json; do
  echo "=== $name ==="
  fd -t f -H -E .git -F "$name" | while IFS= read -r file; do
    case "$file" in
      CHANGELOG.md|docs/error/Unbound.md|composer.json)
        echo "--- $file ---"
        cat -n "$file"
        ;;
    esac
  done
done

Length of output: 15164


@koriym I’ll review the merged CHANGELOG, the Composer conflict for bear/qiq-module 2.1.0–2.1.2, and the new multibinding guidance.

Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym

koriym commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review — cb9215c adds madapaja/twig-module >=2.8.0 <2.8.1 to the composer conflict (2.8.0 adds TwigCompileStep as an unbound multibinding target; fix in madapaja/Madapaja.TwigModule#54) and reworded the CHANGELOG.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
Analysis chain

Script executed:

#!/bin/bash
echo '=== Referenced commit ==='
git show --format=fuller --stat cb9215c -- || true
echo '=== Referenced commit diff ==='
git show --format= --no-ext-diff cb9215c -- CHANGELOG.md composer.json || true
echo '=== Referenced files ==='
for name in CHANGELOG.md composer.json; do
  fd -t f -H -E .git -F "$name" | while IFS= read -r file; do
    case "$file" in
      CHANGELOG.md|composer.json)
        echo "--- $file ---"
        cat -n "$file"
        ;;
    esac
  done
done

Length of output: 13379


@koriym composer.json contains the requested Twig conflict.

In CHANGELOG.md Line 12, the update command does not include madapaja/twig-module. If version 2.8.0 is locked, the command may fail to update ray/compiler. Include madapaja/twig-module in the command when it is installed.

I’ll request a review of the changes.

Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym
koriym merged commit 7a1ee2b into 1.x Nov 24, 2026
39 checks passed
@koriym koriym mentioned this pull request Nov 24, 2026
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.

Multibinding targets added with to() / toProvider() are not compiled

1 participant