Skip to content

Conversation

@koriym
Copy link
Member

@koriym koriym commented Jul 11, 2025

Close #66

The main compatibility issue addressed is with parameter type hints when null is passed. By removing explicit array type hints and relying on runtime type checking with (array) $attr, the code becomes more flexible while maintaining the same functionality.

Two approaches were considered for PHP 8.4 compatibility:

  1. Drop support for older PHP versions that don't allow ?array = null syntax
  2. Remove explicit array type hints while maintaining runtime type safety

We chose approach 2 for the following reasons:

  • Avoids major version bump: Maintains backward compatibility across all supported PHP versions (5.3.0+)
  • Static analysis compatibility: PHPDoc type annotations still provide full static analysis support
  • Minimal maintenance overhead: No need to manage separate branches or breaking changes
  • Runtime safety preserved: Type casting with (array) $attr ensures the same runtime behavior

This approach keeps the library accessible to projects still using older PHP versions while ensuring compatibility with PHP 8.4's stricter type checking, without requiring a major version release.

Thoughts?

Summary by CodeRabbit

  • Chores
    • Updated continuous integration workflow to support PHP 8.3 and 8.4, and upgraded GitHub Actions dependencies.
    • Added static analysis job to CI pipeline and new Composer scripts for testing and static analysis.
  • Refactor
    • Relaxed type constraints on several public methods, allowing more flexible parameter types in helper classes without changing their behavior.
    • Improved documentation accuracy and refined type annotations across multiple components.

@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

Walkthrough

The codebase updates method signatures across several helper classes, removing nullable array type hints in favor of untyped parameters to address PHP 8.4 deprecation. The continuous integration workflow is also updated to test against PHP 8.3 and 8.4 and to use newer GitHub Actions versions.

Changes

File(s) Change Summary
.github/workflows/continuous-integration.yml Added PHP 8.3/8.4 to test matrix; upgraded checkout, cache, and codecov actions to latest major versions; added static-analysis job.
src/Helper/AbstractList.php Changed __invoke method: removed array type hint from $attr parameter; refined property docblocks.
src/Helper/Input.php Changed __invoke method: removed array type hint from $spec parameter; refined PHPDoc types.
src/Helper/Input/AbstractInput.php Changed __invoke method: removed array type hint from $spec parameter; added @readonly annotation; refined property PHPDocs.
src/Helper/Input/Select.php Changed __invoke method: removed array type hint from $spec parameter; updated buildOptionPlaceholder to return '' explicitly.
src/Helper/Styles.php Removed array type hints from all relevant method parameters, both public and protected; refined PHPDoc types for $attr and $capture.
composer.json Added Composer scripts for PHPStan static analysis and PHPUnit testing.
src/Escaper.php Updated PHPDoc return types from @return null to @return void for setter methods.
src/Escaper/AbstractEscaper.php Updated PHPDoc return type from @return null to @return void for setEncoding.
src/Escaper/HtmlEscaper.php Updated PHPDoc return type from @return null to @return void for setFlags.
src/EscaperFactory.php Simplified docblock for newInstance by removing unused @param annotations.
src/Helper/AbstractHelper.php Updated PHPDoc return type for setIndent from @return null to @return void.
src/Helper/AbstractSeries.php Updated PHPDoc return type for addElement from @return null to @return void.
src/Helper/Input/AbstractChecked.php Updated PHPDoc return types for setLabel and setChecked from @return null to @return void.
src/Helper/Scripts.php Updated PHPDoc parameter types for $pos from string to int; updated return types from null to void.
src/HelperLocator.php Updated PHPDoc return type for set from @return null to @return void.

Sequence Diagram(s)

sequenceDiagram
    participant CI as GitHub Actions CI
    participant PHP as PHP Interpreter
    participant Code as Helper Classes

    CI->>PHP: Run tests on PHP 8.3, 8.4
    PHP->>Code: Invoke helper methods (with untyped parameters)
    Code-->>PHP: Process attributes/specs (no type errors on null/array)
    PHP-->>CI: Return test results
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Remove nullable array type hints from method signatures to comply with PHP 8.4 deprecation (#66)
Update CI to test against PHP 8.4 and ensure compatibility with new PHP versions (#66)

Poem

A rabbit hops through fields of code,
Where type hints once did strictly bode.
PHP 8.4 now sets the scene,
No nullable arrays to be seen!
The CI runs with versions new,
The helpers work—no bug in view.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (4)
src/Helper/AbstractList.php (1)

56-62: Add runtime type casting for consistency with other helper classes.

While the type hint removal addresses PHP 8.4 compatibility, this implementation lacks the runtime type safety that other helper classes in this PR provide. The method still expects an array based on the PHPDoc comment (line 51) and property initialization (line 27).

Consider adding runtime type casting for consistency:

 public function __invoke($attr = null)
 {
     if ($attr !== null) {
-        $this->attr = $attr;
+        $this->attr = (array) $attr;
     }
     return $this;
 }

This approach matches the pattern used in src/Helper/Styles.php and maintains type safety while preserving PHP 8.4 compatibility.

src/Helper/Input/AbstractInput.php (1)

77-83: Inconsistent type handling with the prep method.

The __invoke method now accepts any type, but the prep method it calls (line 80) still has an array type hint (line 101). This inconsistency could cause runtime errors when non-array values are passed.

Consider adding runtime type casting to ensure consistency:

 public function __invoke($spec = null)
 {
     if ($spec !== null) {
-        $this->prep($spec);
+        $this->prep((array) $spec);
     }
     return $this;
 }

This ensures that prep receives an array as expected while maintaining the flexible parameter type for __invoke.

src/Helper/Input/Select.php (1)

75-85: Same inconsistency issue as AbstractInput - type mismatch with prep method.

Similar to AbstractInput.php, this method now accepts any type but calls prep (line 78) which expects an array type. This could cause runtime errors.

Apply the same fix as suggested for AbstractInput.php:

 public function __invoke($spec = null)
 {
     if ($spec !== null) {
-        $this->prep($spec);
+        $this->prep((array) $spec);
         $this->attribs($this->attribs);
         $this->options($this->options);
         $this->selected($this->value);
     }

     return $this;
 }
src/Helper/Input.php (1)

31-47: Add runtime type casting to prevent array access errors.

The method removes the array type hint but still accesses $spec as an array (lines 37, 41, 42, 43) without runtime type casting. This could cause errors if non-array values are passed.

Add runtime type casting for safety:

 public function __invoke($spec = null)
 {
     if ($spec === null) {
         return $this;
     }

+    $spec = (array) $spec;
+    
     if (empty($spec['type'])) {
         $spec['type'] = 'text';
     }

     if (empty($spec['attribs']['name'])) {
         $spec['attribs']['name'] = $spec['name'];
     }

     $input = $this->get($spec['type']);
     return $input($spec);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12d4988 and 5e65ca7.

📒 Files selected for processing (6)
  • .github/workflows/continuous-integration.yml (3 hunks)
  • src/Helper/AbstractList.php (1 hunks)
  • src/Helper/Input.php (1 hunks)
  • src/Helper/Input/AbstractInput.php (1 hunks)
  • src/Helper/Input/Select.php (1 hunks)
  • src/Helper/Styles.php (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/Helper/Input/Select.php (2)
src/Helper/Input.php (1)
  • __invoke (31-47)
src/Helper/Input/AbstractInput.php (1)
  • __invoke (77-83)
src/Helper/Input.php (5)
src/Helper/AbstractList.php (1)
  • __invoke (56-62)
src/Helper/Input/AbstractInput.php (1)
  • __invoke (77-83)
src/Escaper/AbstractEscaper.php (1)
  • __invoke (73-73)
src/Helper/Input/Select.php (1)
  • __invoke (75-85)
src/Helper/Title.php (1)
  • __invoke (39-45)
src/Helper/Input/AbstractInput.php (5)
src/Helper/Input.php (1)
  • __invoke (31-47)
src/Helper/AbstractList.php (1)
  • __invoke (56-62)
src/Helper/Input/Select.php (1)
  • __invoke (75-85)
src/Helper/Title.php (1)
  • __invoke (39-45)
src/Helper/Label.php (1)
  • __invoke (68-79)
src/Helper/Styles.php (4)
src/Helper/Scripts.php (7)
  • add (42-49)
  • attr (184-191)
  • addCond (67-75)
  • addInternal (88-94)
  • addCondInternal (108-116)
  • beginInternal (129-133)
  • beginCondInternal (146-150)
src/Helper/Links.php (1)
  • add (31-35)
src/Helper/Metas.php (1)
  • add (31-35)
src/Escaper.php (2)
  • attr (176-179)
  • css (190-193)
🪛 actionlint (1.7.7)
.github/workflows/continuous-integration.yml

48-48: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


61-61: the runner of "codecov/codecov-action@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (3)
.github/workflows/continuous-integration.yml (2)

29-30: Double-check ecosystem readiness for PHP 8.3/8.4

Great to see the new versions in the matrix, but two moving parts may still lag behind:

  1. composer:2.2 was released long before 8.4 existed – verify it bootstraps correctly.
  2. xdebug builds for bleeding-edge PHP sometimes trail GA releases.

Please run the workflow once on a fork or use shivammathur/setup-php@v2’s coverage: none flag for 8.4 until binaries are available.


33-33: Checkout action bumped to v4 – nice catch
Latest major brings Node 20 and improved performance. No further action needed.

src/Helper/Styles.php (1)

42-49: Excellent implementation of PHP 8.4 compatibility fix.

This file demonstrates the correct approach for addressing PHP 8.4 compatibility:

  1. Type hint removal: All array type hints are removed from $attr parameters
  2. Runtime type casting: Proper use of (array) $attr casting maintains type safety
  3. Consistent pattern: Applied consistently across all affected methods

This approach successfully resolves the PHP 8.4 null parameter issue while preserving backward compatibility and type safety.

This implementation should serve as the reference pattern for the other helper classes in this PR.

Also applies to: 67-76, 88-93, 106-111, 129-137, 149-157, 170-179, 218-231, 244-259

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/continuous-integration.yml (1)

61-61: Move to codecov-action@v4 for Node 20 runners
Staying on v3 (Node 16) already triggers the “runner too old” warning flagged by actionlint. Updating is a one-liner:

-        uses: codecov/codecov-action@v3
+        uses: codecov/codecov-action@v4
🧹 Nitpick comments (1)
.github/workflows/continuous-integration.yml (1)

92-94: Pin PHPStan in composer.json instead of installing ad-hoc in CI

Installing PHPStan with composer require at runtime mutates composer.lock, loses the version pin, and costs an extra network round-trip on every run. Prefer committing the dev-dependency and dropping this step:

-      - name: Install PHPStan
-        run: composer require --dev phpstan/phpstan --with-all-dependencies

Add "phpstan/phpstan": "^1.11" (or whatever version you need) under require-dev in composer.json, then composer install will bring it in for both local devs and CI.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e65ca7 and 18eefb5.

📒 Files selected for processing (16)
  • .github/workflows/continuous-integration.yml (3 hunks)
  • composer.json (1 hunks)
  • src/Escaper.php (3 hunks)
  • src/Escaper/AbstractEscaper.php (1 hunks)
  • src/Escaper/HtmlEscaper.php (1 hunks)
  • src/EscaperFactory.php (0 hunks)
  • src/Helper/AbstractHelper.php (1 hunks)
  • src/Helper/AbstractList.php (4 hunks)
  • src/Helper/AbstractSeries.php (1 hunks)
  • src/Helper/Input.php (1 hunks)
  • src/Helper/Input/AbstractChecked.php (2 hunks)
  • src/Helper/Input/AbstractInput.php (3 hunks)
  • src/Helper/Input/Select.php (2 hunks)
  • src/Helper/Scripts.php (3 hunks)
  • src/Helper/Styles.php (9 hunks)
  • src/HelperLocator.php (1 hunks)
💤 Files with no reviewable changes (1)
  • src/EscaperFactory.php
✅ Files skipped from review due to trivial changes (8)
  • src/HelperLocator.php
  • src/Helper/Input/AbstractChecked.php
  • composer.json
  • src/Helper/AbstractHelper.php
  • src/Escaper/AbstractEscaper.php
  • src/Helper/AbstractSeries.php
  • src/Escaper/HtmlEscaper.php
  • src/Escaper.php
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/Helper/AbstractList.php
  • src/Helper/Input/Select.php
  • src/Helper/Input.php
  • src/Helper/Input/AbstractInput.php
  • src/Helper/Styles.php
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/continuous-integration.yml

61-61: the runner of "codecov/codecov-action@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (4)
src/Helper/Scripts.php (3)

60-60: PHPDoc parameter type correction looks good.

The parameter type annotation has been correctly updated from string to int to match the actual usage pattern where $pos defaults to 100 (an integer) and represents a numeric position in the stack.


125-125: PHPDoc return type correction is accurate.

The return type annotation has been correctly updated from null to void since the beginInternal method doesn't explicitly return any value - it only performs setup operations for output buffering.


142-142: PHPDoc return type correction is accurate.

The return type annotation has been correctly updated from null to void since the beginCondInternal method doesn't explicitly return any value - it only performs setup operations for conditional output buffering.

.github/workflows/continuous-integration.yml (1)

29-30: 👍 8.3 / 8.4 matrix entries look good

Adding PHP 8.3 and 8.4 keeps the test matrix current without dropping legacy coverage. No issues spotted.

Copy link
Member

@harikt harikt left a comment

Choose a reason for hiding this comment

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

I want to check again, if I missed the details.

*
* @return self|string
*/
public function __invoke(array $spec = null)
Copy link
Member

Choose a reason for hiding this comment

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

Bit confused, can we do array $spec = [] to fix this ? I didnot noticed where the casting was done . (array) $attr mentioned. May be I missed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the comment, @harikt!

I kept the $spec = null as-is to avoid any behavior changes in legacy code — this method has been around since the PHP 5.x days. Instead of relying on a type hint, I tried to compensate with a more precise PHPDoc type so modern static analysis tools can still verify correctness.

The idea is to preserve runtime compatibility while improving type clarity at the tooling level.

Happy to add an explicit cast if you think it's safer. Let me know what you think!

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.

PHP 8.4: nullable types deprecated

2 participants