home / skills / proxiblue / claude-skills / code-quality-audit

code-quality-audit skill

/code-quality-audit

This skill automates Magento 2 code quality checks, delivering PSR-12, PHPStan, PHP_CodeSniffer, and PHP Mess Detector results with actionable fixes.

npx playbooks add skill proxiblue/claude-skills --skill code-quality-audit

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: code-quality-audit
description: Automated code quality audit skill that runs PSR-12 compliance checks, phpstan static analysis, phpcs code style validation, and phpmd mess detection for Magento 2 code.
---

This skill automates comprehensive code quality checks for Magento 2 projects.

## What This Skill Does

1. **PSR-12 Compliance Check**
   - Validates strict PSR-12 adherence
   - Checks opening braces placement
   - Validates spacing and indentation
   - Verifies proper use statement ordering

2. **PHPStan Static Analysis**
   - Type checking at maximum level
   - Identifies potential bugs and errors
   - Validates method signatures and return types
   - Checks for undefined variables and methods

3. **PHP_CodeSniffer (Magento2 Standard)**
   - Enforces Magento2 coding standards
   - Validates dependency injection patterns
   - Checks service contract usage
   - Verifies plugin and observer implementation

4. **PHP Mess Detector**
   - Identifies code complexity issues
   - Detects unused code and parameters
   - Highlights potential design problems
   - Suggests refactoring opportunities

## Usage

When invoked, this skill will:

1. Run `vendor/bin/php-cs-fixer fix --dry-run --diff` to check PSR-12 compliance
2. Execute `vendor/bin/phpstan analyse -c phpstan.neon` for static analysis
3. Run `vendor/bin/phpcs --standard=Magento2 app/code/` for Magento standards
4. Execute `vendor/bin/phpmd app/code/ text cleancode,codesize,design,naming,unusedcode`

## Output

The skill provides:
- List of violations with file paths and line numbers
- Severity classification (Critical, High, Medium, Low)
- Specific recommendations for fixes
- Code examples of proper implementations

## When to Use

- Before code review submissions
- After implementing new features or modules
- During pull request validation
- Before production deployments
- As part of CI/CD pipeline validation

Overview

This skill automates a comprehensive code quality audit for Magento 2 projects. It combines PSR-12 compliance checks, PHPStan static analysis, PHP_CodeSniffer with the Magento2 standard, and PHP Mess Detector scans. The result is a prioritized list of issues with concrete remediation guidance and code examples.

How this skill works

The skill runs a sequence of standard tools: a PSR-12 fixer in dry-run mode to surface formatting and style violations, PHPStan at a high strictness level to detect type and signature problems, PHPCS configured for the Magento2 standard to validate framework-specific conventions, and PHPMD to identify complexity, unused code, and design smells. It collects findings from each tool, classifies severity, aggregates by file and line, and generates actionable recommendations and example fixes.

When to use it

  • Before submitting code for review to catch style and static-analysis issues early
  • After adding new features or modules to validate types and dependencies
  • As a gate in pull request pipelines to block regressions and enforce standards
  • Before production deployments to reduce runtime errors and maintainability risks
  • During continuous integration to keep codebase quality consistent over time

Best practices

  • Run the audit locally before opening a PR to reduce back-and-forth feedback
  • Fix high and critical severity items first—type errors and undefined methods are priority
  • Address PHPMD findings by simplifying complex methods or extracting classes
  • Use PSR-12 findings to keep consistent formatting; apply automated fixes where safe
  • Keep phpstan configuration tuned for your codebase to reduce false positives

Example use cases

  • Validate a new Magento 2 module to ensure it follows Magento coding patterns and DI practices
  • Scan a large refactor to find regressions in method signatures or returned types
  • Integrate into CI to fail builds when critical or high-severity violations are introduced
  • Run before a release to remove unused code, reduce complexity, and improve maintainability
  • Provide developers with concrete code examples for correcting style and static-analysis errors

FAQ

Which tools does the skill run and in what order?

It runs a PSR-12 dry-run fix, then PHPStan analysis, PHPCS with the Magento2 standard, and finally PHPMD. Results are aggregated and prioritized.

How are severities determined?

Severity combines the originating tool's classification and the issue type: runtime risks and type errors map to Critical/High, style and minor smells to Medium/Low.

Can this be added to CI pipelines?

Yes. The skill is designed for CI integration so builds can fail on critical/high issues and provide developer-friendly reports.