Skip to content

Allow pass int, float and null as tag content#270

Merged
vjik merged 4 commits intomasterfrom
content
Mar 18, 2026
Merged

Allow pass int, float and null as tag content#270
vjik merged 4 commits intomasterfrom
content

Conversation

@vjik
Copy link
Member

@vjik vjik commented Mar 17, 2026

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fix #151

@vjik vjik requested a review from Copilot March 17, 2026 08:00
@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4f5d9f1) to head (538b1d3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #270   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       827       828    +1     
===========================================
  Files             89        89           
  Lines           2225      2225           
===========================================
  Hits            2225      2225           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements issue #151 by widening supported tag content types across the tag API, allowing int, float, and null to be used as content (rendering numeric scalars as strings and null as empty content), and extends coverage across multiple tags and helpers.

Changes:

  • Expand TagContentTrait to accept int|float|null and ensure consistent string rendering.
  • Widen multiple tag/helper method signatures (e.g., Html::*, Button::*, Table::captionString(), Textarea::value(), table/list cell builders) to accept the new content types.
  • Add/extend PHPUnit coverage for numeric/null content across tags and helper factories.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/Tag/TrTest.php Adds coverage for `null
tests/Tag/TextareaTest.php Adds coverage for numeric Textarea::value().
tests/Tag/TableTest.php Refactors captionString test into a data provider including numeric/null inputs.
tests/Tag/StyleTest.php Adds coverage for Stringable style content.
tests/Tag/SelectTest.php Adds coverage for numeric option labels and Stringable prompt text.
tests/Tag/ScriptTest.php Adds coverage for Stringable script content.
tests/Tag/OptgroupTest.php Adds coverage for numeric option labels in optgroups.
tests/Tag/CustomTagTest.php Adds coverage for numeric/null content on custom tags.
tests/Tag/ButtonTest.php Refactors button/submit/reset tests into data providers covering numeric/null content.
tests/Tag/Base/TagContentTraitTest.php Extends trait tests for numeric/null content and addContent/content-array behavior.
tests/Tag/Base/ListTagTest.php Adds coverage for numeric/null list item content.
tests/HtmlTest.php Extends Html::* helper tests to assert numeric/null content rendering across many tags.
src/Tag/Tr.php Updates internal cell builders to accept `Stringable
src/Tag/Textarea.php Widens value() to accept numeric values and casts to string.
src/Tag/Table.php Widens captionString() to accept `Stringable
src/Tag/Style.php Allows Stringable content and casts to string.
src/Tag/Select.php Widens OptionsData Psalm type and prompt() to accept Stringable.
src/Tag/Script.php Allows Stringable content and casts to string.
src/Tag/Optgroup.php Updates options-data PHPDoc to allow numeric/null option labels.
src/Tag/Button.php Widens named constructors to accept `Stringable
src/Tag/Base/TagContentTrait.php Core change: allow `int
src/Tag/Base/ListTag.php Updates list strings() to accept numeric/null item content.
src/Html.php Widens many helper signatures to accept `int
CHANGELOG.md Adds entry describing the new feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the HTML tag API to accept int, float, and null as tag content across core tag building helpers, aligning behavior with issue #151 and updating tests accordingly.

Changes:

  • Broaden TagContentTrait content handling to support string|Stringable|int|float|null and stringify content during rendering.
  • Update multiple tag/helper APIs (Html::*, Button, Table::captionString(), Select::prompt(), list/table row helpers) and add test coverage for the new accepted content types.
  • Add/extend tests across tags to validate rendering of numeric and null content.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Tag/TrTest.php Extends Tr::dataStrings() / headerStrings() test cases to include null, int, float.
tests/Tag/TextareaTest.php Adds int/float value cases for <textarea>.
tests/Tag/TableTest.php Converts caption string test to a data provider covering `string
tests/Tag/StyleTest.php Adds coverage for Style::content() accepting Stringable.
tests/Tag/SelectTest.php Adds coverage for numeric/null option labels and prompt text types.
tests/Tag/ScriptTest.php Adds coverage for Script::content() accepting Stringable.
tests/Tag/OptgroupTest.php Adds coverage for numeric option labels in optgroups.
tests/Tag/CustomTagTest.php Adds content cases for `int
tests/Tag/ButtonTest.php Adds data providers covering `string
tests/Tag/Base/TagContentTraitTest.php Extends trait tests for numeric/null content and array/named-argument usage.
tests/Tag/Base/ListTagTest.php Adds coverage for list item contents including numeric/null.
tests/HtmlTest.php Adds coverage for Html::* helpers with numeric/null content + stringable style/script.
src/Tag/Tr.php Updates internal cell creation to accept broader content types; updates header docs.
src/Tag/Textarea.php Widens value() accepted types to include `int
src/Tag/Table.php Widens captionString() to accept `Stringable
src/Tag/Style.php Allows Stringable content and casts to string.
src/Tag/Select.php Broadens OptionsData psalm type and widens prompt() to numeric/null/stringable.
src/Tag/Script.php Allows Stringable content and casts to string.
src/Tag/Optgroup.php Updates option data phpdoc to allow numeric/null/stringable contents.
src/Tag/Button.php Widens static factory methods to accept numeric/null/stringable content.
src/Tag/Base/TagContentTrait.php Core change: allow `int
src/Tag/Base/ListTag.php Widens list item “strings” helpers to accept numeric/null/stringable contents.
src/Html.php Widens many helper method content parameter types to include `int
CHANGELOG.md Adds changelog entry for allowing int, float, null tag content.
Comments suppressed due to low confidence (2)

src/Tag/Tr.php:106

  • makeDataCells() now accepts string|Stringable|int|float|null, but the public dataStrings() / addDataStrings() docblocks above still say @param string[] $strings and describe encoding “strings passed”. Please update those docblocks to match the actual supported content types (as done for headerStrings()), so static analysis and IDE hints stay accurate.
    /**
     * @param (string|Stringable|int|float|null)[] $strings
     *
     * @return Td[]
     */
    private function makeDataCells(array $strings, array $attributes, bool $encode): array
    {
        return array_map(
            static fn(string|Stringable|int|float|null $string) => (new Td())
                ->content($string)
                ->attributes($attributes)
                ->encode($encode),
            $strings,
        );

src/Tag/Textarea.php:50

  • Textarea::value() currently casts any non-array $value to string before passing it to TagContentTrait::content(). This loses object identity for NoEncodeStringableInterface implementations (they will now be encoded because they become plain strings). Since TagContentTrait::content() now supports Stringable|int|float|null, consider passing $value through unchanged (and only implode() arrays) to preserve encoding semantics for stringable inputs.
    public function value(string|Stringable|int|float|array|null $value): self
    {
        $content = is_array($value)
            ? implode("\n", $value)
            : (string) $value;
        return $this->content($content);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vjik vjik requested a review from a team March 17, 2026 08:30
@vjik vjik added the status:code review The pull request needs review. label Mar 17, 2026
@vjik vjik merged commit 3507be6 into master Mar 18, 2026
29 of 30 checks passed
@vjik vjik deleted the content branch March 18, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow pass int, float and null as content

3 participants