Skip to content

Bumps min PHP to ^8.3#59

Merged
MekDrop merged 1 commit intoimponeer:mainfrom
MekDrop:bump-min-php-to-8.3
Jul 8, 2025
Merged

Bumps min PHP to ^8.3#59
MekDrop merged 1 commit intoimponeer:mainfrom
MekDrop:bump-min-php-to-8.3

Conversation

@MekDrop
Copy link
Copy Markdown
Member

@MekDrop MekDrop commented Jul 8, 2025

Resolves #53

Summary by CodeRabbit

  • New Features

    • Introduced a new enum for error parameter modes, enhancing clarity and type safety.
  • Refactor

    • Modernized error handling classes and traits with strict typing, updated method signatures, and replaced legacy PHP features with modern alternatives.
    • Updated autoloading configuration for development and improved code style consistency.
  • Chores

    • Updated PHP version requirement to 8.3+ and adjusted test matrix to run only on PHP 8.4.
    • Improved and modernized test suites for better reliability and maintainability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 8, 2025

Walkthrough

The codebase was modernized to require PHP 8.3 or higher, updating composer constraints, test workflows, and code to utilize new PHP features such as enums, typed properties, and strict typing. The ErrorsCollection class was refactored to use modern interfaces and serialization, and tests and traits were updated for compatibility and clarity.

Changes

