suggest-simplification
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "suggest-simplification":https://skillpi.com/zh/skills/deepskill-11f0f4e0d70ebd0c824f9bcc7e025516674eefadedc234c51a83e3a862bf7a37。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
识别并建议代码简化机会,包含可提取的方法、复杂表达式、冗余代码以及重构点的检测建议。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 减记
- 实测状态
- 未测试
文件浏览
Frontmatter
name: suggest-simplification
description: Suggests code simplification opportunities. Identifies extract method candidates, complex expressions, redundant code, refactoring opportunities.Code Simplification Suggestions
Analyze PHP code for simplification and refactoring opportunities.
Simplification Patterns
1. Extract Method
// BEFORE: Long inline code block
public function processOrder(Order $order): void
{
// Validate order (5 lines)
if ($order->getItems()->isEmpty()) {
throw new EmptyOrderException();
}
if ($order->getTotal()->isNegative()) {
throw new InvalidTotalException();
}
// Process payment (10 lines)
$payment = $this->paymentGateway->charge(
$order->getTotal(),
$order->getPaymentMethod()
);
if (!$payment->isSuccessful()) {
throw new PaymentFailedException();
}
// Send notifications (5 lines)
$this->mailer->send($order->getCustomer()->getEmail(), 'order_confirmed');
}
// AFTER: Extracted methods
public function processOrder(Order $order): void
{
$this->validateOrder($order);
$this->processPayment($order);
$this->sendConfirmation($order);
}
private function validateOrder(Order $order): void {}
private function processPayment(Order $order): Payment {}
private function sendConfirmation(Order $order): void {}
2. Introduce Explaining Variable
// BEFORE: Complex expression
if ($user->getSubscription()?->isActive()
&& $user->getCreatedAt() < new DateTime('-30 days')
&& !$user->hasUsedTrial()
&& $user->getOrderCount() > 0) {
$this->offerUpgrade($user);
}
// AFTER: Named variables
$hasActiveSubscription = $user->getSubscription()?->isActive();
$isEstablishedUser = $user->getCreatedAt() < new DateTime('-30 days');
$eligibleForUpgrade = !$user->hasUsedTrial() && $user->getOrderCount() > 0;
if ($hasActiveSubscription && $isEstablishedUser && $eligibleForUpgrade) {
$this->offerUpgrade($user);
}
// EVEN BETTER: Extract to method
if ($user->isEligibleForUpgrade()) {
$this->offerUpgrade($user);
}
3. Remove Redundant Code
// BEFORE: Redundant checks
if ($value !== null) {
if ($value !== null) { // Duplicate check
$this->process($value);
}
}
// BEFORE: Unnecessary else
if ($condition) {
return $a;
} else {
return $b;
}
// AFTER: Simplified
if ($condition) {
return $a;
}
return $b;
// BEFORE: Redundant boolean
if ($condition === true) {}
return $value === true;
// AFTER: Simplified
if ($condition) {}
return $value;
4. Simplify Conditionals
// BEFORE: Nested conditionals
if ($user !== null) {
if ($user->isActive()) {
if ($user->hasPermission('edit')) {
return true;
}
}
}
return false;
// AFTER: Combined condition
return $user !== null
&& $user->isActive()
&& $user->hasPermission('edit');
// BEFORE: Negative condition
if (!$items->isEmpty()) {
$this->process($items);
}
// AFTER: Positive condition
if ($items->isNotEmpty()) {
$this->process($items);
}
5. Replace Temp with Query
// BEFORE: Temporary variable used once
$basePrice = $order->getBasePrice();
$discount = $basePrice * 0.1;
return $basePrice - $discount;
// AFTER: Inline or method
return $order->getBasePrice() * 0.9;
// Or if complex:
return $order->getBasePrice() - $this->calculateDiscount($order);
6. Use Collection Methods
// BEFORE: Manual loop
$active = [];
foreach ($users as $user) {
if ($user->isActive()) {
$active[] = $user;
}
}
// AFTER: array_filter
$active = array_filter($users, fn($user) => $user->isActive());
// BEFORE: Manual map
$emails = [];
foreach ($users as $user) {
$emails[] = $user->getEmail();
}
// AFTER: array_map
$emails = array_map(fn($user) => $user->getEmail(), $users);
// BEFORE: Manual find
$found = null;
foreach ($items as $item) {
if ($item->getId() === $id) {
$found = $item;
break;
}
}
// AFTER: Collection method
$found = $collection->first(fn($item) => $item->getId() === $id);
7. Replace Switch with Polymorphism
// BEFORE: Switch on type
public function calculateShipping(Order $order): Money
{
switch ($order->getShippingMethod()) {
case 'standard':
return $this->calculateStandardShipping($order);
case 'express':
return $this->calculateExpressShipping($order);
case 'overnight':
return $this->calculateOvernightShipping($order);
default:
throw new InvalidMethodException();
}
}
// AFTER: Strategy pattern
interface ShippingCalculator {
public function calculate(Order $order): Money;
}
class StandardShipping implements ShippingCalculator {}
class ExpressShipping implements ShippingCalculator {}
public function calculateShipping(Order $order): Money
{
return $this->shippingCalculators
->get($order->getShippingMethod())
->calculate($order);
}
8. Null Object Pattern
// BEFORE: Null checks everywhere
if ($user->getAddress() !== null) {
echo $user->getAddress()->getCity();
} else {
echo 'Unknown';
}
// AFTER: Null Object
class NullAddress implements AddressInterface
{
public function getCity(): string
{
return 'Unknown';
}
}
// Always safe to call
echo $user->getAddress()->getCity();
9. Guard Clauses
// BEFORE: Deeply nested
public function process(Request $request): Response
{
if ($request !== null) {
if ($request->isValid()) {
if ($this->canProcess($request)) {
return $this->doProcess($request);
} else {
return $this->error('Cannot process');
}
} else {
return $this->error('Invalid request');
}
} else {
return $this->error('No request');
}
}
// AFTER: Guard clauses
public function process(Request $request): Response
{
if ($request === null) {
return $this->error('No request');
}
if (!$request->isValid()) {
return $this->error('Invalid request');
}
if (!$this->canProcess($request)) {
return $this->error('Cannot process');
}
return $this->doProcess($request);
}
10. Use Modern PHP Features
// BEFORE: Old syntax
$name = isset($data['name']) ? $data['name'] : 'default';
// AFTER: Null coalescing
$name = $data['name'] ?? 'default';
// BEFORE: Property assignment
$value = $object->getValue();
if ($value !== null) {
echo $value;
}
// AFTER: Nullsafe operator
echo $object?->getValue();
// BEFORE: Match as if/else
if ($status === 'active') {
$color = 'green';
} elseif ($status === 'pending') {
$color = 'yellow';
} else {
$color = 'red';
}
// AFTER: Match expression
$color = match($status) {
'active' => 'green',
'pending' => 'yellow',
default => 'red',
};
Severity Classification
| Pattern | Severity |
|---|---|
| Deeply nested code | 🟠 Major |
| Repeated code blocks | 🟠 Major |
| Complex boolean expressions | 🟡 Minor |
| Old syntax available in modern PHP | 🟢 Suggestion |
| Verbose but clear code | 🟢 Suggestion |
Output Format
### Simplification: [Description]
**Severity:** 🟠/🟡/🟢
**Location:** `file.php:line`
**Type:** [Extract Method|Guard Clause|Collection Method|...]
**Issue:**
[Description of the complexity]
**Current:**
```php
// Complex code
Suggested:
// Simplified code
Benefits:
- Improved readability
- Reduced cognitive load
- Easier testing
- Better reusability
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 面向PHP开发者提供代码简化建议,具有明确的实用价值
- 覆盖多种重构模式,适用于日常开发场景
亮点
- 触发词完整覆盖多种变体,边界清晰
- description准确描述了Skill的核心功能
亮点
- Phase/步骤清晰,有端到端示例
- frontmatter完整,文档结构良好
亮点
- 工具来源明确,参数正确
- 覆盖主要异常,不可逆操作有确认机制
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。