check-method-length
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "check-method-length":https://skillpi.com/zh/skills/deepskill-07e500edaf7e606abc11b1986753fc588084f20baf993d940c9455d8a6e22553。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
分析 PHP 代码中的方法长度问题。检测超过 30 行的方法、违反单一职责的情况,并指出可提取子方法的机会。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 减记
- 实测状态
- 未测试
文件浏览
Frontmatter
name: check-method-length
description: Analyzes PHP code for method length issues. Detects methods exceeding 30 lines, single responsibility violations, extract method opportunities.Method Length Check
Analyze PHP code for method length and complexity issues.
Detection Thresholds
| Lines | Classification |
|---|---|
| 1-15 | ✅ Ideal |
| 16-30 | ⚠️ Acceptable |
| 31-50 | 🟡 Long - consider splitting |
| 51+ | 🟠 Too long - must split |
Detection Patterns
1. Methods Over 30 Lines
// TOO LONG: 50+ lines doing multiple things
public function processOrder(Order $order): void
{
// Validate order (10 lines)
if ($order->getItems()->isEmpty()) {
throw new InvalidOrderException('Empty order');
}
// ... more validation
// Calculate totals (15 lines)
$subtotal = 0;
foreach ($order->getItems() as $item) {
$subtotal += $item->getPrice() * $item->getQuantity();
}
// ... more calculations
// Apply discounts (10 lines)
$discount = $this->calculateDiscount($order);
// ... discount logic
// Process payment (10 lines)
$payment = $this->paymentGateway->charge($total);
// ... payment logic
// Send notifications (10 lines)
$this->mailer->send($order->getCustomer(), 'order_confirmation');
// ... notification logic
}
// GOOD: Split into focused methods
public function processOrder(Order $order): void
{
$this->validateOrder($order);
$totals = $this->calculateTotals($order);
$this->processPayment($order, $totals);
$this->sendNotifications($order);
}
private function validateOrder(Order $order): void
{
// 10 lines of validation
}
private function calculateTotals(Order $order): OrderTotals
{
// 15 lines of calculation
}
2. Single Responsibility Violations
// BAD: Method does too many things
public function createUser(array $data): User
{
// 1. Validate input
// 2. Hash password
// 3. Create user entity
// 4. Save to database
// 5. Send welcome email
// 6. Create activity log
// 7. Update statistics
}
// GOOD: Each method has one responsibility
public function createUser(array $data): User
{
$validatedData = $this->validateUserData($data);
$user = $this->buildUserEntity($validatedData);
$this->userRepository->save($user);
$this->eventDispatcher->dispatch(new UserCreatedEvent($user));
return $user;
}
3. Extract Method Opportunities
// BEFORE: Long conditional blocks
public function calculatePrice(Product $product, User $user): Money
{
$basePrice = $product->getPrice();
// Complex discount calculation (15 lines)
$discount = 0;
if ($user->isPremium()) {
$discount += 10;
}
if ($user->getOrderCount() > 10) {
$discount += 5;
}
if ($product->isOnSale()) {
$discount += $product->getSaleDiscount();
}
if ($this->isHolidaySeason()) {
$discount += 15;
}
$discount = min($discount, 50);
// ...
// Tax calculation (10 lines)
$taxRate = $this->getTaxRate($user->getCountry());
// ...
return $finalPrice;
}
// AFTER: Extracted methods
public function calculatePrice(Product $product, User $user): Money
{
$basePrice = $product->getPrice();
$discount = $this->calculateDiscount($product, $user);
$priceAfterDiscount = $basePrice->subtract($discount);
$tax = $this->calculateTax($priceAfterDiscount, $user);
return $priceAfterDiscount->add($tax);
}
private function calculateDiscount(Product $product, User $user): Money
{
// Focused discount logic
}
private function calculateTax(Money $price, User $user): Money
{
// Focused tax logic
}
4. Long Parameter Lists
// BAD: Too many parameters (indicates method does too much)
public function createReport(
string $title,
DateTime $startDate,
DateTime $endDate,
array $filters,
string $format,
bool $includeCharts,
bool $includeComments,
string $outputPath
): Report {}
// GOOD: Parameter object
public function createReport(ReportRequest $request): Report
{
// Method focuses on orchestration
}
final readonly class ReportRequest
{
public function __construct(
public string $title,
public DateRange $dateRange,
public array $filters,
public ReportFormat $format,
public ReportOptions $options,
) {}
}
Counting Rules
- Count logical lines, not physical lines
- Exclude blank lines and comments from count
- Include all lines in method body (opening/closing braces not counted)
- One statement per line
Refactoring Techniques
Extract Method
// Before
$validated = [];
foreach ($items as $item) {
if ($item->isValid() && $item->isInStock()) {
$validated[] = $item;
}
}
// After
$validated = $this->filterValidItems($items);
private function filterValidItems(array $items): array
{
return array_filter($items, fn($item) => $item->isValid() && $item->isInStock());
}
Introduce Parameter Object
// Before
function search($query, $page, $limit, $sort, $order, $filters) {}
// After
function search(SearchCriteria $criteria) {}
Replace Method with Method Object
// Before: Complex method with many local variables
public function calculate(): int
{
$a = ...;
$b = ...;
$c = ...;
// 50 lines using a, b, c
}
// After: Separate class
class PriceCalculator
{
private int $a;
private int $b;
private int $c;
public function calculate(): int
{
$this->initializeValues();
return $this->computeResult();
}
}
Grep Patterns
# Find method signatures
Grep: "function\s+\w+\s*\(" --glob "**/*.php"
# Count lines between method start and end (manual analysis needed)
Severity Classification
| Lines | Severity |
|---|---|
| 31-50 | 🟡 Minor |
| 51-80 | 🟠 Major |
| 81+ | 🔴 Critical |
Output Format
### Method Length: [MethodName] is too long
**Severity:** 🟠/🟡
**Location:** `file.php:line`
**Lines:** 65
**Issue:**
Method `processOrder` is 65 lines long (recommended: ≤30).
**Responsibilities Found:**
1. Order validation (lines 5-20)
2. Price calculation (lines 22-45)
3. Payment processing (lines 47-60)
4. Notification sending (lines 62-70)
**Suggested Refactoring:**
```php
public function processOrder(Order $order): void
{
$this->validateOrder($order);
$totals = $this->calculateTotals($order);
$this->processPayment($order, $totals);
$this->sendNotifications($order);
}
## When This Is Acceptable
- **CLI commands/migrations** — Long methods in console commands or database migrations are often unavoidable due to sequential operations
- **Test setup methods** — `setUp()` methods with extensive fixture creation may legitimately be long
- **Configuration methods** — Methods that configure framework services/routes often need many lines
### False Positive Indicators
- Method is in a `Command` or `Migration` class
- Method name starts with `setUp` or `configure`
- Method body is mostly configuration/declaration, not logic当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供具体检测阈值和严重性分级
- 覆盖方法过长、SRP违反、提取机会等多个维度
- 面向开发者群体的实用代码质量分析工具
亮点
- description完整清晰,覆盖多种变体
- 明确30行阈值和严重性分级,边界清晰
亮点
- 结构清晰:检测阈值→检测模式→重构技术
- 提供多个完整代码对比示例
- frontmatter完整,文档长度适中
亮点
- 基于PHP代码分析,无需外部依赖
- 提供False Positive Indicators和例外场景
- 纯分析类工具,无不可逆操作风险
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。