Add Laravel Catch Block Rule for PHP#1
Conversation
- 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`.
|
👋 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 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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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`.
This PR adds a new code quality check for Laravel PHP files. It parses PHP files using an AST parser to identify
catchblocks. Specifically, it enforces thatcatchblocks in Laravel application files (detected byapp/in path) must call thereport()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