Skip to content

Fix PHP 8.5 deprecation warnings, tests#110

Open
tfedor wants to merge 2 commits intovoku:masterfrom
tfedor:master
Open

Fix PHP 8.5 deprecation warnings, tests#110
tfedor wants to merge 2 commits intovoku:masterfrom
tfedor:master

Conversation

@tfedor
Copy link
Copy Markdown

@tfedor tfedor commented Dec 9, 2025

Fixes #
Fix PHP 8.5 deprecation warnings #109, and about 9 tests that were failing for me. There are still 5 tests that fail, but I think those are coming from the dependency.


This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes

    • Improved null-safety handling to prevent potential crashes during HTML processing.
  • Performance Improvements

    • Refined HTML attribute removal during minification for better handling.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 9, 2025

Walkthrough

This PR refactors observer registration in HtmlMin from SplObjectStorage's attach() method to direct array-style assignment, adds a null-safety check in protectTagHelper to prevent null dereference, and changes attribute removal in HtmlMinDomObserverOptimizeAttributes from null assignment to the removeAttribute() method.

Changes

Cohort / File(s) Summary
Observer Registration & Null-Safety
src/voku/helper/HtmlMin.php
Modified attachObserverToTheDomLoop to store observers via array-style assignment instead of SplObjectStorage.attach(); added null check in protectTagHelper before accessing $parentNode->nodeValue
Attribute Handling
src/voku/helper/HtmlMinDomObserverOptimizeAttributes.php
Changed domElementAfterMinification to use removeAttribute() method instead of setting attribute property to null when sorting HTML attributes

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Observer storage mechanism change: The shift from SplObjectStorage.attach() to array-style assignment requires verification that indexing behavior, iteration patterns, and any identity-based lookups remain consistent
  • Null-safety check: Straightforward defensive programming addition; verify the null condition is exhaustive
  • Attribute removal refactoring: Ensure removeAttribute() semantics match previous null-assignment behavior in downstream processing

Poem

🐰 Observers now nest in arrays so neat,
Null checks keep parent nodes safe and sweet,
Attributes removed, no null in between,
Cleaner, more careful, and bug-free scene!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions fixing PHP 8.5 deprecation warnings and tests, which aligns with the PR objectives of addressing deprecation warnings from issue #109 and resolving failing tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @tfedor, 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 primarily focuses on resolving PHP 8.5 deprecation warnings and stabilizing the codebase by fixing several related test failures. The changes involve updating how observers are attached, adding null checks for DOM elements, and refining the process of removing HTML attributes, ensuring better compatibility with newer PHP versions and improving overall code reliability.

Highlights

  • PHP 8.5 Deprecation Fixes: Addressed several PHP 8.5 deprecation warnings by updating the observer attachment mechanism and introducing null checks for DOM parent nodes.
  • Attribute Removal Refinement: Improved the method for removing HTML attributes by utilizing removeAttribute() instead of direct null assignment, enhancing code robustness.
  • Test Stability: Fixed approximately 9 failing tests that were encountered, contributing to overall code stability.
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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Dec 9, 2025

Copy link
Copy Markdown

@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 addresses deprecation warnings for PHP 8.5 and fixes several tests. The changes are well-targeted and correct.

The update from SplObjectStorage::attach() to array syntax is the correct way to handle the PHP 8.5 deprecation. The added null check for $parentNode correctly prevents a potential fatal error and likely fixes some of the failing tests mentioned. The switch to removeAttribute() is also a good improvement for code clarity.

I have one minor suggestion to use the nullsafe operator to make one of the new checks more concise. Overall, this is a great set of improvements.


$parentNode = $element->parentNode();
if ($parentNode->nodeValue !== null) {
if (!is_null($parentNode) && $parentNode->nodeValue !== null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this check is correct and fixes a potential null access error, you can make it more concise by using the nullsafe operator (?->), which was introduced in PHP 8.0. It simplifies checks for null before property or method access.

            if ($parentNode?->nodeValue !== null) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Intentional to not break PHP 7 compatibility

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
src/voku/helper/HtmlMin.php (1)

1716-1720: Good null-safety improvement.

The null check for $parentNode before accessing nodeValue prevents potential null dereference when elements don't have a parent node.

Consider using direct comparison for consistency with PHP idioms:

-            if (!is_null($parentNode) && $parentNode->nodeValue !== null) {
+            if ($parentNode !== null && $parentNode->nodeValue !== null) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 872dac4 and 64ada64.

📒 Files selected for processing (2)
  • src/voku/helper/HtmlMin.php (2 hunks)
  • src/voku/helper/HtmlMinDomObserverOptimizeAttributes.php (1 hunks)
⏰ 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 (2)
src/voku/helper/HtmlMinDomObserverOptimizeAttributes.php (1)

143-146: LGTM! Proper use of removeAttribute() for attribute removal.

Using removeAttribute() instead of setting the property to null is the correct DOM API for attribute removal and addresses PHP 8.5 deprecation warnings related to dynamic property access patterns.

src/voku/helper/HtmlMin.php (1)

350-353: Use array-style assignment instead of attach() for SplObjectStorage compatibility with PHP 8.5.

In PHP 8.5.0, SplObjectStorage::attach(), contains(), and detach() methods are deprecated. The array-style syntax ($storage[$object] = $value, isset($storage[$object]), and unset($storage[$object])) should be used instead. The change on line 352 correctly implements this by using $this->domLoopObservers[$observer] = $observer; rather than the deprecated attach() method.

@TheDigitalOrchard
Copy link
Copy Markdown

The author of this library (Lars) seems to have disappeared. Not responding here, and no recent activity on his social channels. Hopefully Lars is okay.

As for this library, we may need to switch to a forked copy to keep it maintained.

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.

2 participants