Skip to content

Compatibility with PHP8.5#167

Open
zoispag wants to merge 7 commits intovoku:masterfrom
kyosenergy:php85
Open

Compatibility with PHP8.5#167
zoispag wants to merge 7 commits intovoku:masterfrom
kyosenergy:php85

Conversation

@zoispag
Copy link

@zoispag zoispag commented Jan 7, 2026

This pull request updates dependencies, modernizes CI workflows, improves compatibility, and refines configuration files for better maintainability and PHP version support. The most important changes are grouped below:

CI/CD and Dependency Updates:

  • Updated the GitHub Actions CI workflow to use the latest versions of actions and tools, including support for PHP 8.3, 8.4, and 8.5, and upgraded actions such as actions/checkout, shivammathur/setup-php, actions/cache, codecov/codecov-action, and actions/upload-artifact to their latest major versions. Also modernized the way composer cache directory is set in the workflow. [1] [2] [3] [4]
  • Updated composer.json to use a development branch (dev-php84) of voku/portable-utf8 for improved PHP 8.4+ compatibility, and added a VCS repository entry for it.

Configuration and Coverage:

  • Refactored phpunit.xml to use the latest schema and configuration style, moving coverage and logging settings to the new format, and added a backup configuration file phpunit.xml.bak with the previous settings. [1] [2]

Code and Test Improvements:

  • Improved numeric string detection in the _do method of AntiXSS.php by using is_numeric() for more robust checks.
  • Minor test adjustments: removed a test case for null input in testNoXss() and removed unnecessary usage of setAccessible(true) in reflection helper methods. [1] [2] [3]

This change is Reviewable

Closes #166

Summary by CodeRabbit

  • Chores
    • Updated CI workflows and action versions; expanded automated testing to newer PHP releases and adjusted dependency declarations.
  • Refactor
    • Improved input-processing logic to reduce unnecessary conversions and streamline validation.
  • Tests
    • Updated test configuration and adjusted tests for newer PHP versions, removing deprecated expectations and version-gating reflective access.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

Walkthrough

This PR updates CI to test PHP 8.3–8.5, modernizes GitHub Actions versions, raises the package PHP requirement to >=8.0, adjusts dependencies, refactors PHPUnit config, and changes AntiXSS numeric-casting logic and test reflection handling to avoid casting errors on PHP 8.5.

Changes

Cohort / File(s) Summary
GitHub Actions / CI
\.github/workflows/ci.yml
Expanded PHP matrix to include 8.3–8.5; upgraded actions (checkout → v6, setup-php → v2, composer-cache → v5, codecov → v5, upload-artifact → v6); added zip & composer tool, restored restore-keys, and migrated cache/output syntax.
Dependency Management
composer.json
Added repositories entry pointing to https://github.com/kyosenergy/portable-utf8; raised require.php to >=8.0; changed voku/portable-utf8 to "dev-php84 as 6.0.13"; bumped phpunit/phpunit constraints in require-dev.
PHPUnit config
phpunit.xml
Replaced legacy XML structure with schema/namespace; moved coverage whitelist to <coverage>/<include> with processUncoveredFiles="true"; updated Clover report path and simplified logging block.
Core logic
src/voku/helper/AntiXSS.php
Replaced eager int/float casts with an is_numeric()-guarded numeric check to avoid casting non-numeric/float-string inputs and related PHP 8.5 errors.
Tests
tests/XssTest.php
Removed null→empty-string test mapping; made setAccessible(true) calls conditional on PHP version (only for PHP < 8.1) to avoid deprecated reflection usage on newer PHP.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibbled code by moonlit light,

