Throw on helper name collisions - #94
Conversation
HelperRegistry is a flat name => callable map and set() overwrote silently, so two packages both registering 'url' meant last-one-wins with no warning and no way to tell it had happened. set() now takes a third parameter, $override, and throws Exception\HelperAlreadyRegistered when the name is taken and override is false. Passing override: true on an unregistered name is deliberately not an error: it means "I accept replacing whatever is there", not "something must be there", so an application can assert its own helper without first probing for a module's. Registering the identical callable twice also throws. Two packages that share an implementation still have to say which one owns the name. The constructor map now routes through set() so there is one way in.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
WalkthroughHelper registration now rejects duplicate names by default, exposes an ChangesHelper registration behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant HelperRegistry
participant HelperAlreadyRegistered
Caller->>HelperRegistry: set(name, callable, override)
alt duplicate name without override
HelperRegistry->>HelperAlreadyRegistered: create exception
HelperAlreadyRegistered-->>Caller: throw exception
else new name or override enabled
HelperRegistry-->>Caller: register callable
end
Poem
✨ Finishing Touches📝 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 |
|
@coderabbitai review . |
|
✅ Action performedReview finished.
|
|
@coderabbitai fullreview |
|
✅ Action performedFull review finished. |
HelperRegistry is a flat name => callable map and set() overwrote silently, so two packages both registering 'url' meant last-one-wins with no warning and no way to tell it had happened.
set() now takes a third parameter, $override, and throws Exception\HelperAlreadyRegistered when the name is taken and override is false. Passing override: true on an unregistered name is deliberately not an error: it means "I accept replacing whatever is there", not "something must be there", so an application can assert its own helper without first probing for a module's.
Registering the identical callable twice also throws. Two packages that share an implementation still have to say which one owns the name.
The constructor map now routes through set() so there is one way in.
Summary by CodeRabbit
override: trueoption to intentionally replace an existing helper.