check-side-effects
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "check-side-effects":https://skillpi.com/zh/skills/deepskill-3a9c99b1fffbe53feb845516cd21583da24d5015e84a9cd48ccc389e8b881189。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
分析 PHP 代码中的副作用问题。检测状态变更、全局访问、静态方法调用以及在业务逻辑中混入的 I/O 操作,并对发现的问题进行列举说明。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: check-side-effects
description: Analyzes PHP code for side effect issues. Detects state mutation, global access, static method calls, I/O operations mixed with business logic.Side Effect Check
Analyze PHP code for side effects that reduce testability.
Side Effect Types
- State mutation — Changing object/array state
- Global access — Reading/writing global variables
- I/O operations — File, network, database
- Output — echo, print, header
- External service calls — API, queue, cache
Detection Patterns
1. State Mutation
// SIDE EFFECT: Mutates input
public function normalize(array &$data): void
{
$data['name'] = trim($data['name']);
$data['email'] = strtolower($data['email']);
}
// PURE: Returns new array
public function normalize(array $data): array
{
return [
'name' => trim($data['name']),
'email' => strtolower($data['email']),
];
}
// SIDE EFFECT: Mutates object
public function complete(Order $order): void
{
$order->setStatus('completed');
$order->setCompletedAt(new DateTime());
}
// BETTER: Command pattern or event
public function complete(Order $order): OrderCompletedEvent
{
return new OrderCompletedEvent($order->getId(), new DateTimeImmutable());
}
2. Global Variable Access
// SIDE EFFECT: Reads global
function getUser(): ?User
{
global $currentUser;
return $currentUser;
}
// SIDE EFFECT: Superglobal access
public function handleRequest(): Response
{
$userId = $_SESSION['user_id']; // Hidden dependency
$data = $_POST; // Hidden input
}
// BETTER: Explicit parameters
public function handleRequest(Session $session, Request $request): Response
{
$userId = $session->get('user_id');
$data = $request->all();
}
3. Static Property Access
// SIDE EFFECT: Static state
class Counter
{
private static int $count = 0;
public static function increment(): void
{
self::$count++; // Shared mutable state
}
public static function getCount(): int
{
return self::$count;
}
}
// BETTER: Instance state
class Counter
{
private int $count = 0;
public function increment(): void
{
$this->count++;
}
}
4. I/O in Business Logic
// SIDE EFFECT: Mixed concerns
public function calculateDiscount(int $userId): float
{
$user = $this->db->query("SELECT * FROM users WHERE id = ?", [$userId]); // I/O
$orderCount = $this->db->query("SELECT COUNT(*) FROM orders WHERE user_id = ?", [$userId]); // I/O
// Pure calculation
if ($orderCount > 100) return 0.20;
if ($orderCount > 50) return 0.15;
return 0.10;
}
// BETTER: Separated concerns
// Pure function
public function calculateDiscountRate(int $orderCount): float
{
return match(true) {
$orderCount > 100 => 0.20,
$orderCount > 50 => 0.15,
default => 0.10,
};
}
// I/O in service
public function getUserDiscountRate(int $userId): float
{
$orderCount = $this->orderRepository->countByUser($userId);
return $this->calculateDiscountRate($orderCount);
}
5. Output Operations
// SIDE EFFECT: Direct output
public function render(array $data): void
{
echo json_encode($data); // Side effect
header('Content-Type: application/json'); // Side effect
}
// BETTER: Return value
public function render(array $data): JsonResponse
{
return new JsonResponse($data);
}
6. Time and Random
// SIDE EFFECT: Non-deterministic
public function createToken(): Token
{
return new Token(
bin2hex(random_bytes(32)), // Random
new DateTime('+1 hour'), // Current time
);
}
// BETTER: Inject dependencies
public function createToken(
RandomGeneratorInterface $random,
ClockInterface $clock,
): Token {
return new Token(
bin2hex($random->bytes(32)),
$clock->now()->modify('+1 hour'),
);
}
7. Logging and Metrics
// SIDE EFFECT: Logging in calculation
public function calculate(Order $order): Money
{
$this->logger->debug('Starting calculation'); // Side effect
$total = $this->computeTotal($order);
$this->metrics->increment('orders.calculated'); // Side effect
$this->logger->info('Calculated', ['total' => $total]); // Side effect
return $total;
}
// BETTER: Separate concerns
public function calculate(Order $order): Money
{
return $this->computeTotal($order);
}
// Decorate for logging
class LoggingOrderCalculator implements OrderCalculatorInterface
{
public function __construct(
private OrderCalculatorInterface $inner,
private LoggerInterface $logger,
) {}
public function calculate(Order $order): Money
{
$this->logger->debug('Starting calculation');
$total = $this->inner->calculate($order);
$this->logger->info('Calculated', ['total' => $total]);
return $total;
}
}
Grep Patterns
# Echo/print
Grep: "(echo|print)\s+" --glob "**/*.php"
# Header calls
Grep: "header\s*\(" --glob "**/*.php"
# Superglobals
Grep: "\$_(GET|POST|SESSION|COOKIE|SERVER|FILES)" --glob "**/*.php"
# Global keyword
Grep: "global\s+\\\$" --glob "**/*.php"
# Static property write
Grep: "(self|static)::\\\$\w+\s*[+\-*\/]?=" --glob "**/*.php"
# File operations
Grep: "(file_put_contents|fwrite|unlink|mkdir|chmod)\(" --glob "**/*.php"
Severity Classification
| Side Effect | Severity |
|---|---|
| Superglobal access | 🟠 Major |
| Static state mutation | 🟠 Major |
| I/O mixed with logic | 🟠 Major |
| Input mutation | 🟡 Minor |
| Logging in pure logic | 🟢 Suggestion |
Refactoring Strategies
Command/Query Separation
// Query: No side effects
public function getTotalPrice(Order $order): Money;
// Command: Side effects
public function completeOrder(Order $order): void;
Return vs Mutate
// Before: Mutate
$order->applyDiscount($discount);
// After: Return new
$discountedOrder = $order->withDiscount($discount);
Output Format
### Side Effect: [Description]
**Severity:** 🟠/🟡/🟢
**Location:** `file.php:line`
**Type:** [State Mutation|Global Access|I/O|...]
**Issue:**
Method mixes business logic with database I/O.
**Current:**
```php
public function calculateDiscount(int $userId): float
{
$user = $this->db->query(...); // I/O
return $this->computeDiscount($user); // Logic
}
Suggested:
public function calculateDiscount(User $user): float
{
return $this->computeDiscount($user); // Pure
}
Testing Impact:
- Before: Need database or complex mocking
- After: Pass User object, test edge cases easily
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- PHP副作用检测是开发中的核心痛点,直接影响代码可测试性和维护性
- 具有明确的实用价值,解决高频刚需问题
亮点
- description清晰描述了核心功能,覆盖多种变体,边界清晰
亮点
- Phase/步骤清晰,有出口条件,含端到端示例
- frontmatter完整,单文件≤500行
亮点
- 工具来源明确,参数正确,覆盖主要异常
- 不可逆操作有确认机制
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。