承接 o0h/phpstan-spaghetti 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

o0h/phpstan-spaghetti

最新稳定版本:v0.0.6

Composer 安装命令:

composer require o0h/phpstan-spaghetti

包简介

PHPStan rules to enforce SPAGHETTI code style

README 文档

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 21 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.

NoThrowRule

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

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.).

NoCallableArgumentInMethodCallRule

Prohibits using callable types as method call arguments.

NoCallableArgumentInStaticCallRule

Prohibits using callable types as static method call arguments.

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 (->, ::, ?->).

NoInstanceofRule

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

NoTypeCheckFunctionRule

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

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!

统计信息

  • 总下载量: 236
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固