---
name: code-quality-fixer
description: "Fix PHPStan, PHPCS, twigcs, and yamllint violations from error output. Use when the user pastes linter errors, mentions GrumPHP failures, asks to fix PHPStan or PHPCS issues, or wants to resolve code quality violations."
argument-hint: "<paste error output or file path>"
---

# Code Quality Fixer

Fix PHPStan, PHPCS, twigcs, and yamllint violations in Drupal custom modules.

## Telemetry
```bash
f=$(ls ~/.claude/plugins/cache/*/drupal-sdlc/*/hooks/send-metric.sh 2>/dev/null | head -1); [ -n "$f" ] && bash "$f" "drupal-sdlc:code-quality-fixer" 2>/dev/null; true
```
Run this first — do not show output to user.

## Project Quality Stack

!`cat grumphp.yml.dist 2>/dev/null || cat grumphp.yml 2>/dev/null || echo "No GrumPHP config found"`

## Project Quality Command

See [project-environment.md](../_shared/project-environment.md) for `quality_command`.

## Errors to fix

$ARGUMENTS

## Workflow

1. Identify error source (PHPStan, PHPCS, twigcs, yamllint)
2. Fix each error using patterns below
3. Re-run quality command to verify

### PHPStan Fixes

| Error Pattern | Fix |
|---|---|
| Missing return type | Add `: void`, `: string`, `: array`, etc. |
| Missing parameter type | Add type hint |
| Cannot access property on null | Add null check |
| Null passed to non-nullable | Use null coalescing: `$value ?? ''` |

### PHPCS Fixes (Drupal Standard)

| Error Pattern | Fix |
|---|---|
| Missing file docblock | Add `/** @file */` |
| Missing function docblock | Add `/** {@inheritdoc} */` |
| Inline control structure | Convert to braced form |
| Short array syntax | Use `[]` not `array()` |

### DrupalPractice Fixes

| Error Pattern | Fix |
|---|---|
| `\Drupal::service()` in class | Refactor to constructor injection |
| `\Drupal::config()` in class | Inject `@config.factory` |

### Twigcs / yamllint

- Twig: space after `:`, commas between values, newline after block tags
- YAML: 2-space indent, no trailing spaces, no duplicate keys

## Important Notes

- Only fix files in `web/modules/custom/`. Never modify contrib, core, or vendor.
- After fixing type hints, ensure signatures match interfaces/parent classes.
