check-method-length
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "check-method-length" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-07e500edaf7e606abc11b1986753fc588084f20baf993d940c9455d8a6e22553. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Analyzes method length issues in PHP code. Detects methods longer than 30 lines, cases that violate single-responsibility, and opportunities to extract submethods.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Analyzes PHP code for method length issues. Detects methods exceeding 30 lines, single responsibility violations, extract method opportunities.
- Inputs and outputs
- ```markdown
- Testing
- Not tested
Browse files
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 logicCurrent listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供具体检测阈值和严重性分级
- 覆盖方法过长、SRP违反、提取机会等多个维度
- 面向开发者群体的实用代码质量分析工具
Highlights
- description完整清晰,覆盖多种变体
- 明确30行阈值和严重性分级,边界清晰
Highlights
- 结构清晰:检测阈值→检测模式→重构技术
- 提供多个完整代码对比示例
- frontmatter完整,文档长度适中
Highlights
- 基于PHP代码分析,无需外部依赖
- 提供False Positive Indicators和例外场景
- 纯分析类工具,无不可逆操作风险
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.