Skip to content

Fix PHPStan errors and code style#2

Merged
smnandre merged 1 commit intomainfrom
fix/phpstan-and-cs
Mar 20, 2026
Merged

Fix PHPStan errors and code style#2
smnandre merged 1 commit intomainfrom
fix/phpstan-and-cs

Conversation

@smnandre
Copy link
Owner

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 focuses on enhancing code quality and reliability by resolving static analysis issues identified by PHPStan and improving code style. The changes ensure more consistent data handling, particularly with array parameters, and refine the logic for processing categories in the PageSpeed API client, leading to a more robust and maintainable codebase.

Highlights

  • Code Style: Standardized spacing around if conditions in src/Analysis.php for improved readability and consistency.
  • PHPStan Error Fixes: Addressed static analysis errors by ensuring array values are properly handled and passed as numerically indexed arrays in src/Analysis/AuditRef.php and src/Analysis/ConfigSettings.php.
  • Category Handling Refinement: Improved the analyse method in src/PageSpeedApi.php to robustly process and resolve categories, including adding a PHPDoc type hint for better type safety.
  • Redundant Assertion Removal: Removed an unnecessary Assert::allIsInstanceOf call in src/Analysis/CategoryResult.php.

🧠 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.

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.

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.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (60151ef) to head (32db0ba).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##                main        #2   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity        51        52    +1     
===========================================
  Files             13        13           
  Lines            264       268    +4     
===========================================
+ Hits             264       268    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@smnandre smnandre merged commit e860a74 into main Mar 20, 2026
4 checks passed
@smnandre smnandre deleted the fix/phpstan-and-cs branch March 20, 2026 00:54
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 aims to fix PHPStan errors and improve code style. The changes are generally positive and improve code quality. However, I've identified a regression in the category processing logic where de-duplication of categories was inadvertently removed. I've also found a minor performance improvement opportunity. My review includes a specific suggestion to address these points.

Comment on lines +56 to 69
$resolvedCategories = [];
foreach ($categories as $category) {
if ($category instanceof Category) {
$resolvedCategories[] = $category;
} else {
if (null === Category::tryFrom($category)) {
throw new \InvalidArgumentException(sprintf('Invalid category "%s" provided.', $category));
}
$categories[$i] = Category::from($category);
$resolvedCategories[] = Category::from($category);
}
}
if([] === $categories = array_unique($categories)) {
$categories = Category::cases();
if ([] === $resolvedCategories) {
$resolvedCategories = Category::cases();
}

Choose a reason for hiding this comment

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

high

This refactoring is cleaner, but it has two issues. First, it has removed the de-duplication of categories that array_unique provided, which could lead to sending duplicate categories in the API request. Second, there's a small inefficiency where Category::tryFrom is checked and then Category::from is called. The suggestion below addresses both points by re-introducing array_unique and reusing the result of tryFrom.

        $resolvedCategories = [];
        foreach ($categories as $category) {
            if ($category instanceof Category) {
                $resolvedCategories[] = $category;
            } else {
                $enumCase = Category::tryFrom($category);
                if (null === $enumCase) {
                    throw new \InvalidArgumentException(sprintf('Invalid category "%s" provided.', $category));
                }
                $resolvedCategories[] = $enumCase;
            }
        }

        $resolvedCategories = array_values(array_unique($resolvedCategories));
        if ([] === $resolvedCategories) {
            $resolvedCategories = Category::cases();
        }

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