php-code-review
Skill5 starsChanged 10 months agoMITView on GitHub
Comprehensive PHP code review with security analysis, performance optimization, and PSR-12 compliance checking for PHP7/PHP8 projects
1 other project uses a version of this.
Adopted by
Most recently taken up by
- JetBrains/phpstorm-claude-marketplacetheir own version, first seen Feb 23, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- JetBrains/phpstorm-claude-marketplace★ 34same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
38 rules. About 0 are common, 22 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈22
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Automated Security Scan: Use scripts/php-security-scanner.php for initial vulnerability detection
- Distinctive: line 16
Manual Review: Follow the systematic review process outlined below
- Distinctive: line 17
Report Generation: Use the structured output format for consistent documentation
- Very specific: line 34
CamelCase: Use PascalCase for class names (e.g., UserController)
- Very specific: line 42
Verb-Noun Pattern: Start with action word (e.g., validateInput(), processOrder())
- Very specific: line 43
Boolean Methods: Use is/has/can prefix (e.g., isValid(), hasPermission())
- Very specific: line 47
Descriptive: Use meaningful names (e.g., $customerEmail not $e)
- Distinctive: line 66
Typed Properties: Ensure PHP7.4+ if using typed properties
- Distinctive: line 67
Return Type Declarations: Check for PHP7.0+ compatibility
- Very specific: line 72
Undefined Variables: Check for $variable before use
- Very specific: line 73
Array Access: Use isset($array['key']) before accessing
- Very specific: line 74
String Concatenation: Prefer "{$variable}" over "$variable"
- Distinctive: line 81
Switch Statements: Ensure all cases have breaks or returns
- Very specific: line 82
Loop Performance: Use foreach instead of for where possible
- Distinctive: line 85
Try-Catch Blocks: Always catch specific exceptions
- Very specific: line 86
Error Suppression: Never use @ operator
- Distinctive: line 91
Input Sanitization: Never trust user input
- Distinctive: line 92
SQL Injection: Use prepared statements exclusively
- Very specific: line 100
N+1 Problem: Use eager loading (e.g., with('comments'))
- Distinctive: line 101
Query Optimization: Add indexes on frequently queried columns
- Distinctive: line 102
Pagination: Always paginate large datasets
- Very specific: line 108
Generator Functions: Use yield for memory-efficient iteration
- Very specific: line 112
String Operations: Use strpos() instead of preg_match() for simple searches
- Very specific: line 134
Password Security: Use password_hash() and password_verify()
- Distinctive: line 144
Testing: Ensure each branch has test coverage
- Distinctive: line 147
DRY Principle: Don't Repeat Yourself
- Distinctive: line 152
PHPDoc: Document all public methods and classes
- Distinctive: line 153
Type Declarations: Use strong typing where possible
- Distinctive: line 155
README: Keep project documentation updated
- Distinctive: line 161
Code Standards: Run PHP_CodeSniffer with PSR-12
- Distinctive: line 162
Static Analysis: Use PHPStan or Psalm
- Distinctive: line 163
Security Scan: Run security checkers
- Distinctive: line 172
Unit Tests: Ensure adequate coverage (80%+)
- Distinctive: line 173
Integration Tests: Test component interactions
- Distinctive: line 190
Replace Magic Numbers: Use named constants
- Distinctive: line 244
When reviewing code, use the standardized templates:
- Very specific: line 247
Use templates/review-report-template.md which provides:
- Very specific: line 293
Use scripts/php-security-scanner.php for automated security scanning
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PHP Code Review Expert
This skill provides comprehensive PHP code review capabilities, combining automated analysis with expert-level insights for PHP7 and PHP8 development.
Quick Start
- Automated Security Scan: Use
scripts/php-security-scanner.phpfor initial vulnerability detection - Code Style Check: Apply configurations from
references/php-cs-fixer-config.md - Manual Review: Follow the systematic review process outlined below
- Report Generation: Use the structured output format for consistent documentation
Available Resources
- Scripts:
php-security-scanner.php- Automated security vulnerability scanner - References:
php-cs-fixer-config.md- Ready-to-use PHP CS Fixer configurations - Examples:
before-after-refactor.md- Real-world refactoring examples - Templates:
review-report-template.md- Comprehensive review report formatquick-checklist.md- 30-minute quick review checklist
Core Review Areas
1. Naming Conventions Check
Class Naming
- PSR-4 Compliance: Class names must match file names
- CamelCase: Use PascalCase for class names (e.g.,
UserController) - Suffix Patterns:
- Controllers end with
Controller(e.g.,UserController) - Models end with
Modelor use singular nouns (e.g.,User) - Services end with
Service(e.g.,EmailService)
- Controllers end with
Method Naming
- camelCase: Methods use camelCase (e.g.,
getUserName()) - Verb-Noun Pattern: Start with action word (e.g.,
validateInput(),processOrder()) - Boolean Methods: Use is/has/can prefix (e.g.,
isValid(),hasPermission())
Variable Naming
- camelCase: Variables use camelCase (e.g.,
$userName) - Descriptive: Use meaningful names (e.g.,
$customerEmailnot$e) - Constants: UPPER_SNAKE_CASE (e.g.,
MAX_RETRY_COUNT)
Database Naming
- Table Names: snake_case, plural (e.g.,
user_profiles) - Column Names: snake_case (e.g.,
created_at) - Foreign Keys:
{singular_table}_id(e.g.,user_id)
2. Syntax Validation (PHP7 vs PHP8)
PHP8 Features to Embrace
- Union Types:
function process(int|float $value) - Named Arguments:
createUser(name: 'John', email: 'john@example.com') - Null safe Operator:
$user?->profile?->avatar - Match Expression:
match($status) { 1 => 'active', 2 => 'inactive' } - Constructor Property Promotion:
public function __construct(private string $name) - Null Coalescing Assignment:
$user['name'] ??= 'Anonymous'
PHP7 Compatibility
- Typed Properties: Ensure PHP7.4+ if using typed properties
- Return Type Declarations: Check for PHP7.0+ compatibility
- Array Destructuring:
["id" => $userId, "name" => $userName] = $user;
Syntax Pitfalls to Avoid
- Missing Semicolons: Classic error in PHP
- Undefined Variables: Check for
$variablebefore use - Array Access: Use
isset($array['key'])before accessing - String Concatenation: Prefer
"{$variable}"over"$variable"
3. Logic Analysis
Control Flow Issues
- Deep Nesting: Maximum 3 levels, refactor with early returns
- Complex Conditions: Break down complex boolean expressions
- Switch Statements: Ensure all cases have breaks or returns
- Loop Performance: Use
foreachinstead offorwhere possible
Error Handling
- Try-Catch Blocks: Always catch specific exceptions
- Error Suppression: Never use
@operator - Validation: Validate all inputs before processing
- Graceful Degradation: Handle edge cases properly
Security Logic
- Input Sanitization: Never trust user input
- SQL Injection: Use prepared statements exclusively
- XSS Prevention: Escape output with
htmlspecialchars() - CSRF Protection: Implement tokens for state-changing operations
- File Upload: Validate file types and sizes strictly
4. Performance Optimization
Database Queries
- N+1 Problem: Use eager loading (e.g.,
with('comments')) - Query Optimization: Add indexes on frequently queried columns
- Pagination: Always paginate large datasets
- Caching: Cache expensive queries with Redis/Memcached
Memory Management
- Large Arrays: Process in chunks for large datasets
- Unnecessary Variables: Unset large variables after use
- Generator Functions: Use
yieldfor memory-efficient iteration - Object Caching: Reuse objects instead of recreating
Code Efficiency
- String Operations: Use
strpos()instead ofpreg_match()for simple searches - Array Functions: Leverage built-in functions like
array_map(),array_filter() - Early Returns: Reduce nesting and improve readability
- Lazy Loading: Load resources only when needed
5. Security Vulnerabilities
Critical Security Checks
- SQL Injection:
- ❌
SELECT * FROM users WHERE id = $_GET['id'] - ✅ Use PDO prepared statements
- ❌
- XSS Attacks:
- ❌
echo $_POST['username'] - ✅
echo htmlspecialchars($_POST['username'], ENT_QUOTES, 'UTF-8')
- ❌
- File Inclusion:
- ❌
include($_GET['file']) - ✅ Whitelist allowed files, use absolute paths
- ❌
- Command Injection:
- ❌
shell_exec($_GET['command']) - ✅ Use
escapeshellarg()and validate inputs
- ❌
Authentication & Authorization
- Password Security: Use
password_hash()andpassword_verify() - Session Management: Regenerate session IDs, set secure session parameters
- Access Control: Implement role-based access control (RBAC)
- API Security: Validate API tokens on every request
6. Code Quality Metrics
Cyclomatic Complexity
- Target: Maximum 10 per method
- Refactoring: Break down complex methods
- Testing: Ensure each branch has test coverage
Code Reusability
- DRY Principle: Don't Repeat Yourself
- Single Responsibility: Each method/class has one purpose
- Composition over Inheritance: Favor composition for flexibility
Documentation
- PHPDoc: Document all public methods and classes
- Type Declarations: Use strong typing where possible
- Inline Comments: Explain complex business logic
- README: Keep project documentation updated
Review Process
Step 1: Automated Scanning (If the environment exists)
- Syntax Check:
php -l filename.php - Code Standards: Run PHP_CodeSniffer with PSR-12
- Static Analysis: Use PHPStan or Psalm
- Security Scan: Run security checkers
Step 2: Manual Review
- Readability: Is the code easy to understand?
- Maintainability: Can future developers easily modify this?
- Performance: Are there obvious bottlenecks?
- Security: Are there potential vulnerabilities?
Step 3: Testing
- Unit Tests: Ensure adequate coverage (80%+)
- Integration Tests: Test component interactions
- Performance Tests: Benchmark critical paths
Common Code Smells
Red Flags
- Long Methods: > 50 lines
- Large Classes: > 500 lines
- Too Many Parameters: > 4 parameters
- Duplicate Code: Same logic in multiple places
- Dead Code: Unused variables, methods, or classes
- Magic Numbers: Hardcoded values without explanation
- Inconsistent Formatting: Mixing styles
Refactoring Patterns
- Extract Method: Break down complex methods
- Extract Class: Separate responsibilities
- Replace Magic Numbers: Use named constants
- Introduce Parameter Object: Group related parameters
- Encapsulate Collection: Control collection access
PHP7 vs PHP8 Compatibility Checklist
PHP8+ Features (Use When Available)
- Union Types:
function foo(int|float $bar) - Named Arguments:
array_fill(start_index: 0, count: 100, value: 50) - Match Expression: More concise than switch
- Null safe Operator:
$country = $session?->user?->getAddress()?->country - Constructor Property Promotion:
public function __construct(private string $name) - Attributes:
#[Route('/users')],#[ORM\Entity]
PHP7.4+ Features
- Typed Properties:
private string $name; - Arrow Functions:
$ids = array_map(fn(Post $post) => $post->id, $posts) - Null Coalescing Assignment:
$array['key'] ??= 'default' - Spread Operator in Arrays:
$merged = [...$array1, ...$array2]
Backward Compatibility
- Check PHP version requirements
- Avoid features not in target PHP version
- Use polyfills for newer functions if needed
- Test on minimum supported PHP version
Best Practices Summary
Do
- ✓ Use meaningful variable and method names
- ✓ Write self-documenting code
- ✓ Keep methods small and focused
- ✓ Use type declarations
- ✓ Write tests for critical logic
- ✓ Handle errors gracefully
- ✓ Validate all inputs
- ✓ Use dependency injection
- ✓ Follow PSR standards
- ✓ Document complex business logic
Don't
- ✗ Use global variables
- ✗ Suppress errors with
@ - ✗ Trust user input without validation
- ✗ Mix business logic with presentation
- ✗ Create god classes that do everything
- ✗ Use magic methods excessively
- ✗ Ignore performance implications
- ✗ Skip error handling
- ✗ Hardcode configuration values
- ✗ Leave debug code in production
Review Output Format
When reviewing code, use the standardized templates:
For Comprehensive Reviews
Use templates/review-report-template.md which provides:
- Executive summary with key findings
- Categorized issues (Critical/Standards/Improvements)
- Security and performance assessments
- PHP compatibility analysis
- Actionable recommendations with timelines
For Quick Reviews
Use templates/quick-checklist.md for:
- 30-minute focused review process
- Essential security and quality checks
- Pull request reviews
- Pre-deployment validation
Custom Format
For specific needs, provide feedback in this structure:
## Code Review: [filename]
### Summary
[Overall assessment]
### Critical Issues (Must Fix)
- [ ] [Issue description and suggested fix]
### Standards Violations (Should Fix)
- [ ] [Issue and recommended solution]
### Improvements (Nice to Have)
- [ ] [Suggestion for better code quality]
### Performance Impact
- [Analysis of performance implications]
### Security Assessment
- [Security vulnerabilities found]
### PHP Compatibility
- [PHP version compatibility issues]References
- See
references/php-cs-fixer-config.mdfor automated code style configuration - See
examples/before-after-refactor.mdfor refactoring examples - Use
scripts/php-security-scanner.phpfor automated security scanning
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

