Skip to content

Conversation

@koriym
Copy link
Member

@koriym koriym commented Nov 12, 2025

Fix deprecation warning by explicitly marking the $length parameter as nullable (?int) in AbstractStrlen::substr() method.

Summary by CodeRabbit

  • Refactor
    • Improved internal type safety and static analysis compatibility for better code reliability.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

The substr() method signature in AbstractStrlen.php was updated to use PHP 7.1+ nullable type syntax, changing the $length parameter from int $length = null to ?int $length = null. This modernizes the type declaration while maintaining identical behavior.

Changes

Cohort / File(s) Summary
Type Declaration Modernization
src/Rule/AbstractStrlen.php
Updated substr() method parameter from int $length = null to ?int $length = null for explicit nullable type declaration

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A nullable type so clean and bright,
PHP seven-point-one's delight!
No logic bent, no behavior swayed,
Just clearer types, precise and made—
Static analysis will surely praise! 🌟

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 PR title accurately describes the main change: fixing a PHP 8.4 deprecation by updating the method signature to use nullable type syntax.
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
  • Commit unit tests in branch fix/php84-nullable-parameter

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.

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

🧹 Nitpick comments (1)
src/Rule/AbstractStrlen.php (1)

141-141: Consider updating test helper classes for consistency.

While the test helper classes in tests/Rule/FakeStrlen*.php won't trigger deprecation warnings (they use no parameter type hints), you may want to update their substr() method signatures to match the parent class for consistency:

public function substr(string $str, int $start, ?int $length = null): string

This is purely optional and doesn't affect functionality.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb7616 and 4362bf2.

📒 Files selected for processing (1)
  • src/Rule/AbstractStrlen.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Rule/AbstractStrlen.php (3)
tests/Rule/FakeStrlen.php (1)
  • substr (21-24)
tests/Rule/FakeStrlenIconv.php (1)
  • substr (16-19)
tests/Rule/FakeStrlenMbstring.php (1)
  • substr (16-19)
🔇 Additional comments (1)
src/Rule/AbstractStrlen.php (1)

141-141: LGTM! Correctly addresses PHP 8.4 deprecation.

The change from int $length = null to ?int $length = null properly fixes the PHP 8.4 deprecation warning for implicitly nullable parameters. This explicit nullable syntax is the recommended approach and maintains full backward compatibility while removing the warning.

@harikt harikt merged commit 56157d3 into 4.x Nov 25, 2025
1 of 26 checks passed
@harikt harikt deleted the fix/php84-nullable-parameter branch November 25, 2025 07:29
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