Skip to content

Enhance PHPStan options and fix type-related issues#49

Open
fadrian06 wants to merge 11 commits into
leafsphp:v4.xfrom
fadrian06:fix-phpstan-errors
Open

Enhance PHPStan options and fix type-related issues#49
fadrian06 wants to merge 11 commits into
leafsphp:v4.xfrom
fadrian06:fix-phpstan-errors

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

This pull request focuses on improving type safety and static analysis in the codebase, particularly for the authentication classes. The changes enhance PHPStan integration, clarify property and method types, and improve error reporting and documentation for user-related data.

Static analysis and type safety improvements:

  • Updated phpstan.dist.neon to set a stricter error format, exclude test paths from analysis, and enable additional reporting options for unmatched or uncommented ignores.
  • Improved type annotations for the $db property in Auth (src/Auth.php) to indicate it can be null, and initialized it as such.
  • Added a PHPStan assertion (@phpstan-assert Db $this->db) to the checkDbConnection method in Auth to improve static analysis.

User data and error handling enhancements:

  • Enhanced property and return type annotations for user errors in User (src/Auth/User.php), specifying possible structures for error arrays. [1] [2]
  • Updated the update method in User to specify the expected structure of the $userData parameter, improving clarity for optional fields like email.
  • Added a @property annotation for $email in the User class docblock for better documentation and IDE support.

Minor corrections:

  • Fixed docblock return type in the dbConnection method of Auth for accuracy.
  • Simplified conditional checks in getAuthInfo in User by removing unnecessary null coalescing, as the properties are always initialized.

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

  • Yes
  • No

Copilot AI review requested due to automatic review settings June 21, 2026 23:31

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 improves static analysis/type safety for the authentication package by tightening PHPStan configuration and refining PHPDoc types in Auth and User to better reflect nullable DB state and user/error data structures.

Changes:

  • Updated phpstan.dist.neon to improve output formatting and reporting options, and to exclude tests from analysis.
  • Made Auth::$db explicitly nullable and added a PHPStan assertion in checkDbConnection() to help inference after connection checks.
  • Refined User PHPDoc types for errors and update() input, and simplified getAuthInfo() conditional checks.

Reviewed changes

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

File Description
src/Auth/User.php Tightens PHPDoc for user errors and update payloads; simplifies getAuthInfo() role/permission checks.
src/Auth.php Makes DB property nullable, fixes PHPDoc return formatting, and adds PHPStan assertion for DB connection checks.
phpstan.dist.neon Adjusts PHPStan reporting/options and excludes test paths from analysis.

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

Comment thread src/Auth/User.php
Comment thread src/Auth/User.php
Comment thread src/Auth/User.php
Comment thread src/Auth.php
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