PHPackages                             o0h/phpstan-spaghetti - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. o0h/phpstan-spaghetti

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

o0h/phpstan-spaghetti
=====================

PHPStan rules to enforce SPAGHETTI code style

v0.0.6(2mo ago)0236MITPHPPHP ^8.2CI passing

Since Jan 31Pushed 2mo agoCompare

[ Source](https://github.com/o0h/phpstan-spaghetti)[ Packagist](https://packagist.org/packages/o0h/phpstan-spaghetti)[ Docs](https://github.com/o0h/phpstan-spaghetti)[ RSS](/packages/o0h-phpstan-spaghetti/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (9)Used By (0)

PHPStan Spaghetti
=================

[](#phpstan-spaghetti)

[![Latest Stable Version](https://camo.githubusercontent.com/4f0ca2d262f9f5bf09d09aac454ccd30cd0640e8c278b5d8acc83aed12c50a90/68747470733a2f2f706f7365722e707567782e6f72672f6f30682f7068707374616e2d7370616768657474692f76)](https://packagist.org/packages/o0h/phpstan-spaghetti)[![Total Downloads](https://camo.githubusercontent.com/2cb182a1e2886215dff28e29b0b38a4fc834dcf7ae8cb5241bf6cc572cf4e96d/68747470733a2f2f706f7365722e707567782e6f72672f6f30682f7068707374616e2d7370616768657474692f646f776e6c6f616473)](https://packagist.org/packages/o0h/phpstan-spaghetti)[![License](https://camo.githubusercontent.com/b1eec37273ff4481860e098edbbb5e44e124e05a6f761dd1d098cce82ae19cf0/68747470733a2f2f706f7365722e707567782e6f72672f6f30682f7068707374616e2d7370616768657474692f6c6963656e7365)](https://packagist.org/packages/o0h/phpstan-spaghetti)[![PHPUnit](https://github.com/o0h/phpstan-spaghetti/workflows/PHPUnit/badge.svg)](https://github.com/o0h/phpstan-spaghetti/actions?query=workflow%3APHPUnit)[![PHPStan](https://github.com/o0h/phpstan-spaghetti/workflows/PHPStan/badge.svg)](https://github.com/o0h/phpstan-spaghetti/actions?query=workflow%3APHPStan)[![Coding Standard](https://github.com/o0h/phpstan-spaghetti/workflows/Coding%20Standard/badge.svg)](https://github.com/o0h/phpstan-spaghetti/actions?query=workflow%3A%22Coding+Standard%22)

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

Why?
----

[](#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
------------

[](#installation)

Install via Composer:

```
composer require --dev o0h/phpstan-spaghetti
```

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

Manual installationIf 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
-------------

[](#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
-----

[](#rules)

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

### Control Flow

[](#control-flow)

#### NoLoopsRule

[](#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

[](#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

[](#noswitchmatchrule)

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

#### NoTryCatchRule

[](#notrycatchrule)

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

#### NoReturnRule

[](#noreturnrule)

Prohibits `return` statements. Use inline code and `goto` instead.

#### NoYieldRule

[](#noyieldrule)

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

#### NoThrowRule

[](#nothrowrule)

Prohibits `throw` statements. Handle errors with conditional checks and `goto`.

### Functions

[](#functions)

#### NoFunctionDefinitionRule

[](#nofunctiondefinitionrule)

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

#### NoCallableArgumentRule

[](#nocallableargumentrule)

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

#### NoCallableArgumentInMethodCallRule

[](#nocallableargumentinmethodcallrule)

Prohibits using callable types as method call arguments.

#### NoCallableArgumentInStaticCallRule

[](#nocallableargumentinstaticcallrule)

Prohibits using callable types as static method call arguments.

### Object-Oriented Programming

[](#object-oriented-programming)

#### NoClassLikeDefinitionRule

[](#noclasslikedefinitionrule)

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

#### NoObjectInstantiationRule

[](#noobjectinstantiationrule)

Prohibits object instantiation with `new` keyword.

#### NoObjectAccessRule

[](#noobjectaccessrule)

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

#### NoInstanceofRule

[](#noinstanceofrule)

Prohibits `instanceof` operator. Spaghetti code shouldn't use objects anyway.

#### NoTypeCheckFunctionRule

[](#notypecheckfunctionrule)

Prohibits type check functions (`is_a()`, `is_subclass_of()`, `get_class()`, `get_parent_class()`). Spaghetti code shouldn't use objects anyway.

### Operators

[](#operators)

#### NoTernaryOperatorRule

[](#noternaryoperatorrule)

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

#### NoNullCoalesceRule

[](#nonullcoalescerule)

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

#### NoSpaceshipOperatorRule

[](#nospaceshipoperatorrule)

Prohibits spaceship operator (``).

### Structure

[](#structure)

#### NoNamespaceRule

[](#nonamespacerule)

Prohibits namespace declarations. Use global namespace only.

#### NoTypeDeclarationRule

[](#notypedeclarationrule)

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

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
```

### Code Style

[](#code-style)

Check code style:

```
composer cs-check
```

Fix code style:

```
composer cs-fix
```

### Static Analysis

[](#static-analysis)

```
composer phpstan
```

### Run All Checks

[](#run-all-checks)

```
composer ci
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- PHPStan 2.0 or higher

License
-------

[](#license)

MIT

Disclaimer
----------

[](#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!

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance84

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

6

Last Release

82d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7308bfca1f335f367cd1f08501356d6bc065f42e115bdd6bbcd140f0df90fd55?d=identicon)[o0h](/maintainers/o0h)

---

Top Contributors

[![o0h](https://avatars.githubusercontent.com/u/907122?v=4)](https://github.com/o0h "o0h (23 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (14 commits)")

---

Tags

PHPStanstatic analysiscode qualityphpstan-extensionspaghetti-code

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/o0h-phpstan-spaghetti/health.svg)

```
[![Health](https://phpackages.com/badges/o0h-phpstan-spaghetti/health.svg)](https://phpackages.com/packages/o0h-phpstan-spaghetti)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[staabm/phpstan-dba

2912.3M2](/packages/staabm-phpstan-dba)[ekino/phpstan-banned-code

Detected banned code using PHPStan

2925.6M92](/packages/ekino-phpstan-banned-code)[staabm/phpstan-todo-by

1991.8M55](/packages/staabm-phpstan-todo-by)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

3462.2M52](/packages/shipmonk-dead-code-detector)[szepeviktor/phpstan-wordpress

WordPress extensions for PHPStan

3257.8M898](/packages/szepeviktor-phpstan-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
