-
Notifications
You must be signed in to change notification settings - Fork 1
(Changed) Update to PHP 8.3 and Enforce Explicit Type Declarations #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Remove references to PHP 8.2 in workflows and configuration files - Update composer constraints to reflect the new requirement - Align development and production environments with PHP 8.3 BREAKING CHANGE: Environments must now use PHP 8.3 or higher.
- Introduce explicit type declarations for clarity and type safety - Remove redundant comments to streamline the code - Correct formatting for improved readability and consistency These changes align the codebase with established style guidelines, making it easier to maintain and collaborate on.
📝 WalkthroughWalkthroughThis pull request updates the PHP version used throughout the project from 8.2 to 8.3. The changes include modifications to GitHub Actions workflows (Codecov and CI), configuration files for static analysis and refactoring tools, and documentation updates to reflect the new PHP version requirement. Additionally, various source and test files have updated type declarations for constants to enforce stricter type safety. No alterations to the core business logic or control flow were made. Changes
Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 PHPStan (2.0.3)/bin/bash: line 1: /vendor/bin/phpstan: No such file or directory Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
|
Changelog updates: 🔄 2025-02-12 *Changed
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
Auto-approved PR |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
=========================================
Coverage 98.80% 98.80%
Complexity 26 26
=========================================
Files 1 1
Lines 84 84
=========================================
Hits 83 83
Misses 1 1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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 (7)
tests/Unit/TrimTest.php (1)
71-74: Consider removing redundant data provider annotation.Since you're using PHP 8+ attributes, the docblock
@dataProviderannotation is redundant. The#[DataProvider]attribute is sufficient.- /** - * @dataProvider trimDataProvider - */ #[DataProvider('trimDataProvider')]Additionally, consider using
stringinstead ofmixedfor the$expectedparameter since all test cases return strings:- public function testTrim(string $input, string $characters, mixed $expected): void + public function testTrim(string $input, string $characters, string $expected): voidtests/Unit/StrReplaceTest.php (1)
17-17: Consider using more specific array type hints.While adding explicit types improves type safety, consider using PHP 8.3's new array shape syntax for more precise type declarations:
- private const array SEARCH = [ + private const array{0: string, 1: string, 2: string} SEARCH = [- private const array REPLACE = [ + private const array{0: string, 1: string, 2: string} REPLACE = [Also applies to: 19-19, 25-25, 31-31
src/UnicodeMappings.php (1)
28-28: Enhance type safety with array shape type hint.Consider using PHP 8.3's array shape syntax to explicitly declare the key-value types:
- private const array UTF8_ANSI2 = [ + private const array<string, string> UTF8_ANSI2 = [tests/Unit/Utf8AnsiTest.php (1)
17-17: Enhance type safety and maintain consistency.
- Use more specific array type hint for better type safety:
- private const array UTF8_TO_ANSI_MAP = [ + private const array<string, string> UTF8_TO_ANSI_MAP = [
- Consider extracting this mapping to a shared constant since it duplicates
UTF8_ANSI2fromUnicodeMappingstrait.src/AccentNormalization.php (1)
29-29: Consider using more specific array type declarations.While the
arraytype declaration is correct, you could leverage PHP 8.3's type system more effectively by using a more specific type hint.Apply this diff to improve type specificity:
- private const array REMOVE_ACCENTS_FROM = [ + private const array<int, string> REMOVE_ACCENTS_FROM = [ - private const array REMOVE_ACCENTS_TO = [ + private const array<int, string> REMOVE_ACCENTS_TO = [Also applies to: 273-273
composer.json (1)
45-45: Simplify PHP version constraint.The current constraint
">=8.3.0|>=8.4.0"can be simplified to just">=8.3.0"since it already covers PHP 8.4 and future versions.- "php": ">=8.3.0|>=8.4.0" + "php": ">=8.3.0"src/StringManipulation.php (1)
197-197: Fix parameter comment alignment.The parameter comments are not aligned correctly according to PER Coding Style 2.0 guidelines.
- * an empty string. + * an empty string.- * the expected format of the date. + * the expected format of the date.Also applies to: 285-285
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis
[notice] 197-197: src/StringManipulation.php#L197
Parameter comment not aligned correctly; expected 27 spaces but found 28
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
.github/workflows/codecov.yml(1 hunks).github/workflows/php.yml(1 hunks).phan/config.php(1 hunks)README.md(1 hunks)composer.json(1 hunks)phpstan.neon(1 hunks)rector.php(1 hunks)src/AccentNormalization.php(2 hunks)src/StringManipulation.php(2 hunks)src/UnicodeMappings.php(1 hunks)tests/Unit/IsValidDateTest.php(2 hunks)tests/Unit/NameFixTest.php(1 hunks)tests/Unit/SearchWordsTest.php(1 hunks)tests/Unit/StrReplaceTest.php(1 hunks)tests/Unit/TrimTest.php(1 hunks)tests/Unit/Utf8AnsiTest.php(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- README.md
- phpstan.neon
- tests/Unit/NameFixTest.php
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.php`: Review PHP code for adherence to PER Coding Styl...
**/*.php: Review PHP code for adherence to PER Coding Style 2.0 guidelines. Ensure proper namespace usage, code organisation, and separation of concerns. Verify that SOLID principles are followed and encourage FOOP techniques—such as employing immutable data, pure functions, and functional composition—to improve maintainability, testability, and performance.
src/UnicodeMappings.phptests/Unit/TrimTest.phptests/Unit/Utf8AnsiTest.phptests/Unit/SearchWordsTest.phprector.phptests/Unit/IsValidDateTest.phptests/Unit/StrReplaceTest.phpsrc/AccentNormalization.phpsrc/StringManipulation.php
🪛 GitHub Check: Codacy Static Code Analysis
src/StringManipulation.php
[notice] 197-197: src/StringManipulation.php#L197
Parameter comment not aligned correctly; expected 27 spaces but found 28
[notice] 285-285: src/StringManipulation.php#L285
Parameter comment not aligned correctly; expected 23 spaces but found 24
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: guardrails/scan
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: build (8.4)
- GitHub Check: build (8.3)
🔇 Additional comments (9)
tests/Unit/TrimTest.php (3)
1-9: Well-structured file with proper declarations!The file follows PSR standards with strict typing enabled and proper namespace organization.
11-16: Excellent class declaration with proper metadata!The class is correctly marked as final and includes proper PHPDoc annotations for internal usage and coverage tracking.
18-18: Perfect type declaration for the constant!The explicit string type declaration aligns with PHP 8.3's enhanced type system and improves code clarity.
rector.php (1)
46-46: LGTM! PHP 8.3 configuration is properly updated.The Rector configuration has been correctly updated to PHP 8.3, including all necessary rule sets and level sets.
Also applies to: 51-51, 56-56
tests/Unit/SearchWordsTest.php (1)
17-17: LGTM! Excellent use of PHP 8.3's typed class constant.The explicit string type declaration enhances type safety and code clarity.
tests/Unit/IsValidDateTest.php (1)
18-20: LGTM! Well-structured typed constants.The explicit string type declarations for date format constants improve type safety and self-documentation.
.phan/config.php (1)
57-58: LGTM! Appropriate Phan configuration update.The target PHP version update aligns correctly with the project's new PHP 8.3 requirement.
.github/workflows/codecov.yml (1)
12-15: LGTM! PHP 8.3 setup is correctly configured.The PHP version update in the Codecov workflow aligns with the PR objective to upgrade to PHP 8.3.
.github/workflows/php.yml (1)
18-18: LGTM! PHP versions matrix is correctly updated.The CI workflow now appropriately tests against PHP 8.3 and 8.4, aligning with the project's new minimum version requirement while ensuring forward compatibility.
User description
Summary
This merge request updates the project to require PHP 8.3 (removing support for PHP 8.2) and introduces explicit type declarations for constants in both source and test files. These changes improve overall code clarity, enhance performance by leveraging PHP 8.3 optimisations, and streamline maintenance efforts.
Context and Background
Previously, the project allowed PHP 8.2 or higher. With the release and stabilisation of PHP 8.3, it is advantageous to align our configurations, documentation, and tooling to harness newer features and optimisations. Additionally, the codebase relied on docblocks to describe constant types, leading to potential ambiguity in code maintenance.
Problem Description
Solution Description
private const string,private const array). Redundant docblocks are removed, simplifying maintenance and ensuring consistent code expectations.List of Changes
private const string) for constants throughout the codebasePR Type
Enhancement, Bug fix
Description
Update project to require PHP 8.3, removing PHP 8.2 support.
Add explicit type declarations for constants across source and test files.
Update configuration files (e.g.,
.phan/config.php,rector.php) to align with PHP 8.3.Adjust CI workflows and documentation to reflect PHP 8.3 requirement.
Changes walkthrough 📝
5 files
Update Phan configuration to target PHP 8.3Update Rector configuration to PHP 8.3Update CI workflow to use PHP 8.3Remove PHP 8.2 from CI matrixUpdate PHPStan configuration to PHP 8.32 files
Add explicit type declarations for constantsAdd explicit type declarations for constants1 files
Minor formatting adjustments in doc comments6 files
Add explicit type declarations for test constantsAdjust test data for name handlingAdd explicit type declarations for test constantsAdd explicit type declarations for test constantsAdd explicit type declarations for test constantsAdd explicit type declarations for test constants1 files
Update system requirements to PHP 8.31 files
Set minimum PHP requirement to 8.3Summary by CodeRabbit
Chores
Documentation
Tests
Refactor