Skip to main content
skill CX Codex

magento-code-reviewer — Claude Code skill for Magento 2 review

Reviews Magento 2 PHP code against PSR-12, Magento coding standards, security and performance rules. Useful before a commit or in a pull request.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add maxnorm/magento2-agent-skills --skill magento-code-reviewer -a claude-code
Open on GitHub

What magento-code-reviewer does

The skill walks through five areas: coding standards, security, performance, architecture and code quality. On standards it enforces PSR-12, the vendor/magento/magento-coding-standard/Magento2 ruleset and the project's .editorconfig. It also expects declare(strict_types=1);, type hints on every parameter and return value, strict === and !== comparisons, and constructor property promotion with readonly.

Security review covers SQL injection, XSS, missing CSRF form keys and broken access control. Performance review looks at N+1 queries, block and full page caching, and collection filters. Architecture review checks module structure, di.xml, service contracts, plugins and event observers.

For automated checks it points at vendor/bin/phpstan or vendor/bin/psalm, vendor/bin/phpcs --standard=Magento2, and names Blackfire and XHProf for profiling. Those tools have to be present in the project, otherwise the automated pass has nothing to run. Findings come back sorted into four severity levels, from critical vulnerabilities down to style preferences.

What it helps with

  • check a PHP file against PSR-12 before committing
  • find SQL injection and unescaped output in a module
  • trace N+1 queries in a product collection
  • validate module structure and di.xml against Magento patterns
  • flag missing type hints and unused imports in a class

Example prompts for the agent

  • review this module against Magento 2 and PSR-12 standards
  • do a code review of Model/ProductSync.php before the pull request
  • find security issues in this controller and tell me how to fix them

How to install magento-code-reviewer

1Skills CLI (Vercel)

npx skills add maxnorm/magento2-agent-skills --skill magento-code-reviewer -a claude-code

2Manually: put the files in place

~/.claude/skills/magento-code-reviewer/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/magento-code-reviewer/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about magento-code-reviewer

How do I install magento-code-reviewer in Claude?

Run npx skills add maxnorm/magento2-agent-skills --skill magento-code-reviewer -a claude-code. The skill lands in ~/.claude/skills/magento-code-reviewer/SKILL.md.

What does magento-code-reviewer do?

It reviews Magento 2 code for PSR-12 and Magento coding standards compliance, security vulnerabilities, performance bottlenecks and architecture mistakes. Feedback comes with code examples and suggested fixes.

What tools does the skill need?

Automated checks run through vendor/bin/phpstan or vendor/bin/psalm and vendor/bin/phpcs --standard=Magento2. For profiling it names Blackfire and XHProf.

Source text

SKILL.md · MIT
---
name: magento-code-reviewer
description: Reviews Magento 2 code for quality, security, performance, and compliance with PSR-12 and Magento coding standards. Use proactively when reviewing code, before commits, during pull requests, or when ensuring code quality. Enforces strict type declarations, proper dependency injection, security best practices, and performance optimization.
---

# Magento 2 Code Reviewer

Elite code review expert specializing in modern code analysis, security vulnerabilities, performance optimization, and production reliability for Magento 2 applications. Follows Adobe Commerce best practices and Magento 2 Certified Developer standards.

## When to Use

- Reviewing code before commits or pull requests
- Ensuring code quality and standards compliance
- Security vulnerability assessment
- Performance optimization review
- Architecture and design pattern validation
- Pre-deployment code quality checks

## Magento 2 Coding Standards (CRITICAL)

### PSR-12 & Magento Standards
- **PSR-12 Compliance**: Strictly enforce PSR-12 coding standards
- **Magento Coding Standard**: Verify compliance with `vendor/magento/magento-coding-standard/Magento2`
- **EditorConfig**: Check project's `.editorconfig` for indentation (4 spaces), line endings (LF), encoding (UTF-8)
- **Opening Braces**: Classes and methods must have opening braces on their own line
- **No Tabs**: Must use spaces, never tabs

### Type Safety & Modern PHP
- **Strict Types**: `declare(strict_types=1);` required
  - Classes: After copyright block, before namespace
  - Templates: Same line as `<?php` opening tag
- **Type Hinting**: All parameters and return types must be type-hinted
- **Constructor Property Promotion**: Use with `readonly` modifier where appropriate
- **Strict Comparisons**: Always use `===` and `!==` (never `==` or `!=`)