cast worries gone, no more fright.
PHP leaps now, eight-point-five—hooray!
is_numeric() saved the day. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Compatibility with PHP8.5' clearly and concisely summarizes the main objective of the PR, directly corresponding to the primary change of adding PHP 8.5 compatibility.
Linked Issues check ✅ Passed The PR fully addresses issue #166 by fixing the ErrorException on invalid numeric casts, updating dependencies, adding PHP 8.5 CI support, and handling deprecated ReflectionMethod::setAccessible usage.
Out of Scope Changes check ✅ Passed All changes are directly related to PHP 8.5 compatibility: workflow updates for PHP 8.5 testing, dependency updates for compatibility, code fixes for casting errors, and test updates for PHP version differences.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c62840a and 4b9f2b4.

📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • composer.json
  • src/voku/helper/AntiXSS.php
  • tests/XssTest.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/ci.yml
  • tests/XssTest.php
  • composer.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
src/voku/helper/AntiXSS.php (1)

656-667: LGTM! Correctly fixes PHP 8.5 compatibility issue.

The is_numeric() guard prevents casting invalid numeric strings (like UUIDs) to int/float, which would throw an ErrorException in PHP 8.5. The short-circuit logic ensures the casts are only attempted when safe, resolving the reported issue without changing the security behavior.

Note: The parentheses around the OR expression are necessary for correct operator precedence, contrary to the previous review 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zoispag, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's compatibility with modern PHP versions, specifically up to PHP 8.5, by updating core dependencies and modernizing the continuous integration pipeline. It also includes important configuration updates for PHPUnit and minor code improvements for numeric string handling, ensuring better maintainability and future-proofing.

Highlights

  • PHP 8.5 Compatibility: Updated CI to support PHP 8.3, 8.4, and 8.5, and adjusted composer.json to use a PHP 8.4+ compatible branch of voku/portable-utf8.
  • CI/CD Modernization: Upgraded GitHub Actions (checkout, setup-php, cache, codecov, upload-artifact) to their latest major versions and modernized composer cache handling.
  • PHPUnit Configuration Update: Refactored phpunit.xml to align with the latest schema and configuration style for coverage and logging, while preserving the old config in phpunit.xml.bak.
  • Code Robustness: Improved numeric string detection in AntiXSS.php using is_numeric() for better reliability.
  • Test Refinements: Removed a null input test case and unnecessary setAccessible(true) calls in reflection helper methods within XssTest.php.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/ci.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of updating dependencies and CI workflows for PHP 8.5 compatibility. The modernization of phpunit.xml is also a welcome improvement. However, there are a few critical issues in the test files that need to be addressed. Specifically, changes to reflection helpers will break the test suite, and a valid test case has been removed, reducing coverage. Additionally, a backup file has been committed to the repository, which should be removed to avoid clutter.

Comment on lines 2122 to 2125
$reflection = new \ReflectionObject($object);
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $parameters);

Choose a reason for hiding this comment

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

critical

The call to $method->setAccessible(true); has been removed from this reflection helper. This is a critical change that will break tests. This line is necessary to allow the testing of private and protected methods, such as _remove_evil_attributes. Without it, invokeArgs will throw a ReflectionException for non-public methods. Please restore this line.

        $reflection = new \ReflectionObject($object);
        $method = $reflection->getMethod($methodName);
        $method->setAccessible(true);

        return $method->invokeArgs($object, $parameters);

Comment on lines 2138 to 2141
$reflection = new \ReflectionObject($object);
$property = $reflection->getProperty($propertyName);
$property->setAccessible(true);

return $property->getValue($object);

Choose a reason for hiding this comment

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

critical

Similar to the invokeMethod helper, removing $property->setAccessible(true); here is a critical error. This line is required to access private or protected properties during testing. Its removal will cause tests that rely on inspecting these properties (like _xss_found) to fail. Please re-add this call.

        $reflection = new \ReflectionObject($object);
        $property = $reflection->getProperty($propertyName);
        $property->setAccessible(true);

        return $property->getValue($object);

phpunit.xml.bak Outdated
Comment on lines +1 to +13
<phpunit bootstrap="tests/bootstrap.php">
<testsuite name="Anti-XSS Test Suite">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>

Choose a reason for hiding this comment

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

medium

