Skip to content

feat(HTMLNode): add type-specific factory methods for template loading#81

Merged
usernane merged 1 commit into
devfrom
feat/type-specific-factory-methods
Jun 10, 2026
Merged

feat(HTMLNode): add type-specific factory methods for template loading#81
usernane merged 1 commit into
devfrom
feat/type-specific-factory-methods

Conversation

@usernane

Copy link
Copy Markdown
Member

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 use instanceof checks, and type mismatches surface late. Fixes #65.

Changes

  • fromFileAsDocument(string $path, array $vars = []): HTMLDoc — throws if not a full document
  • fromFileAsNode(string $path, array $vars = []): HTMLNode — throws if multiple roots or empty
  • fromFileAsArray(string $path, array $vars = []): array — always succeeds, normalizes output
  • Test templates: multi-root.html, empty.html
  • 10 tests covering all branches at 100%

How to Test / Verify

cd tests && php ../vendor/bin/phpunit WebFiori/Tests/Ui/FromFileFactoryTest.php

10 tests, 22 assertions. Full suite: 362 tests pass.

Breaking Changes and Migration Steps

None. Additive — three new methods, existing fromFile() unchanged.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not) — 100% coverage of new methods
  • I updated docs (if needed) Docs Repo — N/A, PHPDoc included
  • I ran lint/cs-fixer (if applicable) (composer fix-cs) — N/A
  • I considered backward compatibility
  • I considered security

Related issues

Closes #65

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
@usernane usernane merged commit 9bb0ea8 into dev Jun 10, 2026
2 checks passed
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.43%. Comparing base (e047352) to head (deadb49).
⚠️ Report is 2 commits behind head on dev.

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              
Flag Coverage Δ
php-8.3 98.43% <100.00%> (+0.02%) ⬆️
php-8.5 97.67% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant