o0h/phpstan-spaghetti

PHPStan rules to enforce SPAGHETTI code style

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:phpstan-extension

pkg:composer/o0h/phpstan-spaghetti

v0.0.1 2026-01-31 07:05 UTC

This package is auto-updated.

Last update: 2026-01-31 07:08:27 UTC


README

Latest Stable Version Total Downloads License PHPUnit PHPStan Coding Standard

A PHPStan extension that enforces true spaghetti code principles in your PHP projects.

Why?

While most static analysis tools try to improve code quality, PHPStan Spaghetti takes a different approach: it ensures your code stays true to the classic spaghetti code style. No more clean, maintainable code - embrace the chaos!

Installation

Install via Composer:

composer require --dev o0h/phpstan-spaghetti

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/o0h/phpstan-spaghetti/extension.neon

Configuration

The extension is enabled by default. To disable the rules, add the following to your phpstan.neon:

parameters:
    spaghettiRules:
        enabled: false

To explicitly enable (default behavior):

parameters:
    spaghettiRules:
        enabled: true

Rules

PHPStan Spaghetti provides 16 rules organized into 5 categories to enforce true spaghetti code principles.

Control Flow

NoLoopsRule

Prohibits all loop constructs (for, while, do-while, foreach). Use goto statements instead.

Violation:

foreach ($items as $item) {
    process($item);
}

Compliant:

$i = 0;
$count = count($items);
loop_start:
$done = $i >= $count;
if ($done)
    goto loop_end;
goto do_process;

do_process:
process($items[$i]);
$i++;
goto loop_start;

loop_end:

RestrictedIfRule

Enforces strict rules for if statements:

  • No else or elseif clauses
  • Only unary conditions (no &&, ||, etc.)
  • Body must contain only a single goto statement

NoSwitchMatchRule

Prohibits switch and match expressions. Use chains of if and goto instead.

NoTryCatchRule

Prohibits try-catch-finally blocks. Handle errors with conditional checks and goto.

NoReturnRule

Prohibits return statements. Use inline code and goto instead.

NoYieldRule

Prohibits yield and yield from expressions. No generators allowed in spaghetti code.

Functions

NoFunctionDefinitionRule

Prohibits user-defined functions. Use inline code with goto statements instead.

NoCallableArgumentRule

Prohibits using callable types as function arguments (closures, arrow functions, string callables, etc.).

Object-Oriented Programming

NoClassLikeDefinitionRule

Prohibits all class-like definitions (classes, interfaces, traits, enums). Spaghetti code should be procedural!

NoObjectInstantiationRule

Prohibits object instantiation with new keyword.

NoObjectAccessRule

Prohibits accessing object properties and methods (->, ::, ?->).

Operators

NoTernaryOperatorRule

Prohibits ternary operators (? :). Use if statements with goto instead.

NoNullCoalesceRule

Prohibits null coalesce operators (??, ??=).

NoSpaceshipOperatorRule

Prohibits spaceship operator (<=>).

Structure

NoNamespaceRule

Prohibits namespace declarations. Use global namespace only.

NoTypeDeclarationRule

Prohibits type declarations for parameters, return values, and properties.

Development

Running Tests

composer test

Code Style

Check code style:

composer cs-check

Fix code style:

composer cs-fix

Static Analysis

composer phpstan

Run All Checks

composer ci

Requirements

  • PHP 8.2 or higher
  • PHPStan 2.0 or higher

License

MIT

Disclaimer

This package is intended for educational and entertainment purposes. Please do not actually use these coding practices in production code. Embrace clean code principles, not spaghetti code!