feat(HTMLNode): add type-specific factory methods for template loading#81
Merged
Conversation
Add three new static methods that wrap fromFile() with explicit return types and fail-fast validation: - fromFileAsDocument(): returns HTMLDoc, throws if not a full document - fromFileAsNode(): returns HTMLNode, throws if multiple roots or empty - fromFileAsArray(): returns array, always succeeds by normalizing The existing fromFile() remains unchanged for backward compatibility. Closes #65
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #81 +/- ##
============================================
+ Coverage 98.40% 98.43% +0.02%
- Complexity 967 978 +11
============================================
Files 7 7
Lines 1946 1975 +29
============================================
+ Hits 1915 1944 +29
Misses 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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
Add three type-specific factory methods that wrap
fromFile()with explicit return types and fail-fast validation.Motivation
fromFile()returns 5 possible types with no declared union type. Callers must useinstanceofchecks, and type mismatches surface late. Fixes #65.Changes
fromFileAsDocument(string $path, array $vars = []): HTMLDoc— throws if not a full documentfromFileAsNode(string $path, array $vars = []): HTMLNode— throws if multiple roots or emptyfromFileAsArray(string $path, array $vars = []): array— always succeeds, normalizes outputmulti-root.html,empty.htmlHow to Test / Verify
10 tests, 22 assertions. Full suite: 362 tests pass.
Breaking Changes and Migration Steps
None. Additive — three new methods, existing
fromFile()unchanged.Checklist
composer fix-cs) — N/ARelated issues
Closes #65