feat: validate extension attributes in the constructor - #15
Merged
Conversation
Greptile SummaryThe PR moves extension-name and value-type validation into CloudEvent construction.
Confidence Score: 4/5The PR is not yet safe to merge because native unserialization can still produce a CloudEvent whose invalid extensions are accepted by validate(). PHP native unserialization bypasses the constructor, while current validate() contains no extension checks and the class has no unserialization hook to re-establish the constructor invariant. Files Needing Attention: src/CloudEvents/CloudEvent.php Important Files Changed
Reviews (4): Last reviewed commit: "feat: validate extension attributes in t..." | Re-trigger Greptile |
Meldiron
force-pushed
the
feat-constructor-validation
branch
from
July 30, 2026 11:07
524f2a5 to
8a89ab2
Compare
Meldiron
force-pushed
the
docs-spec-accuracy
branch
from
July 31, 2026 10:00
eb1675c to
aed7a6b
Compare
Meldiron
force-pushed
the
feat-constructor-validation
branch
from
July 31, 2026 10:03
8a89ab2 to
4b48d08
Compare
Extension attribute names and value types are now checked when a CloudEvent is constructed, so an event carrying invalid extensions can never exist. Previously the constructor accepted anything and the problem only surfaced when validate() was called. Since extensions are passed at construction time and the property is readonly, the redundant checks in fromArray() and validate() are removed; error messages are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Meldiron
force-pushed
the
feat-constructor-validation
branch
from
July 31, 2026 10:10
4b48d08 to
eb07d94
Compare
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.
What
Extension attribute names and value types are now validated when a
CloudEventis constructed:Why
Previously the constructor accepted any
extensionsarray and the problem only surfaced whenvalidate()happened to be called — an invalid event could travel through the system before failing. Since$extensionsisreadonlyand every path into an instance (fromArray(),fromJson()) goes through the constructor, checking once at construction guarantees an instance never carries an invalid extension.Notes
fromArray()andvalidate()are removed;fromArray()still treatsnullextension values as unset before constructing. Exception messages are unchanged, and the existingfromArrayrejection tests pass as-is against the constructor-thrown exceptions.validate()time. ThetestValidateRejects*Extension*tests were reworked into their constructor-level equivalents (testConstructorRejectsInvalidExtensionName/ReservedExtensionName/InvalidExtensionValue).extensionsproperty.🤖 Generated with Claude Code