Skip to content

Modernize for PHP 8.1+ and PHPUnit 11#2

Merged
joanfabregat merged 4 commits into
masterfrom
modernize-php8
Apr 15, 2026
Merged

Modernize for PHP 8.1+ and PHPUnit 11#2
joanfabregat merged 4 commits into
masterfrom
modernize-php8

Conversation

@joanfabregat

Copy link
Copy Markdown
Member

Summary

  • Drop PHP 7.x support, require PHP 8.1+ with ext-mbstring
  • Upgrade PHPUnit from ^7 to ^11 (resolves Dependabot alert #1CVE-2026-24765)
  • Modernize source code: PHP 8.4 typed constants, trailing commas, clean docblocks
  • Rewrite tests with #[DataProvider] attributes, assertSame assertions, and full coverage of strip(), stripNonPrint(), ligatures, edge cases
  • Add phpunit.xml.dist configuration
  • Add GitHub Actions CI workflow (PHP 8.1–8.4 matrix) for pushes and PRs
  • Update README with Packagist badges and modern usage examples

Test plan

  • All 60 tests pass on PHP 8.3 (verified in ephemeral container)
  • CI workflow runs on this PR across PHP 8.1–8.4

🤖 Generated with Claude Code

Drop PHP 7.x support, require PHP 8.1+. Update PHPUnit from ^7 to ^11
(fixes CVE-2026-24765 Dependabot alert). Modernize source with typed
constants and trailing commas. Rewrite tests with data providers and
proper assertions. Add phpunit.xml.dist, CI workflow for PRs, and
Packagist badges to README.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 15, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown

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 modernizes the library for newer PHP/PHPUnit versions by updating platform constraints, refreshing the implementation and test suite, and adding CI + PHPUnit configuration.

Changes:

  • Bump requirements to PHP 8.1+ (plus ext-mbstring) and upgrade PHPUnit to ^11.
  • Modernize StripAccents + expand/rewrite tests using PHPUnit attributes and more explicit assertions.
  • Add PHPUnit config (phpunit.xml.dist) and a GitHub Actions CI workflow to run tests across multiple PHP versions.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/StripAccents.php Modernized implementation and constants; reformatted stripNonPrint() signature.
tests/StripAccentsTest.php Rewritten tests with a data provider + added coverage for edge cases/ligatures/stripNonPrint().
phpunit.xml.dist New PHPUnit 11 configuration (bootstrap, cache dir, source include).
composer.json Drops PHP 7.x, requires PHP 8.1+ and ext-mbstring, upgrades PHPUnit dev requirement.
README.md Updated docs with badges and modern examples (incl. named args).
.gitignore Ignores PHPUnit cache directory.
.github/workflows/ci.yml Adds CI job running PHPUnit in a PHP version matrix.

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

Comment thread README.md Outdated
Comment on lines +38 to +41
// "ABC AEY "

// You can specify any encoding supported by htmlentities() as a second parameter
echo StripAccents::strip("A strïng with àccénts", "iso-8859-1");
echo StripAccents::stripNonPrint("ABC ÀÈÝ 是我这", replaceWith: "-");
// "ABC AEY ---"

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The example output for stripNonPrint(..., replaceWith: "-") appears incorrect for the current implementation: the regex runs byte-wise (no /u modifier), so each 3-byte CJK character becomes 3 replacements (the tests assert 9 - total). Update the README example to match actual behavior, or clarify/document a character-wise replacement approach if that’s the intent.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/ci.yml
Comment on lines +5 to +7
branches: [master]
pull_request:
branches: [master]

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The workflow is restricted to branches: [master]. If the default branch is main (as suggested by the PR diff base), CI won’t run for pushes/PRs to the default branch. Consider switching this filter to the actual default branch name or removing the branch filter to ensure CI runs on all PRs.

Suggested change
branches: [master]
pull_request:
branches: [master]
branches: [main]
pull_request:
branches: [main]

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/ci.yml Outdated

strategy:
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4']

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

CI runs PHP 8.1/8.2, but the code in this PR uses typed class constants (PHP 8.3+). Either drop 8.1/8.2 from the matrix or adjust the code/composer constraints so the matrix matches the supported PHP versions.

Suggested change
php-version: ['8.1', '8.2', '8.3', '8.4']
php-version: ['8.3', '8.4']

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated
composer require codeinc/strip-accents
```

Requires PHP 8.1 or later.

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

README requirement statement is incomplete/inconsistent with composer.json: the package now requires ext-mbstring, but the README only mentions the PHP version. Also, if typed class constants remain, the minimum PHP version becomes 8.3+. Please align the README requirements with the actual composer/platform constraints.

Suggested change
Requires PHP 8.1 or later.
Requires PHP 8.3 or later with the `mbstring` extension enabled.

Copilot uses AI. Check for mistakes.
Comment thread src/StripAccents.php Outdated
class StripAccents
{
public const DEFAULT_ENCODING = 'utf-8';
private const string DEFAULT_ENCODING = 'utf-8';

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

private const string DEFAULT_ENCODING uses typed class constants, which are not supported in PHP 8.1/8.2. With the current composer.json requirement (php >=8.1) and CI matrix including 8.1/8.2, this will cause a parse error on those versions. Either remove the constant type declarations, or bump the minimum PHP version (and update README/CI accordingly).

Suggested change
private const string DEFAULT_ENCODING = 'utf-8';
private const DEFAULT_ENCODING = 'utf-8';

Copilot uses AI. Check for mistakes.
Comment thread tests/StripAccentsTest.php Outdated
'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a',
'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'e', 'o',
'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y'
private const array ACCENT_MAP = [

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

private const array ACCENT_MAP uses typed class constants, which are not supported in PHP 8.1/8.2. Since the PR targets PHP 8.1+ (and CI tests 8.1/8.2), this will make the test suite fail to even parse on those versions. Either remove the type from the constant or raise the project’s minimum PHP version and align CI/README.

Suggested change
private const array ACCENT_MAP = [
private const ACCENT_MAP = [

Copilot uses AI. Check for mistakes.
joanfabregat and others added 3 commits April 15, 2026 11:38
Remove typed class constants (PHP 8.3+ only) to maintain PHP 8.1+
compatibility. Document mbstring requirement and correct stripNonPrint
example output in README.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
PHPUnit 11 requires PHP 8.2+, so drop 8.1 from the matrix and bump
the composer constraint accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Keep backward compatibility with existing consumers that may reference
StripAccents::DEFAULT_ENCODING directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@joanfabregat joanfabregat merged commit 66c8214 into master Apr 15, 2026
3 checks passed
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