Skip to content

Migrate to php82 with rector - #64

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

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

Conversation

@fadrian06

@fadrian06 fadrian06 commented Oct 21, 2026 •

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

➜ 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 baseline file to enforce strict type checking and address
previously ignored errors in Auth and User classes.
@fadrian06
fadrian06 force-pushed the migrate-to-php82-with-rector branch from b08c616 to 89611e4 Compare October 21, 2026 04:02
Add missing spaces after the 'fn' keyword in anonymous functions to
adhere to project coding standards and improve readability.
Update exception handling across Auth and User classes to pass the
original exception code and the previous exception instance to the
new Exception constructor. This ensures that stack traces are not
lost during re-throwing.

Additionally, add 'code-quality' to the alchemy.yml configuration
to enforce better static analysis standards.
Use (bool) instead of !! for better readability and to clearly express
the intent of converting the email verification timestamp to a boolean
value.
Add declare(strict_types=1) to ensure type safety and prevent implicit
type coercion, improving code reliability and maintainability.
Improve code readability and maintainability by using descriptive variable
names in catch blocks. Additionally, add 'coding-style' to the alchemy
analysis configuration to enforce these standards.
Add a blank line between static properties in FakeBillingDriver to
adhere to PSR coding standards and improve code structure.
Enforce strict return types across the codebase to improve code
predictability and satisfy static analysis requirements. This change
updates middleware callbacks, class methods, and test closures to
explicitly declare a void return type.
Update method signatures across Auth and User classes to use the 'static'
return type hint instead of docblock annotations. This improves type
safety, enables better IDE autocompletion, and ensures consistency with
modern PHP standards for fluent interfaces.
Update method signatures across Auth, Model, and User classes to include
native PHP type hints. This improves code readability, enables better
static analysis, and ensures type safety throughout the authentication
layer.
Add explicit return type hints to closures across the codebase to
improve static analysis, code clarity, and ensure type safety for
callback functions.
Remove an unnecessary empty line in the __call method docblock to
improve code readability and maintain consistency with project
coding standards.
Add return type declarations to `find`, `createUserFor`, and
`verifyToken` methods to improve code clarity, static analysis, and
type safety.

refactor(tests): add type hint to deleteUser table parameter

Update the `deleteUser` helper function in Pest to explicitly type the
`$table` parameter as a string, ensuring consistency with expected
database operations.
- Update Auth::find check to verify instance of User instead of truthy
- Update User methods to check for empty array instead of truthy
- Ensure consistent validation logic to prevent unexpected behavior
 when dealing with falsy return values from the data layer.
Update alchemy.yml to include named-args in the refactoring rules.
Apply named arguments to Auth and User classes to clarify the intent
of boolean flags and configuration parameters, making the codebase
easier to maintain and understand.
Add `declare(strict_types=1);` to all core Auth files to enforce strict
type checking and prevent unexpected type coercion. Update alchemy.yml
to include additional rector rules for improved code quality and
automated refactoring.
- Add return type hint 'Auth' to the auth() function.
- Use 'static' keyword for the closure to prevent unnecessary binding.
- Simplify conditional check and clean up docblock for better readability.
Consolidate multi-line docblocks into single-line format and ensure
consistent type hinting across class properties to improve code
readability and maintainability.
Change middleware closures to static to prevent binding to the current
class instance, reducing memory usage and improving performance by
avoiding unnecessary object context.
Update the env method signature to use the 'mixed' type for the default
parameter and return type to improve code clarity and leverage modern
PHP type safety features.
Add trailing commas to improve code readability and ensure cleaner git
diffs for future modifications to these structures.
Update the config method signature to use explicit mixed types for better
static analysis and consistency. Add an explicit return null to ensure
the method adheres to the defined return type contract.
@fadrian06
fadrian06 marked this pull request as draft October 21, 2026 05:49
Update method signatures to include explicit return types for better
type safety, improved IDE autocompletion, and cleaner documentation.
Additionally, simplify DocBlock formatting to reduce verbosity.
Consolidate multi-line docblocks into single-line summaries and remove
redundant parameter descriptions to improve code readability and reduce
vertical clutter.
Refactor docblocks to single-line format to improve code readability and
reduce vertical whitespace in the Auth Model class.
Remove the ReturnTypeWillChange attribute from the __toString method
as the method now explicitly declares a string return type, making
the attribute redundant and cleaning up the codebase.
Update method signatures in the User class to include explicit return
types and parameter types. This improves code readability, enables
better static analysis, and ensures type safety across the
authentication module.
Remove redundant multi-line docblock descriptions and unnecessary type
annotations to reduce code verbosity and improve readability.
Remove redundant empty lines and unnecessary return type annotations in
docblocks to improve code readability and maintain consistency with
the project's documentation style.
Remove redundant docblock lines and consolidate single-line comments to
improve code readability and maintain consistency across the trait.
@fadrian06
fadrian06 marked this pull request as ready for review October 21, 2026 06:10
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