Looking to hire Laravel developers? Try LaraJobs

laravel-ai-review maintained by abdur-rahaman

Description
AI-powered Laravel code review package — detect bugs, security vulnerabilities, suggest refactoring, generate PHPUnit tests, and review GitHub pull requests.
Author
Last update
2026/11/30 19:50 (dev-main)
License
Links
Downloads
1

Comments
comments powered by Disqus

Laravel AI Review

AI-powered code review for Laravel applications

Latest Version on Packagist License

abdur-rahaman/laravel-ai-review analyzes your Laravel code with modern LLMs (OpenAI, Azure OpenAI, Anthropic Claude, or local Ollama models). It detects bugs, security vulnerabilities, performance issues, suggests refactorings, generates PHPUnit/Pest tests, and can automatically review GitHub pull requests.


Features

Feature Description
Code Analysis Deep review of PHP/Laravel code for bugs, logic errors, and style issues
Security Scanning Detects mass assignment, SQL injection, XSS, hardcoded secrets, missing auth, etc.
Refactoring Suggestions SOLID, clean code, and Laravel-idiomatic improvements
Test Generation Auto-generate PHPUnit or Pest tests for any class
GitHub PR Reviews Comment on pull requests with AI findings (CLI + webhook)
Multi-provider OpenAI, Azure OpenAI, Anthropic, Ollama
Artisan Commands Simple CLI interface
Facade API Use AiReview::analyze() anywhere in your app

Requirements

  • PHP 8.1+
  • Laravel 9, 10, 11, 12, or 13
  • An API key for at least one supported AI provider

Installation

composer require abdur-rahaman/laravel-ai-review

Publish the config:

php artisan vendor:publish --tag=ai-review-config

Add your API key to .env:

# Required for OpenAI (default)
OPENAI_API_KEY=sk-...

# Optional overrides
AI_REVIEW_PROVIDER=openai          # openai | azure | anthropic | ollama
AI_REVIEW_MODEL=gpt-4o
AI_REVIEW_MAX_TOKENS=4096
AI_REVIEW_TEMPERATURE=0.2

# GitHub integration (for PR reviews)
GITHUB_TOKEN=ghp_...
GITHUB_WEBHOOK_SECRET=your-webhook-secret

Usage

1. Analyze a single file

php artisan ai-review:analyze app/Models/User.php
php artisan ai-review:analyze app/Http/Controllers/PostController.php --format=markdown --save

2. Scan a directory / whole app

php artisan ai-review:scan
php artisan ai-review:scan app/Http/Controllers --save
php artisan ai-review:scan app --exclude=vendor --exclude=storage

3. Generate tests

php artisan ai-review:generate-tests app/Services/OrderService.php
php artisan ai-review:generate-tests app/Models/User.php --framework=pest --save

4. Review a GitHub Pull Request

php artisan ai-review:review-pr your-org your-repo 42
php artisan ai-review:review-pr your-org your-repo 42 --comment
php artisan ai-review:review-pr your-org your-repo 42 --request-changes

5. GitHub Webhook (automatic PR reviews)

  1. In your GitHub repository go to Settings → Webhooks → Add webhook
  2. Payload URL: https://your-app.com/ai-review/webhook/github
  3. Content type: application/json
  4. Secret: the value of GITHUB_WEBHOOK_SECRET
  5. Events: select Pull requests

The package will automatically analyze opened/updated PRs and post a review comment.


Programmatic API

use AbdurRahaman\LaravelAiReview\Facades\AiReview;
use AbdurRahaman\LaravelAiReview\Services\CodeAnalyzer;
use AbdurRahaman\LaravelAiReview\Services\TestGenerator;

// Via Facade
$result = AiReview::analyze(file_get_contents('app/Models/User.php'), 'User.php');
$result = AiReview::analyzeFile(app_path('Models/User.php'));
$scan   = AiReview::scan(app_path());

// Via dependency injection
public function __construct(
    private CodeAnalyzer $analyzer,
    private TestGenerator $tests,
) {}

public function review()
{
    $analysis = $this->analyzer->analyzeFile(app_path('Http/Controllers/OrderController.php'));

    // $analysis structure:
    // [
    //   'summary'     => '...',
    //   'score'       => 78,
    //   'issues'      => [ ['type' => 'bug', 'severity' => 'high', ...], ... ],
    //   'refactoring' => [ ... ],
    //   'security'    => [ ... ],
    // ]

    $generated = $this->tests->generateForFile(app_path('Services/PaymentService.php'), 'pest');
}

Configuration

See config/ai-review.php for all options. Key sections:

  • provider – which AI backend to use
  • analysis – max tokens, file size limits, excluded directories, severity filters
  • github – token, webhook secret, auto-comment behaviour
  • prompts – fully customizable system & user prompts

Output Formats

Format Flag Description
console --format=console Colored terminal output (default)
markdown --format=markdown GitHub-flavored Markdown
json --format=json Machine-readable JSON
html --format=html Standalone HTML report

Reports can be saved under storage/app/ai-reviews/ with --save.


Supported AI Providers

Provider Env vars Notes
OpenAI OPENAI_API_KEY, AI_REVIEW_MODEL Default, best quality
Azure AZURE_OPENAI_* Enterprise deployments
Anthropic ANTHROPIC_API_KEY Claude 3.5 Sonnet recommended
Ollama OLLAMA_BASE_URL, AI_REVIEW_OLLAMA_MODEL Fully local / offline

Testing the Package

composer test

Security

If you discover any security-related issues in the package itself, please email the maintainer. Never commit real API keys or GitHub tokens.


License

The MIT License (MIT). See LICENSE for details.


Credits