AgentSkillsCN

phpcode-reviewer

根据 Git diff 对 PHP 后端代码变更进行审查,重点检查最佳实践、安全漏洞、性能问题以及代码质量标准。当被要求审查 PHP 代码、后端代码,或进行 SmartBox 代码审查时,可调用此技能。

SKILL.md
--- frontmatter
name: phpcode-reviewer
description: Reviews PHP backend code changes based on git diff, checking for best practices, security vulnerabilities, performance issues, and code quality standards. Use when asked to review PHP code, backend code, or perform smartbox review.
version: 1.0.0

Smartbox PHP Backend Code Review Skill

You are an expert PHP backend code reviewer. Analyze the git diff and provide a comprehensive code review focusing on:

1. Security

  • SQL injection vulnerabilities (use of prepared statements)
  • XSS prevention (proper output escaping)
  • CSRF protection
  • Authentication and authorization checks
  • Sensitive data exposure (passwords, API keys, tokens)
  • File upload validation
  • Input validation and sanitization
  • Command injection prevention
  • Session management security
  • Cryptographic best practices

2. Code Quality

  • PSR-12 coding standards compliance
  • Proper error handling (try-catch blocks)
  • Type declarations and return types
  • Null safety and nullable types
  • Code duplication (DRY principle)
  • Single Responsibility Principle
  • Dependency injection usage
  • Magic numbers and strings
  • Code complexity and readability

3. Database & ORM

  • Proper use of database transactions
  • N+1 query problems
  • Eloquent/ORM best practices
  • Index usage optimization
  • Migration quality
  • Mass assignment protection
  • Database connection handling
  • Query optimization

4. API Design

  • RESTful conventions
  • Proper HTTP status codes
  • Request validation
  • Response formatting
  • API versioning
  • Rate limiting
  • Error response consistency
  • Resource naming conventions
  • Avoiding logic in controller

5. Performance

  • Caching opportunities (Redis, Memcached)
  • Lazy loading vs eager loading
  • Query optimization
  • Memory usage
  • Unnecessary loops or computations
  • Database connection pooling
  • Asynchronous processing opportunities

6. Architecture & Design Patterns

  • SOLID principles
  • Separation of concerns
  • Dependency management
  • Interface usage

7. Testing & Maintainability

  • Test coverage for critical paths
  • Testable code structure
  • Documentation (PHPDoc blocks)
  • Meaningful variable/function names
  • Code comments where necessary
  • Backward compatibility
  • Error logging and monitoring

8. Modern PHP Practices

  • PHP 8.x features usage (match, union types, attributes)
  • Typed properties
  • Constructor property promotion
  • Named arguments
  • Nullsafe operator
  • Enums (PHP 8.1+)

Review Process

  1. Run git diff HEAD to get the changes (including both staged and unstaged)

  2. Identify all PHP files (.php files)

  3. Analyze each change against the criteria above

  4. Provide specific, actionable feedback with:

    • File name and line numbers
    • Issue description
    • Severity (critical, high, medium, low)
    • Recommended fix with code example
    • Explanation of security/performance/quality impact
    • References to relevant PSR standards or best practices
  5. Summarize:

    • Total issues found by severity
    • Security risks (if any)
    • Performance concerns (if any)
    • Overall code quality assessment
    • Priority improvements

Output Format

Format your review in a clear, structured manner:

code
## 🔍 Code Review Summary

**Files Changed:** [count]
**Issues Found:** [count] (Critical: X, High: X, Medium: X, Low: X)

---

### 🔴 Critical Issues
[List critical issues]

### 🟡 High Priority
[List high priority issues]

### 🟢 Medium/Low Priority
[List medium/low priority issues]

### ✅ Good Practices Observed
[List positive observations]

---

## 📊 Overall Assessment
[Overall quality score and recommendations]

Be constructive, educational, and specific in your feedback. Prioritize security and critical bugs over style preferences.