Skip to content

Add Laravel Catch Block Rule for PHP#1

Draft
google-labs-jules[bot] wants to merge 2 commits intomainfrom
laravel-catch-block-rule-18213852287861914688
Draft

Add Laravel Catch Block Rule for PHP#1
google-labs-jules[bot] wants to merge 2 commits intomainfrom
laravel-catch-block-rule-18213852287861914688

Conversation

@google-labs-jules
Copy link

This PR adds a new code quality check for Laravel PHP files. It parses PHP files using an AST parser to identify catch blocks. Specifically, it enforces that catch blocks in Laravel application files (detected by app/ in path) must call the report() helper function. If the call is missing, it is flagged as a Critical issue. If the call exists but is not the first statement in the catch block, it is flagged as a Medium risk. This ensures proper error reporting practices in Laravel applications.


PR created automatically by Jules for task 18213852287861914688 started by @ngoyal16

- Implemented `LaravelCatchBlockRule` in `analyzers/php/laravel_catch.go` using AST parsing.
- Added dependency `github.com/z7zmey/php-parser` for robust PHP parsing.
- Updated `PHPAnalyzer` in `analyzers/php/php.go` to include the new rule and process its findings.
- The rule detects missing `report()` calls in catch blocks (Critical) and `report()` calls that are not the first statement (Medium) in Laravel app files.
- Added comprehensive tests in `analyzers/php/laravel_catch_test.go`.
@google-labs-jules
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

// Create a basic analysis object if we only have other issues
analysis = &models.PHPFileAnalysis{
Path: path,
TotalBytes: len(content),
Copy link
Contributor

Choose a reason for hiding this comment

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

add details like how many try/catch function found without report, or not in the firstline with detail line number so that it can report in the codequality report.

Copy link
Author

Choose a reason for hiding this comment

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

I have updated the analysis to track the number of catch blocks missing report() or having it misplaced. These statistics are now included in the PHPFileAnalysis struct (which goes into the JSON artifact) and are also printed in the console output for better visibility. The individual issues with detailed line numbers were already present and are preserved.

- Implemented `LaravelCatchBlockRule` in `analyzers/php/laravel_catch.go` using AST parsing.
- Added dependency `github.com/z7zmey/php-parser` for robust PHP parsing.
- Updated `PHPAnalyzer` in `analyzers/php/php.go` to include the new rule and process its findings.
- The rule detects missing `report()` calls in catch blocks (Critical) and `report()` calls that are not the first statement (Medium) in Laravel app files.
- Added metrics `CatchBlocksMissingReport` and `CatchBlocksMisplacedReport` to `PHPFileAnalysis` model and output.
- Added comprehensive tests in `analyzers/php/laravel_catch_test.go`.
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