check-side-effects
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-side-effects" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-3a9c99b1fffbe53feb845516cd21583da24d5015e84a9cd48ccc389e8b881189. 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
Analyze side-effect issues in PHP code. Detect state mutations, global access, static method calls, and I/O operations mixed into business logic, and list the issues found.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Analyzes PHP code for side effect issues. Detects state mutation, global access, static method calls, I/O operations mixed with business logic.
- Testing
- Not tested
Browse files
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
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- PHP副作用检测是开发中的核心痛点,直接影响代码可测试性和维护性
- 具有明确的实用价值,解决高频刚需问题
Highlights
- description清晰描述了核心功能,覆盖多种变体,边界清晰
Highlights
- Phase/步骤清晰,有出口条件,含端到端示例
- frontmatter完整,单文件≤500行
Highlights
- 工具来源明确,参数正确,覆盖主要异常
- 不可逆操作有确认机制
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.