This backup file should not be committed to the repository. Version control systems like Git are designed to keep track of file history, making backup files redundant and adding unnecessary clutter to the project. If you need to revert to the old configuration, you can do so through Git's history.

(string) $strInt === $str
||
(string) $strFloat === $str
(\is_numeric($str) && ((string) (int) $str === $str || (string) (float) $str === $str))

Choose a reason for hiding this comment

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

medium

The logic here is sound, but the extra parentheses around the \is_numeric(...) condition are redundant and can be removed for better readability. The || operator has lower precedence than &&, so the expression will be evaluated correctly without them.

            \is_numeric($str) && ((string) (int) $str === $str || (string) (float) $str === $str)

'<a href="https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_15446515888862039806%22%7D&n_type=0&p_from=1" target="_blank">Valid Link</a>' => '<a href="https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_15446515888862039806%22%7D&n_type=0&p_from=1" target="_blank">Valid Link</a>',
'' => '',
' ' => ' ',
null => '',

Choose a reason for hiding this comment

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

medium

This test case for null input appears to have been removed. Since xss_clean(null) is expected to return an empty string, this is a valid and useful test case that ensures correct behavior for this input. Removing it reduces test coverage. Please consider re-adding it.

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: 1

🤖 Fix all issues with AI agents
In @phpunit.xml:
- Around line 1-14: The phpunit.xml uses the PHPUnit 9.3-style
<coverage>/<include> blocks which are incompatible with PHPUnit 6/7 used on PHP
7.0-7.2; update the repo to supply a config compatible with both versions by
either restoring the older phpunit.xml.bak format (using <filter><whitelist>
elements) alongside the current phpunit.xml, or produce a phpunit.xml.dist that
uses the legacy <filter><whitelist> syntax while keeping the new file for
PHPUnit 9+, and ensure composer.json's phpunit/phpunit constraint
(~6.0||~7.0||~9.0) is honored by CI so jobs on PHP 7.0-7.2 will load the legacy
config.
🧹 Nitpick comments (3)
phpunit.xml.bak (1)

1-13: Backup file retained for reference.

This backup preserves the legacy PHPUnit configuration with deprecated <filter>/<whitelist> and <logging>/<log> syntax. Consider removing this file after confirming the new phpunit.xml works correctly across all PHP versions, or add it to .gitignore to prevent accidental commits.

phpunit.xml (1)

14-14: Remove empty <logging/> element.

The empty <logging/> element serves no purpose and can be removed.

Suggested fix
   </testsuite>
-  <logging/>
 </phpunit>
composer.json (1)

24-32: Using a fork with a development branch is necessary but document the rationale.

The official voku/portable-utf8 package (version 6.0.13) only supports PHP >=7.0.0 and lacks PHP 8.4+ compatibility. The kyosenergy/portable-utf8 fork is actively maintained and explicitly designed for PHP 8.4 compatibility, making this workaround justified.

However, add documentation explaining this dependency choice (in a comment or README) so future maintainers understand the reason. Additionally, monitor the official package for updates and plan a migration back once PHP 8.4+ support is released.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25a3cf6 and 630b204.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • composer.json
  • phpunit.xml
  • phpunit.xml.bak
  • src/voku/helper/AntiXSS.php
  • tests/XssTest.php
💤 Files with no reviewable changes (1)
  • tests/XssTest.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (5)
src/voku/helper/AntiXSS.php (1)

656-667: LGTM! The is_numeric() guard prevents PHP 8.5 deprecation warnings.

The conditional now short-circuits before casting non-numeric strings, avoiding the "implicit conversion from float-string to int" deprecation introduced in PHP 8.5. The logic correctly:

  • Skips processing for pure numeric strings (integers and floats)
  • Avoids unnecessary casts on non-numeric input
  • Preserves the original behavior for XSS detection
.github/workflows/ci.yml (4)

49-58: LGTM! Proper migration from deprecated set-output to GITHUB_OUTPUT.

