o0h/phpstan-spaghetti
Composer 安装命令:
composer require o0h/phpstan-spaghetti
包简介
PHPStan rules to enforce SPAGHETTI code style
README 文档
README
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
elseorelseifclauses - Only unary conditions (no
&&,||, etc.) - Body must contain only a single
gotostatement
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!
o0h/phpstan-spaghetti 适用场景与选型建议
o0h/phpstan-spaghetti 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 236 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「static-analysis」 「PHPStan」 「code-quality」 「phpstan-extension」 「spaghetti-code」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 o0h/phpstan-spaghetti 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 o0h/phpstan-spaghetti 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 o0h/phpstan-spaghetti 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine Criteria extensions for PHPStan
PHPStan for Silverstripe
PHPStan extensions for Containers
Check a project's code coverage, optionally enforcing a minimum value
A generic package for implementing Laravel Pint coding standards across Laravel packages
PHPStan extension for detecting parameters that should use SensitiveParameter
统计信息
- 总下载量: 236
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-31