Skip to content

Improve PHPStan config#230

Merged
BrianHenryIE merged 9 commits into
masterfrom
phpstan
Dec 20, 2025
Merged

Improve PHPStan config#230
BrianHenryIE merged 9 commits into
masterfrom
phpstan

Conversation

@BrianHenryIE

Copy link
Copy Markdown
Owner

Add a GitHub Actions workflow to annotate errors to max level, and fail on the level specified in phpstan.neon (currently level 7).

TODO: modify the badge displayed in the README to be gray with a red X when the workflow is failing. (I have this in another repo somewhere)

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @BrianHenryIE, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the project's static analysis and code quality enforcement by refining the PHPStan configuration and related Composer scripts. It elevates the strictness of PHPStan analysis to its maximum level, integrates automatic code style fixing into the change analysis process, and streamlines the PHPStan setup by removing an unnecessary bootstrap file and configuring error reporting more precisely. These changes lay the groundwork for more robust continuous integration, as indicated by the intent to integrate with GitHub Actions for error annotation.

Highlights

  • Enhanced PHPStan Strictness: The analyze-changes-strict Composer script now uses phpstan analyse --level max for the highest level of static analysis, replacing the previous level 9.
  • Automated Code Fixing: The cs-changes and cs-changes-strict Composer scripts have been updated to automatically run phpcbf (PHP Code Beautifier and Fixer) before phpcs (PHP Code Sniffer), ensuring code style issues are fixed prior to reporting.
  • PHPStan Configuration Refinement: The phpstan.neon configuration now includes reportUnmatchedIgnoredErrors: false to prevent warnings about unused ignored errors, and the phpstanbootstrap.php file, along with its reference, has been removed, simplifying the setup.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/phpstan.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves the PHPStan configuration by updating the analysis level to max, removing an unused bootstrap file, and cleaning up the configuration. It also refactors some composer scripts for running code style checks. The changes are generally good, but there are opportunities to further improve the composer scripts by reducing duplication and simplifying complex shell commands. I've added a couple of suggestions to address this.

Comment thread composer.json
],
"analyze-changes-strict": [
"updated_files=$(echo $(git diff --name-only `git merge-base origin/master HEAD` | grep php | tr '\\n' '\\0' | xargs -0 ls -1df 2>/dev/null)); if [ -n \"$updated_files\" ]; then echo \"Found: $updated_files\"; phpstan analyse --memory-limit=-1 $updated_files --level 9 --verbose || true; else echo \"No modified php files for phpstan.\"; fi;"
"updated_files=$(echo $(git diff --name-only `git merge-base origin/master HEAD` | grep php | tr '\\n' '\\0' | xargs -0 ls -1df 2>/dev/null)); if [ -n \"$updated_files\" ]; then echo \"Found: $updated_files\"; phpstan analyse --memory-limit=-1 $updated_files --level max --verbose || true; else echo \"No modified php files for phpstan.\"; fi;"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This long command to get updated files is repeated in multiple scripts and can be simplified. The part echo $(... | grep php | tr ...) is a complex way to filter for existing PHP files. You can achieve the same result more cleanly using git diff's built-in filtering capabilities.

This simplification can be applied to analyze-changes, analyze-changes-strict, cs-changes, and cs-changes-strict scripts.

          "updated_files=$(git diff --name-only --diff-filter=ACMRTUXB \`git merge-base origin/master HEAD\` -- '**/*.php'); if [ -n \"$updated_files\" ]; then echo \"Found: $updated_files\"; phpstan analyse --memory-limit=-1 $updated_files --level max --verbose || true; else echo \"No modified php files for phpstan.\"; fi;"

Comment thread composer.json
@BrianHenryIE BrianHenryIE changed the base branch from AbstractRenamespacerCommand to master December 20, 2025 08:38
@BrianHenryIE BrianHenryIE merged commit 6dbb917 into master Dec 20, 2025
@BrianHenryIE BrianHenryIE deleted the phpstan branch December 22, 2025 01:58
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