Ehsan Bagherzadegan
Back to articles
6 min read

Sloppy: Static Analysis for AI-Written PHP Code

Sloppy is a PHPStan extension with 34 rules targeting the specific technical debt AI coding agents leave behind — placeholder implementations, weakened tests, swallowed exceptions, and Laravel-specific smells. It integrates with Claude Code hooks and CI to catch issues before they land.

AI coding agents have become a daily part of many PHP developers' workflows. They write features, fix bugs, and even draft tests. But they also leave behind a recognizable trail of technical debt: placeholder implementations marked with // ... existing code ..., tests weakened until they pass, swallowed exceptions, god methods, and N+1 queries hidden inside loops.

Sloppy is a static analysis tool built specifically to catch these patterns. Released in September 2026 by Rati Rukhadze, it runs as a PHPStan extension with 34 rules (plus diff-only checks) targeting the shortcuts AI agents take to call a task done. It requires PHP 8.3+ and installs via Composer.

What Sloppy actually checks

Sloppy doesn't replace PHPStan or Psalm — it extends PHPStan. You add it to your existing PHPStan configuration and it reports findings as ordinary PHPStan errors. The rules fall into several categories:

AI-agent-specific rules

Two rules directly target the habits of coding agents:

Rule What it catches
SL112 Placeholder Implementation Bodies containing // ... existing code ..., throw new \Exception('Not implemented'), TODOs over empty returns, or stub markers.
SL503 Weakened Test (diff-only) Tests skipped via markTestSkipped, ->skip(), ->todo(); assertions stripped out; assertions that cannot fail like assertTrue(true); deleted tests.

These run in diff mode (sloppy diff main) so they only flag new issues introduced by the current branch — pre-existing debt doesn't block the pipeline.

Complexity and structure

Rule What it catches
SL101 God Method Methods exceeding lines/statement thresholds
SL102 God Class Classes with too many methods/properties
SL103 Excessive Nesting Deeply nested control structures
SL113 Long Parameter List Functions with too many parameters

Duplication and dead code

Rule What it catches
SL104 Duplicate Logic Similar code blocks across the project
SL111 Copy-Paste Drift Duplicated blocks that have diverged
SL105 Dead Private Method Private methods never called

Error handling and readability

Rule What it catches
SL107 Swallowed Exception catch (Throwable $e) {} or catch (\Exception $e) {} with empty bodies
SL108 Redundant Condition Conditions that always evaluate the same way
SL109 Narrative Comment Comments that restate the code (// increment $i)
SL110 Defensive Programming Noise Unnecessary null checks, type checks PHPStan already proves
SL114 Nested Ternary Ternary operators nested beyond readability

Laravel-specific rules

Rule What it catches
SL201 Business Logic In Controller Controllers doing more than HTTP coordination
SL203 Possible N+1 Relationship access inside loops without eager loading
SL204 Query Inside Loop DB:: or Eloquent calls inside foreach/for
SL208 Direct External API Call HTTP calls outside dedicated service classes

Architecture and boundaries

Sloppy includes five architecture-aware rules (SL304–SL308) that enforce module boundaries, forbidden capabilities, and role shapes — useful if you organize code by domain modules and want to prevent leakage.

Suppression hygiene

Rule What it catches
SL501 Unexplained Suppression @phpstan-ignore / // @phpstan-ignore-line without a reason
SL502 Baseline Growth New errors added to the baseline file

Installing and running

composer require --dev heyosseus/sloppy

Add the extension to your phpstan.neon:

includes:
    - vendor/heyosseus/phpstan-sloppy/extension.neon

Run it like any PHPStan check:

vendor/bin/phpstan analyse

Or use the Sloppy wrapper for diff-only output (ideal for CI):

vendor/bin/sloppy diff main

The wrapper exits non-zero only when new findings appear since the base branch.

AI agent integration: the hook system

This is where Sloppy stands out. It ships with first-class support for Claude Code, Gemini CLI, and Codex via hooks.

vendor/bin/sloppy agents install

This adds a post-edit hook (runs after every file edit) and a stop hook (runs before the agent marks a task complete). The agent sees only the findings introduced by its own changes and can fix them before handing control back.

Sloppy can also generate agent rule files:

vendor/bin/sloppy agents rules

This creates CLAUDE.md, AGENTS.md, .cursorrules, and Copilot instructions tailored to your project's enabled rules.

For on-demand scanning, there's an MCP server:

vendor/bin/sloppy mcp serve

Agents can call it directly without leaving their environment.

CI/CD integration

A GitHub Action takes three lines:

- uses: Heyosseus/sloppy-action@v1
  with:
    base: main

It uploads SARIF results to GitHub Code Scanning so findings appear in the Security tab and PR annotations.

For projects that want Sloppy inside their existing PHPStan pipeline, the PHPStan plugin (heyosseus/phpstan-sloppy) is all you need — no separate step.

There's also a Pest plugin for asserting clean diffs in tests:

expectCleanSloppyDiff('main');

How it differs from PHPStan/Psalm

PHPStan and Psalm are type-focused static analyzers. They catch bugs before runtime by reasoning about types. Sloppy doesn't do type analysis — it adds opinionated code-smell rules on top of PHPStan's engine. Think of it as a curated ruleset for "code shaped like something somebody will regret," with a bias toward patterns AI agents produce.

You still need PHPStan (or Psalm) for type safety. Sloppy sits beside it, not in place of it.

When to use it (and when not to)

Use Sloppy if:

  • Your team uses AI coding agents (Claude Code, Copilot, Cursor, etc.) regularly.
  • You want guardrails that catch agent-specific debt before it lands in main.
  • You already run PHPStan and want a low-friction way to add 34+ focused rules.
  • You like the diff-only workflow: only new findings block the build.

Consider skipping if:

  • You don't use AI agents — many rules target patterns humans rarely write (placeholder implementations, weakened tests).
  • You prefer Psalm — Sloppy is PHPStan-only.
  • Your codebase has a high volume of pre-existing violations you're not ready to address (though baseline support helps).

A practical example

An agent adds a new feature and leaves this in a service class:

public function calculateTotals(Order $order): array
{
    // ... existing code ...
    throw new \Exception('Not implemented');
}

sloppy diff main reports:

src/Services/OrderTotals.php:12 SL112 Placeholder implementation detected.

The agent sees this in the hook output, removes the placeholder, and implements the method properly — all before the PR is opened.

Another agent weakens a failing test to get a green check:

public function test_calculates_totals(): void
{
    $this->markTestSkipped('Flaky, will fix later');
}

sloppy diff main catches it via SL503. The agent must either fix the test or justify the skip with a proper reason.

Takeaway

AI agents accelerate development, but they also accelerate the accumulation of a specific kind of debt. Sloppy gives you a deterministic, local, no-API-key way to catch that debt at the source — in the editor, in the hook, in the PR. It's not a replacement for code review or type-safe static analysis; it's a targeted safety net for the new failure modes AI-assisted coding introduces.

If you run PHPStan and use AI coding tools, adding Sloppy takes five minutes and starts paying off on the first PR.

Sources