Files / Groups Change Summary
.github/workflows/on-pull-request.yml Updated CI to test only on PHP 8.4, removing older PHP versions from the matrix.
composer.json Raised PHP requirement to ">=8.3", added autoload-dev, improved formatting.
src/ErrorsCollection.php, src/ParamsMode.php Refactored ErrorsCollection: replaced integer modes with ParamsMode enum, added strict typing, modernized methods. Added new ParamsMode enum.
src/ErrorsTrait.php Added strict typing, updated method signatures, clarified property and parameter names.
tests/ErrorsCollectionTest.php, tests/ErrorsTraitTest.php Updated namespaces, modernized PHPUnit assertions, added data providers, and improved type safety in tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ErrorsCollection
    participant ParamsMode

    User->>ErrorsCollection: new ErrorsCollection(mode: ParamsMode)
    User->>ErrorsCollection: add(error data)
    ErrorsCollection->>ParamsMode: Check mode for error handling
    User->>ErrorsCollection: toJson()
    ErrorsCollection->>User: JSON string (throws JsonException on failure)
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Bump minimum PHP version to 8.3 (#53)

Possibly related issues

Poem

A hop and a skip, to PHP eight-three,
Modern code for all the bunnies to see!
Enums and types, so strict and neat,
Errors collected, never missing a beat.
With tests that leap and code that shines,
🐇 This rabbit’s proud of these modern lines!
— CodeRabbit

✨ Finishing Touches
  • 📝 Generate Docstrings

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

🧹 Nitpick comments (1)
tests/ErrorsTraitTest.php (1)

62-62: Fix copy-paste error in method documentation.

The comment says "must return array" but the method should return a string.

-			'getErrors without param must return array'
+			'getHtmlErrors should return string'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5888c60 and 40eb314.

📒 Files selected for processing (7)
  • .github/workflows/on-pull-request.yml (1 hunks)
  • composer.json (1 hunks)
  • src/ErrorsCollection.php (1 hunks)
  • src/ErrorsTrait.php (2 hunks)
  • src/ParamsMode.php (1 hunks)
  • tests/ErrorsCollectionTest.php (4 hunks)
  • tests/ErrorsTraitTest.php (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/ErrorsTraitTest.php (2)
src/ErrorsTrait.php (4)
  • __construct (20-23)
  • getErrors (32-35)
  • getHtmlErrors (50-53)
  • hasError (58-61)
src/ErrorsCollection.php (1)
  • __construct (26-30)
src/ErrorsTrait.php (1)
src/ErrorsCollection.php (3)
  • ErrorsCollection (14-201)
  • toArray (186-189)
  • getHtml (101-106)
src/ErrorsCollection.php (1)
src/UnsetErrorException.php (1)
  • UnsetErrorException (7-10)
tests/ErrorsCollectionTest.php (2)
src/ErrorsCollection.php (10)
  • ErrorsCollection (14-201)
  • add (125-150)
  • offsetGet (50-53)
  • offsetUnset (73-76)
  • isEmpty (83-86)
  • clear (91-94)
  • getHtml (101-106)
  • count (155-158)
  • toArray (186-189)
  • toJson (196-199)
src/UnsetErrorException.php (1)
  • UnsetErrorException (7-10)
🪛 PHPMD (2.15.0)
src/ErrorsTrait.php

42-42: Avoid unused parameters such as '$err_str'. (Unused Code Rules)

(UnusedFormalParameter)

src/ErrorsCollection.php

73-73: Avoid unused parameters such as '$offset'. (Unused Code Rules)

(UnusedFormalParameter)

🔇 Additional comments (16)
composer.json (2)

16-16: PHP version bump looks good and aligns with modernization goals.

The update from PHP 5.6 to 8.3 is a significant modernization step that enables the use of modern PHP features like enums, typed properties, and strict typing seen throughout the codebase.


30-34: Good addition of autoload-dev section for test namespace.

The PSR-4 autoloading configuration for tests aligns well with the namespace changes in the test files.

.github/workflows/on-pull-request.yml (1)

15-16: Workflow update aligns well with the PHP version bump.

Testing both PHP 8.3 (minimum required) and 8.4 (latest stable) provides appropriate coverage for the modernized codebase.

src/ParamsMode.php (1)

1-25: Excellent modernization using PHP 8.1+ enums.

The ParamsMode enum is a great replacement for what were likely integer constants or magic numbers. The strict typing declaration, integer backing, and clear documentation make this a solid implementation that leverages modern PHP features.

src/ErrorsTrait.php (3)

15-15: Good addition of strict typing to the errors property.

The typed property declaration ErrorsCollection $errors improves type safety and aligns with modern PHP practices.


32-34: Approve the improved method signature with union return type.

The addition of parameter and return type hints improves code clarity and type safety. The parameter name change from $ashtml to $asHTML follows proper camelCase convention.


50-50: Good addition of return type declarations.

The explicit return type declarations for getHtmlErrors(): string and hasError(): bool improve type safety and code clarity.

Also applies to: 58-58

tests/ErrorsTraitTest.php (3)

3-3: Namespace update aligns with autoload-dev configuration.

The namespace change from Imponeer\Tests\ObjectErrors to Imponeer\ObjectErrors\Tests is consistent with the PSR-4 autoloading configuration added to composer.json.


25-25: Good addition of void return types to test methods.

The explicit void return type declarations modernize the test code and improve type safety.

Also applies to: 56-56, 66-66


29-53: Good removal of PHPUnit compatibility checks.

Removing the conditional checks for assertIsString and assertIsBool methods simplifies the code since PHPUnit versions compatible with PHP 8.3+ will have these methods available.

src/ErrorsCollection.php (4)

7-14: Modern interface implementation looks good.

The replacement of Serializable with Stringable and the addition of JsonException import align well with PHP 8.3+ best practices.


26-30: Excellent use of modern PHP features.

The constructor property promotion with readonly modifier is a clean approach for immutable configuration.


73-73: PHPMD warning can be safely ignored.

The $offset parameter is required by the ArrayAccess interface. The never return type correctly indicates this method always throws an exception.


196-199: Good improvement in error handling.

Using JSON_THROW_ON_ERROR flag makes JSON encoding failures explicit, which is much better than silent failures.

tests/ErrorsCollectionTest.php (2)

148-175: Excellent modernization of data providers.

Using Generator with descriptive yield keys and leveraging ParamsMode::cases() makes the tests more maintainable and readable.

Also applies to: 207-214


15-205: Test modernization is comprehensive and well-executed.

The addition of strict typing, use of the ParamsMode enum, and improved assertions make the tests more robust and maintainable.

Comment thread composer.json
],
"type": "library",
"require-dev": {
"phpunit/phpunit": "^5.2|^7.0|^8.0",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Update PHPUnit version constraint for PHP 8.3+ compatibility.

The current PHPUnit constraint ^5.2|^7.0|^8.0 includes very old versions that may not be compatible with PHP 8.3. PHPUnit 5.2 was released in 2016 and doesn't support PHP 8.3.

Update the PHPUnit constraint to support modern PHP versions:

-		"phpunit/phpunit": "^5.2|^7.0|^8.0",
+		"phpunit/phpunit": "^9.5|^10.0|^11.0",

Let me verify the PHPUnit version compatibility:


🌐 Web query:

What are the PHP version requirements for PHPUnit versions 5.2, 7.0, 8.0, 9.5, 10.0, and 11.0?

💡 Result:

Here are the PHP version requirements for the specified PHPUnit versions:

PHPUnit Version PHP Compatibility
5.2 PHP 5.6 - PHP 7.1
7.0 PHP 7.1 - PHP 7.3
8.0 PHP 7.2 - PHP 7.4
9.5 PHP 7.3 - PHP 8.0
10.0 PHP 8.1 or later
11.0 PHP 8.2 or later

For detailed information on supported versions, you can refer to the official PHPUnit supported versions page. (phpunit.de)

Citations:


Update PHPUnit constraint for PHP 8.3+ compatibility

The existing constraint

"phpunit/phpunit": "^5.2|^7.0|^8.0",

only covers up to PHP 8.0 and includes EOL PHPUnit versions. To ensure coverage on PHP 8.3 (and modern PHP releases) while still testing on PHP 7.3/7.4 if needed, bump to:

File: composer.json
Line: 11

-    "phpunit/phpunit": "^5.2|^7.0|^8.0",
+    "phpunit/phpunit": "^9.5|^10.0|^11.0",
  • ^9.5 → supports PHP 7.3–8.0
  • ^10.0 → supports PHP 8.1+
  • ^11.0 → supports PHP 8.2+ (and therefore PHP 8.3)
🤖 Prompt for AI Agents
In composer.json at line 11, update the PHPUnit version constraint from
"^5.2|^7.0|^8.0" to include modern supported versions for PHP 8.3 and above.
Replace it with "^9.5|^10.0|^11.0" to cover PHPUnit versions compatible with PHP
7.3 through PHP 8.3+, ensuring testing compatibility with current and future PHP
releases.

Comment thread src/ErrorsTrait.php
Comment on lines +42 to 45
public function setErrors(string $err_str): void
{
call_user_func_array([$this->errors, 'add'], func_get_args());
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix misleading parameter declaration in setErrors method.

The method signature declares string $err_str but the implementation uses func_get_args() to accept multiple arguments, making the parameter declaration misleading.

Consider using variadic parameters for clarity:

-	public function setErrors(string $err_str): void
+	public function setErrors(string ...$err_strs): void
 	{
-		call_user_func_array([$this->errors, 'add'], func_get_args());
+		call_user_func_array([$this->errors, 'add'], $err_strs);
 	}

Or even better, use the spread operator:

-	public function setErrors(string $err_str): void
+	public function setErrors(string ...$err_strs): void
 	{
-		call_user_func_array([$this->errors, 'add'], func_get_args());
+		$this->errors->add(...$err_strs);
 	}
🧰 Tools
🪛 PHPMD (2.15.0)

42-42: Avoid unused parameters such as '$err_str'. (Unused Code Rules)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In src/ErrorsTrait.php around lines 42 to 45, the setErrors method declares a
single string parameter but internally accepts multiple arguments using
func_get_args(), causing a mismatch. Change the method signature to use a
variadic parameter (e.g., setErrors(string ...$err_str): void) to clearly
indicate it accepts multiple string arguments, and update the implementation to
use the variadic parameter directly instead of func_get_args().

Comment thread src/ErrorsCollection.php
if (isset($err_data[1]) && ($err_data[1] !== false)) {
$err_data[0] = sprintf("[%s] %s", $err_data[1], $err_data[0]);
}
$this->errors[] = $err_data[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add string cast for consistency.

Other modes cast error data to string, but Mode2AsPrefix doesn't. For consistency and type safety, consider casting here as well.

-                $this->errors[] = $err_data[0];
+                $this->errors[] = (string) $err_data[0];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$this->errors[] = $err_data[0];
$this->errors[] = (string) $err_data[0];
🤖 Prompt for AI Agents
In src/ErrorsCollection.php at line 144, the error data added to the errors
array is not cast to a string, unlike other modes. To maintain consistency and
type safety, cast $err_data[0] to a string before adding it to $this->errors by
explicitly converting it using (string).

@MekDrop MekDrop merged commit 4aa06d9 into imponeer:main Jul 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bump min PHP to 8.3

1 participant