analyze-solid-violations

分析 PHP 代码库中违反 SOLID 原则的工具或报告。检测上帝类(单一职责原则)、类型切换(开闭原则)、契约破坏(里氏替换原则)、臃肿接口(接口隔离原则)以及具体依赖(依赖倒置原则),并生成包含严重性等级和可操作修复建议的报告。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "analyze-solid-violations":https://skillpi.com/zh/skills/deepskill-4d8c733b6678dd15e1c234b97ab669bce5a3797ce9a2b797e44180e707a5148a。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

分析 PHP 代码库中违反 SOLID 原则的工具或报告。检测上帝类(单一职责原则)、类型切换(开闭原则)、契约破坏(里氏替换原则)、臃肿接口(接口隔离原则)以及具体依赖(依赖倒置原则),并生成包含严重性等级和可操作修复建议的报告。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
减记
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: analyze-solid-violations
description: Analyzes PHP codebase for SOLID principle violations. Detects God classes (SRP), type switches (OCP), broken contracts (LSP), fat interfaces (ISP), and concrete dependencies (DIP). Generates actionable reports with severity levels and remediation recommendations.

SOLID Violations Analyzer

Overview

This skill analyzes PHP codebases for SOLID principle violations and generates detailed reports with severity levels and remediation recommendations.

Analysis Workflow

Step 1: Scope Identification

Determine analysis scope from user input or detect automatically:

# Detect project structure
ls -la src/

# Identify key directories
find . -type d -name "Domain" -o -name "Application" -o -name "Infrastructure"

Step 2: Run Detection Patterns

Execute detection patterns for each SOLID principle.

SRP (Single Responsibility) Detection

God Class Detection

# Find large classes (>500 lines)
find . -name "*.php" -path "*/src/*" -exec wc -l {} \; | awk '$1 > 500 {print "CRITICAL: " $0}'

# Find classes with many methods
for file in $(find . -name "*.php" -path "*/src/*"); do
  count=$(grep -c "public function" "$file" 2>/dev/null || echo 0)
  if [ "$count" -gt 15 ]; then
    echo "WARNING: $file has $count public methods"
  fi
done

# Classes with problematic names
grep -rn "class.*Manager\|class.*Handler\|class.*Helper\|class.*Util" --include="*.php" src/

High Dependency Count

# Count constructor dependencies
grep -rn "__construct" --include="*.php" -A 20 src/ | \
  grep -E "private|readonly" | \
  awk -F: '{files[$1]++} END {for(f in files) if(files[f]>7) print "WARNING: " f " has " files[f] " dependencies"}'

Multiple Responsibility Indicators

# Classes with "And" in name
grep -rn "class\s\+\w*And\w*" --include="*.php" src/

# Check for mixed concerns
grep -rn "class.*Service" --include="*.php" src/ -l | while read file; do
  if grep -q "Repository\|Mailer\|Logger" "$file"; then
    echo "INFO: $file may have mixed concerns"
  fi
done

OCP (Open/Closed) Detection

Type Switch Detection

# Switch on type property
grep -rn "switch.*->type\|match.*->type\|match.*::class" --include="*.php" src/

# instanceof chains
grep -rn "if.*instanceof\|elseif.*instanceof" --include="*.php" src/

# Type-based conditionals
grep -rn "if.*getType\(\)\s*===\|if.*->type\s*===" --include="*.php" src/

# Hardcoded type maps
grep -rn "\[.*::class\s*=>" --include="*.php" src/

Extension Indicators

# Classes that need frequent modification (check git history if available)
git log --since="3 months ago" --name-only --pretty=format: -- "*.php" | \
  sort | uniq -c | sort -rn | head -20

LSP (Liskov Substitution) Detection

Contract Violations

# NotImplementedException throws
grep -rn "throw.*NotImplemented\|throw.*NotSupported\|throw.*UnsupportedOperation" --include="*.php" src/

# Empty method overrides
grep -rn "public function.*\{[\s]*\}" --include="*.php" src/

# Parent type checks in child classes
grep -rn "if.*parent::\|parent::.*?:" --include="*.php" src/

Precondition/Postcondition Issues

# Additional validation in overrides
grep -rn "function.*override" --include="*.php" -A 10 src/ | grep "if.*throw"

# Return null where parent might not
grep -rn "return\s*null;" --include="*.php" src/

ISP (Interface Segregation) Detection

Fat Interface Detection

# Count methods in interfaces
for file in $(find . -name "*.php" -path "*/src/*" -exec grep -l "^interface" {} \;); do
  count=$(grep -c "public function" "$file" 2>/dev/null || echo 0)
  if [ "$count" -gt 5 ]; then
    echo "WARNING: $file interface has $count methods"
  fi
  if [ "$count" -gt 8 ]; then
    echo "CRITICAL: $file interface has $count methods - consider splitting"
  fi
done

Unused Interface Methods

# Find "// TODO" or "// not implemented" in interface implementations
grep -rn "//\s*TODO\|//\s*not implemented\|//\s*unused" --include="*.php" src/

# Empty implementations
grep -rn "function.*\{[\s]*return;\s*\}" --include="*.php" src/

Generic Interface Names

# Overly generic interface names
grep -rn "interface\s\+\(Service\|Manager\|Handler\)\s*$" --include="*.php" src/

DIP (Dependency Inversion) Detection

