Skip to content

Migrate to php82 with rector - #64

Open
fadrian06 wants to merge 19 commits into
leafsphp:v5.xfrom
fadrian06:migrate-to-php82-with-rector
Open

fadrian06 wants to merge 19 commits into
leafsphp:v5.xfrom
fadrian06:migrate-to-php82-with-rector

Conversation

@fadrian06

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce? (pls check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe below

Description

image
➜ php -a                                                                                                                                            
Interactive shell                                                                                                                                   

php > use Leaf\App;                                                                                                                                 php > var_dump(class_exists(App::class));                                                                                                           php shell code:1:                                                                                                                                   
bool(false)                                                                                                                                         
php > use Leaf\Billing\Tier;                                                                                                                        php > $tier = $subscription['tier'] ?? null;                                                                                                        php > var_dump($tier instanceof Tier);                                                                                                              php shell code:1:                                                                                                                                   
bool(false)                                                                                                                                         
php > foreach ([] as $item) {} 

All refactors were tested in interactive shell.

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Replace hardcoded class strings and fully qualified names with ::class
syntax and add missing use statements. This improves maintainability
and enables better static analysis and IDE support.
Replace the manual isset check and assignment with the null
coalescing assignment operator. This change simplifies the logic and
improves code readability by using modern PHP syntax.
Update the array_map call to use the first-class callable syntax
introduced in PHP 8.1. This improves code readability and allows
for better static analysis compared to using string-based callbacks.
Implement the Stringable interface and add a string return type hint
to the __toString method. This ensures compatibility with PHP 8.0+
and explicitly defines the class's string representation behavior.
Update catch statements to use non-capturing catches. This removes
unused variables where the exception object is not required for
the error handling logic, following PHP 8.0+ syntax.
Replace traditional anonymous functions with arrow functions in the
UsesRoles trait and auth helper. This modernization reduces code
verbosity and improves readability for simple return statements.
Simplify the return statement in the subscription method by using the
shorthand ternary operator (?:). This change removes the redundant
reference to the subscription property, making the code cleaner and
more concise.
Update the table creation logic to use a match expression instead of
a switch statement. This modernizes the code using PHP 8 features
and improves readability by removing redundant break statements.
Remove setAccessible(true) calls from ReflectionProperty instances in
google.test.php and roles.test.php. These calls are no longer required
in modern PHP versions, and removing them simplifies the test code.
…ions

Add the dead-code rule set to alchemy configuration to improve code
quality and maintainability. Remove explicit null assignments from
class properties in Auth and UsesSubscriptions because they are
redundant in PHP and flagged as dead code.
Remove redundant @return and @PARAM tags from PHPDoc blocks across the
codebase. These tags are unnecessary because the methods already use
native PHP type hints. This cleanup reduces documentation noise and
improves maintainability.
Remove the explicit count check before iterating over hidden fields.
PHP's foreach handles empty arrays natively, making the check
unnecessary. This simplifies the logic and reduces nesting levels.
Remove the try-catch block that only re-throws exceptions to simplify
the code and allow the test runner to handle errors naturally.
Remove the empty __construct method from the FakeBillingDriver class
to clean up the test mock as it performs no initialization logic.
Remove the try-catch block in the beforeAll hook that was simply
rethrowing exceptions. This simplifies the database initialization
logic for tests without changing the error handling behavior.
Remove the unused $testUser variable from the logout closure in
tests/user.test.php to clean up the test code and avoid unnecessary
variable capturing.
Delete the phpstan-baseline.neon file to enforce stricter static
analysis. This ensures that type errors in Auth.php and User.php are
no longer ignored, promoting better code quality and type safety.
Ensure consistent formatting by adding a space after the fn keyword
in arrow functions. This aligns the code with PSR-12 standards and
improves overall code style consistency.
Create phpstan-baseline.neon to ignore existing static analysis errors.
This ensures that future static analysis runs only report new issues.
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.

1 participant