The change from ::set-output to >> $GITHUB_OUTPUT follows GitHub's recommended approach after the deprecation notice.


94-101: Verify action versions are available.actions/upload-artifact@v6 is available and runs on Node.js 24, requiring a minimum Actions Runner version of 2.327.1. The versions are valid.


38-39: actions/checkout@v6 exists and is stable. Version 6 has been released with stable versions including v6.0.0 and v6.0.1. The reference @v6 is valid and appropriate for use in the workflow.

Likely an incorrect or invalid review comment.


28-30: No action needed. shivammathur/setup-php@v2 explicitly supports PHP 8.5 (documented range: PHP 5.3–8.6), so the workflow matrix entries for PHP 8.3, 8.4, and 8.5 are correct. No continue-on-error flag is required.

Likely an incorrect or invalid review comment.

Comment on lines +1 to +14
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuite name="Anti-XSS Test Suite">
<directory>tests</directory>
</testsuite>
<logging/>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

PHPUnit configuration may not be compatible with PHP 7.0-7.2.

This configuration uses PHPUnit 9.3+ schema with <coverage> and <include> blocks. However, composer.json allows phpunit ~6.0 || ~7.0 || ~9.0, and the CI matrix tests PHP 7.0-7.2 which require PHPUnit 6.x or 7.x (PHPUnit 9 requires PHP 7.3+).

PHPUnit 6/7 uses the old <filter>/<whitelist> syntax from phpunit.xml.bak. This means:

  • PHP 7.0-7.2 CI jobs may fail or produce warnings about unrecognized configuration elements

Consider keeping both config files or using PHPUnit's ability to auto-detect configuration format.

#!/bin/bash
# Verify PHPUnit version constraints in composer.json
cat composer.json | jq '.["require-dev"]["phpunit/phpunit"]'
🤖 Prompt for AI Agents
In @phpunit.xml around lines 1 - 14, The phpunit.xml uses the PHPUnit 9.3-style
<coverage>/<include> blocks which are incompatible with PHPUnit 6/7 used on PHP
7.0-7.2; update the repo to supply a config compatible with both versions by
either restoring the older phpunit.xml.bak format (using <filter><whitelist>
elements) alongside the current phpunit.xml, or produce a phpunit.xml.dist that
uses the legacy <filter><whitelist> syntax while keeping the new file for
PHPUnit 9+, and ensure composer.json's phpunit/phpunit constraint
(~6.0||~7.0||~9.0) is honored by CI so jobs on PHP 7.0-7.2 will load the legacy
config.

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: 1

🤖 Fix all issues with AI agents
In @phpunit.xml:
- Around line 1-13: The phpunit.xml uses PHPUnit 9.3+ coverage syntax
(<coverage>, <include>, <report>) which is incompatible with PHPUnit 7.x
installed on PHP 7.0/7.1 in CI; create a legacy configuration (e.g.,
phpunit-legacy.xml) that replaces the modern <coverage> block with the legacy
<filter>/<whitelist> structure and same <directory> entries, then update the CI
workflow to select phpunit-legacy.xml when running jobs on PHP 7.0 and 7.1 (or
alternatively split configs and constrain which config each PHP job uses).
🧹 Nitpick comments (1)
phpunit.xml (1)

14-14: Consider removing the empty logging element.

The empty <logging/> element serves no functional purpose and can be removed to simplify the configuration.

♻️ Proposed cleanup
   </testsuite>
-  <logging/>
-
 </phpunit>
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 630b204 and c62840a.

📒 Files selected for processing (1)
  • phpunit.xml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

- Add is_numeric() guard to prevent ErrorException on invalid numeric
  strings in PHP 8.5 when casting to int
- Conditionally call setAccessible() only on PHP < 8.1 to avoid
  deprecation warnings while maintaining PHP 8.0 compatibility
- Remove redundant parentheses in condition
@AWqxKAWERbXo
Copy link

If only bots could actually merge fixes 🥲

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.5 compatibility

2 participants