Direct Instantiation

# New in methods (excluding exceptions, DateTime, stdClass)
grep -rn "new\s\+[A-Z]" --include="*.php" src/ | \
  grep -v "Exception\|DateTime\|stdClass\|DateTimeImmutable\|ArrayObject\|SplQueue"

# Static method calls to concrete classes
grep -rn "[A-Z][a-z]*::[a-z]" --include="*.php" src/ | \
  grep -v "self::\|static::\|parent::\|Uuid::\|Money::"

Concrete Type Hints

# Constructor with concrete types (not interfaces)
grep -rn "__construct" --include="*.php" -A 15 src/ | \
  grep -E "(private|readonly)\s+[A-Z][a-z]*[A-Z][a-z]*\s+\\\$" | \
  grep -v "Interface\|Abstract\|Contract"

Service Locator Anti-pattern

# Container/locator usage
grep -rn "container->get\|app()->make\|\\\$this->get(" --include="*.php" src/

Report Generation

Analysis Output Format

# SOLID Violations Report

## Summary

| Principle | Critical | Warning | Info |
|-----------|----------|---------|------|
| SRP | X | X | X |
| OCP | X | X | X |
| LSP | X | X | X |
| ISP | X | X | X |
| DIP | X | X | X |

## Critical Violations

### SRP-001: God Class
- **File:** `src/Service/UserManager.php`
- **Lines:** 847
- **Issue:** Class exceeds 500 lines with 23 public methods
- **Recommendation:** Extract into focused classes
- **Skills:** `create-use-case`, `create-domain-service`

### OCP-001: Type Switch
- **File:** `src/Payment/PaymentProcessor.php:45`
- **Issue:** Switch on payment type requires modification for new types
- **Recommendation:** Apply Strategy pattern
- **Skills:** `create-strategy`

## Warning Violations

### ISP-001: Fat Interface
- **File:** `src/Repository/UserRepository.php`
- **Methods:** 12
- **Issue:** Interface too large, clients forced to depend on unused methods
- **Recommendation:** Segregate into UserReader, UserWriter, UserStats

## Remediation Priority

1. **Immediate:** God classes blocking testing
2. **High:** Type switches preventing extension
3. **Medium:** Fat interfaces causing coupling
4. **Low:** Minor DIP violations

Severity Classification

Severity Criteria Action
CRITICAL >500 LOC, >10 deps, NotImplementedException Immediate refactoring
WARNING 300-500 LOC, 7-10 deps, type switches Plan refactoring
INFO 200-300 LOC, minor issues Monitor in next iteration

Remediation Skills

Violation Recommended Skill
God Class create-use-case
Type Switch create-strategy
No Interface create-repository
Domain Logic create-domain-service
Value Extraction create-value-object
Factory Missing create-factory
Decorator Need create-decorator

Quick Analysis Commands

# Full analysis
echo "=== SRP ===" && \
find . -name "*.php" -path "*/src/*" -exec wc -l {} \; | awk '$1 > 400' && \
echo "=== OCP ===" && \
grep -rn "switch.*type\|match.*::class" --include="*.php" src/ && \
echo "=== LSP ===" && \
grep -rn "NotImplemented\|NotSupported" --include="*.php" src/ && \
echo "=== ISP ===" && \
for f in $(find . -name "*.php" -exec grep -l "^interface" {} \;); do \
  c=$(grep -c "public function" "$f"); [ $c -gt 5 ] && echo "$f: $c methods"; \
done && \
echo "=== DIP ===" && \
grep -rn "new\s\+[A-Z]" --include="*.php" src/ | grep -v "Exception\|DateTime" | head -20

Integration with solid-knowledge

This analyzer uses detection patterns from solid-knowledge. For detailed principle explanations and patterns, refer to:

  • solid-knowledge/references/srp-patterns.md
  • solid-knowledge/references/ocp-patterns.md
  • solid-knowledge/references/lsp-patterns.md
  • solid-knowledge/references/isp-patterns.md
  • solid-knowledge/references/dip-patterns.md
  • solid-knowledge/references/antipatterns.md

Report Template

See assets/report-template.md for the full report format.

When This Is Acceptable

  • Doctrine entities — Entities may appear to violate SRP due to persistence concerns mixed with domain logic (framework requirement)
  • DTOs/Value Objects — Data classes with many properties don't violate SRP (single responsibility = data transfer)
  • Framework controllers — Slim controllers with inject+validate+delegate are acceptable

False Positive Indicators

  • Class is a DTO, Value Object, or Request/Response object
  • Class is a Doctrine entity with only getters/setters + domain methods
  • Apparent SRP violation is actually framework convention

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 直接解决PHP开发者核心痛点:SOLID原则违规检测
  • 显著提升代码质量与可维护性,具有明确实用价值
  • 提供可操作的修复建议和严重性等级分类
触发精准88/100

亮点

  • 触发词精准完整,覆盖多种变体
  • 边界清晰,description位置正确且内容完整
结构规范85/100

亮点

  • Phase/步骤清晰,有出口条件
  • 含端到端示例,frontmatter完整
  • 单文件≤500行,结构良好
执行可靠82/100

亮点

  • 工具来源明确,参数正确
  • 覆盖主要异常,不可逆操作有确认机制
  • 提供快速分析命令和集成指南
证据可验 (前四项均值)87/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。