### Code Quality Checklist
- [ ] `declare(strict_types=1);` present
- [ ] All parameters type-hinted
- [ ] All return types type-hinted
- [ ] Constructor property promotion with `readonly` used where possible
- [ ] No unused imports
- [ ] Strict comparisons used throughout
- [ ] No static methods without justification
- [ ] Constructor has PHPDoc with all `@param` annotations
- [ ] Copyright header present
- [ ] Minimal comments (only critical ones)

### Comment Standards
- **Minimal Comments**: Only critical comments should remain
- **PHPDoc Requirements**: Include only `@param`, `@return`, and `@throws` annotations
- **No Verbose Descriptions**: Avoid lengthy method descriptions unless genuinely complex
- **No Inline Comments**: Flag explanatory inline comments for straightforward code
- **Copyright Headers**: Must be present in all files

### Expected Code Format

**Class:**
```php
<?php

/**
 * Copyright © 2025 CompanyName. All rights reserved.
 */

declare(strict_types=1);

namespace CompanyName\ModuleName\Model;

use CompanyName\ModuleName\Api\ConfigInterface;
use CompanyName\ModuleName\Api\DependencyInterface;

class Example
{
    /**
     * @param DependencyInterface $dependency
     * @param ConfigInterface $config
     */
    public function __construct(
        private readonly DependencyInterface $dependency,
        private readonly ConfigInterface $config
    ) {
    }
}
```

**Template:**
```php
<?php declare(strict_types=1);

use CompanyName\ModuleName\ViewModel\ViewModelClass;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/**
 * CompanyName - Module Name
 *
 * Template description.
 *
 * Copyright © 2025 CompanyName. All rights reserved.
 *
 * @var ViewModelClass $viewModel
 * @var Template $block
 * @var Escaper $escaper
 */
```

## Review Process

### 1. Automated Analysis
Run these tools for automated checks:
- **Static Analysis**: `vendor/bin/phpstan` or `vendor/bin/psalm`
- **Code Style**: `vendor/bin/phpcs --standard=Magento2`
- **Security Scanning**: Review for common vulnerabilities
- **Performance Profiling**: Use Blackfire, XHProf for performance issues

### 2. Standards Compliance
- **PSR Compliance**: Enforce PSR-1, PSR-2, PSR-4, and PSR-12
- **Magento Patterns**: Verify Factory, Observer, Plugin, Repository, Service Contract patterns
- **SOLID Principles**: Evaluate Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
- **Dependency Injection**: Check proper DI usage (no service locators)
- **Service Contracts**: Verify interface usage

### 3. Security Review
- **Input Validation**: Check proper sanitization and validation
- **SQL Injection**: Identify vulnerable queries, recommend parameterized queries
- **XSS Prevention**: Verify output escaping (`$escaper->escapeHtml()`, etc.)
- **CSRF Protection**: Check form key implementation
- **Access Control**: Ensure proper ACL implementation
- **Data Encryption**: Review sensitive data handling

### 4. Performance Review
- **Database Queries**: Analyze N+1 problems, missing indexes, inefficient joins
- **Caching Strategy**: Review Full Page Cache, Block Cache implementations
- **Memory Usage**: Identify memory leaks and inefficient object instantiation
- **Collection Optimization**: Review filters, pagination, select statements
- **Frontend Performance**: Evaluate JavaScript/CSS bundling, image optimization

### 5. Architecture Review
- **Module Structure**: Validate proper directory structure
- **Dependency Injection**: Review di.xml configurations
- **Service Contracts**: Ensure proper API interface implementation
- **Plugin Usage**: Evaluate before/after/around plugin implementations
- **Event Observers**: Review event dispatching patterns
- **Database Schema**: Validate db_schema.xml and upgrade scripts

## Reporting Standards

### Severity Classification
- **Critical**: Security vulnerabilities, data loss risks, breaking changes
- **High**: Performance issues, architectural problems, standards violations
- **Medium**: Code quality issues, maintainability concerns
- **Low**: Style preferences, minor optimizations

### Feedback Format
- Provide specific code examples
- Include recommended fixes
- Reference Magento documentation links
- Quantify performance implications where applicable

## Best Practices Reference

Follow Adobe Commerce best practices:
- [Coding Standards](https://developer.adobe.com/commerce/php/coding-standards/)
- [Best Practices](https://developer.adobe.com/commerce/php/best-practices/)
- [Extension Development](https://developer.adobe.com/commerce/php/best-practices/extensions/)

**CRITICAL**: Always check project for coding standards files (phpcs.xml, .php-cs-fixer.php, .editorconfig) and enforce them rigorously.

© maxnorm · MIT · maxnorm/magento2-agent-skills

Similar skills

Everything for Code review and refactoring →

From the same set5

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor