Token导航 LogoToken导航TokenDH.com
研究检索权限需确认github未标认证来源可访问许可证需确认审计通过

detect-code-smells检测代码气味

Agent Skill

detect-code-smells 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

356

周安装

15

GitHub Stars

66

下载量

125
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:detect-code-smells(检测代码气味)
来源仓库:https://github.com/dykyi-roman/awesome-claude-code
仓库路径:skills/detect-code-smells
安装命令:
npx skills add https://github.com/dykyi-roman/awesome-claude-code --skill detect-code-smells
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dykyi-roman/awesome-claude-code --skill detect-code-smells

简介

detect-code-smells 分析 PHP 代码库中的代码异味,按严重程度分类并提供重构建议。

  • 适用于代码质量监控与维护的技术债务管理场景。
  • 内置 God Class、Feature Envy、Long Parameter List 等 10 类异味检测规则。
  • 需确认目标路径可访问性及是否具备文件遍历权限。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Code Smells Detector

Overview

This skill analyzes PHP codebases for code smells (symptoms of deeper problems) and generates detailed reports with severity levels and refactoring recommendations.

Code Smells Catalog

SmellDescriptionDetectionSeverity
God ClassClass doing too much>500 LOC, >15 methodsCRITICAL
Feature EnvyMethod uses another class moreForeign calls > own callsWARNING
Data ClumpsSame fields appear together3+ repeated params/fieldsWARNING
Long Parameter ListMethod with many params>4 parametersWARNING
Long MethodMethod doing too much>50 LOCWARNING
Primitive ObsessionPrimitives instead of objectsstring $email, int $moneyINFO
Message ChainsLong getter chains->get()->get()->get()WARNING
Inappropriate IntimacyClasses knowing too muchDirect field accessWARNING

Detection Patterns

God Class Detection

# Large classes (>500 lines)
Grep: "^class " --glob "**/*.php"
# Then check file line counts

# Many public methods (>15)
Grep: "public function " --glob "**/*.php"
# Count per file

# Many dependencies (>8)
Grep: "__construct" --glob "**/*.php" -A 20
# Count constructor parameters

# Problematic names
Grep: "class.*Manager|class.*Handler|class.*Helper|class.*Util|class.*Processor" --glob "**/*.php"

Indicators:

  • Class > 500 lines → CRITICAL
  • Class > 15 public methods → CRITICAL
  • Class > 8 constructor dependencies → WARNING
  • Class name contains Manager, Handler, Helper, Util → INFO

Feature Envy Detection

# Methods using other class data excessively
Grep: "\$this->[a-z]+->get[A-Z]" --glob "**/*.php"

# Multiple calls to same foreign object
Grep: "\$[a-z]+->.*\$[a-z]+->" --glob "**/*.php"

# Getters called more than own methods
Grep: "function [a-z]+\(" --glob "**/*.php" -A 30
# Analyze method bodies for foreign vs own calls

Indicators:

  • Method calls other object's methods > own methods → WARNING
  • Multiple chained calls to foreign object → INFO
  • Method only transforms data from another class → WARNING

Data Clumps Detection

# Repeated parameter groups in constructors
Grep: "__construct\(" --glob "**/*.php" -A 10
# Look for patterns: (string $x, string $y, string $z) appearing multiple times

# Repeated parameter groups in methods
Grep: "function [a-z]+\(" --glob "**/*.php"
# Look for same 3+ parameter combinations

# Multiple classes with same field groups
Grep: "(private|readonly) (string|int|float)" --glob "**/*.php"
# Detect repeated field patterns

Common Data Clumps:

  • $street, $city, $zipCode, $country → Address Value Object
  • $startDate, $endDate → DateRange Value Object
  • $amount, $currency → Money Value Object
  • $firstName, $lastName, $email → Contact/Person Value Object

Long Parameter List Detection

# Methods with many parameters
Grep: "function [a-z]+\(" --glob "**/*.php"
# Count parameters (comma-separated)

# Constructors with many parameters
Grep: "__construct\(" --glob "**/*.php" -A 15
# Count parameters

Thresholds:

  • 4+ parameters → INFO
  • 6+ parameters → WARNING
  • 8+ parameters → CRITICAL

Long Method Detection

# Find method definitions and count lines until closing brace
Grep: "function [a-z]+\(" --glob "**/*.php" -A 60
# Analyze method length

# Nested control structures (indicator of complexity)
Grep: "if\s*\(.*\{.*if\s*\(" --glob "**/*.php" --multiline

Thresholds:

  • 30+ lines → INFO
  • 50+ lines → WARNING
  • 100+ lines → CRITICAL

Primitive Obsession Detection

# String parameters that should be Value Objects
Grep: "string \$email|string \$phone|string \$url|string \$currency|string \$country" --glob "**/*.php"

# Integer amounts
Grep: "int \$amount|int \$price|int \$total|int \$money|int \$cents" --glob "**/*.php"

# Float for money
Grep: "float \$amount|float \$price|float \$money" --glob "**/*.php"

# String status/type
Grep: "string \$status|string \$type|string \$state" --glob "**/*.php"

# Magic strings
Grep: "=== 'pending'|=== 'active'|=== 'completed'|=== 'draft'" --glob "**/*.php"

Should be Value Objects:

  • Email addresses → Email
  • Phone numbers → PhoneNumber
  • URLs → Url or Uri
  • Money amounts → Money (with currency)
  • Dates/periods → DateRange, Period
  • Identifiers → UserId, OrderId, etc.
  • Status/Type → Enum

Message Chains Detection

# Long getter chains
Grep: "->get[A-Z][a-z]+\(\)->get[A-Z][a-z]+\(\)" --glob "**/*.php"

# Triple or more chains
Grep: "->.*->.*->" --glob "**/*.php"

# Law of Demeter violations
Grep: "\$this->[a-z]+->get[A-Z].*->get[A-Z]" --glob "**/*.php"

Indicators:

  • 2 chained getters → INFO
  • 3+ chained getters → WARNING
  • Chains in loops → CRITICAL

Inappropriate Intimacy Detection

# Direct public property access
Grep: "\$[a-z]+->(?!get|set|is|has|can)[a-z]+" --glob "**/*.php"

# Friend classes accessing private state (via reflection)
Grep: "ReflectionClass|ReflectionProperty|setAccessible" --glob "**/*.php"

# Classes knowing internal structure
Grep: "->getInternalState|->getRawData|->getFields" --glob "**/*.php"

Report Format

# Code Smells Analysis Report

## Summary

| Smell | Critical | Warning | Info |
|-------|----------|---------|------|
| God Class | X | X | - |
| Feature Envy | - | X | X |
| Data Clumps | - | X | - |
| Long Parameter List | X | X | X |
| Long Method | - | X | X |
| Primitive Obsession | - | X | X |
| Message Chains | - | X | X |
| Inappropriate Intimacy | - | X | - |

**Total Issues:** X critical, X warnings, X info

## Critical Issues

### SMELL-001: God Class
- **File:** `src/Service/OrderManager.php`
- **Lines:** 847
- **Public Methods:** 23
- **Dependencies:** 12
- **Issue:** Class has too many responsibilities
- **Refactoring:**
  - Extract `OrderValidator` (validation logic)
  - Extract `OrderNotifier` (notification logic)
  - Extract `OrderPriceCalculator` (pricing logic)
- **Skills:** `create-use-case`, `create-domain-service`

### SMELL-002: Long Parameter List
- **File:** `src/Domain/Order/Order.php:45`
- **Method:** `createOrder()`
- **Parameters:** 9
- **Issue:** Too many parameters, hard to maintain
- **Refactoring:** Introduce Parameter Object
- **Skills:** `create-dto`, `create-builder`

## Warning Issues

### SMELL-003: Data Clump
- **Files:**
  - `src/Domain/User/User.php:15` — $street, $city, $zipCode
  - `src/Domain/Company/Company.php:23` — $street, $city, $zipCode
  - `src/Application/DTO/CreateOrderDTO.php:8` — $street, $city, $zipCode
- **Issue:** Address fields repeated across 3 classes
- **Refactoring:** Extract Address Value Object
- **Skills:** `create-value-object`

### SMELL-004: Feature Envy
- **File:** `src/Service/ReportGenerator.php:89`
- **Method:** `generateUserReport()`
- **Issue:** Method makes 15 calls to User object, only 2 to own class
- **Refactoring:** Move method to User or create UserReportBuilder
- **Skills:** `create-domain-service`

### SMELL-005: Primitive Obsession
- **File:** `src/Domain/User/User.php:12`
- **Field:** `private string $email`
- **Issue:** Email should be Value Object for validation
- **Refactoring:** Create Email Value Object
- **Skills:** `create-value-object`

### SMELL-006: Message Chain
- **File:** `src/Application/Handler/CreateOrderHandler.php:34`
- **Code:** `$user->getCompany()->getAddress()->getCountry()`
- **Issue:** Law of Demeter violation, tight coupling
- **Refactoring:** Add shortcut method or delegate

## Info Issues

### SMELL-007: Long Method
- **File:** `src/Infrastructure/Repository/OrderRepository.php:78`
- **Method:** `findByComplexCriteria()`
- **Lines:** 45
- **Issue:** Method approaching complexity threshold
- **Refactoring:** Extract query builder or specification

## Refactoring Priority

1. **Immediate:** God Classes blocking testing
2. **High:** Data Clumps causing duplication
3. **Medium:** Long Parameter Lists
4. **Low:** Message Chains, minor smells

Remediation Skills

SmellRecommended SkillApproach
God Classcreate-use-case, create-domain-serviceExtract focused classes
Feature Envycreate-domain-serviceMove method to data owner
Data Clumpscreate-value-objectExtract Value Object
Long Parameter Listcreate-dto, create-builderIntroduce Parameter Object
Long Methodcreate-use-caseExtract methods
Primitive Obsessioncreate-value-objectReplace with Value Object
Message Chains(refactoring)Hide delegate, extract method
Inappropriate Intimacy(refactoring)Move method, extract class

Quick Analysis Commands

# Full smell detection
echo "=== God Classes ===" && \
find . -name "*.php" -path "*/src/*" -exec wc -l {} \; | awk '$1 > 400' && \
echo "=== Long Parameter Lists ===" && \
grep -rn "function [a-z]*(" --include="*.php" src/ | grep -E "(\$[a-z]+,\s*){5,}" && \
echo "=== Primitive Obsession ===" && \
grep -rn "string \$email\|string \$phone\|int \$amount\|float \$price" --include="*.php" src/ && \
echo "=== Message Chains ===" && \
grep -rn "->get[A-Z].*->get[A-Z].*->get[A-Z]" --include="*.php" src/ && \
echo "=== Magic Strings ===" && \
grep -rn "=== '[a-z]*'\|== '[a-z]*'" --include="*.php" src/

Integration with Other Skills

This skill works alongside:

  • analyze-solid-violations — SOLID violations overlap with some smells
  • structural-auditor — architectural context for smells
  • ddd-auditor — domain model quality assessment

References

Based on Martin Fowler's "Refactoring" catalog:

When This Is Acceptable

  • DTOs — Data classes are NOT a code smell; they serve a clear data transfer purpose
  • Configuration classes — Classes with many constants/properties for configuration
  • Builder pattern — Method chaining in builders creates apparent "Feature Envy" but is by design

False Positive Indicators

  • Class has DTO, Request, Response, Config in its name
  • Class implements a Builder pattern with fluent API
  • "Long parameter list" is actually a constructor with proper dependency injection

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.82%
按下载量换算44

Claude

29.74%
按下载量换算37

Cursor

17.63%
按下载量换算22

Gemini CLI

8.69%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills