check-dependency-injection
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-dependency-injection" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-12ecd6fe358d65726700d670a87d99222ad6e02128326b1c9a308cfb65b69e58. 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 dependency injection issues in PHP code. Detects use of constructor injection, interface dependencies, service locator anti-patterns, and occurrences of the new keyword in business logic.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Analyzes PHP code for dependency injection issues. Detects constructor injection usage, interface dependencies, service locator antipattern, new keyword in business logic.
- Inputs and outputs
- ```markdown
- Testing
- Not tested
Browse files
Frontmatter
name: check-dependency-injection
description: Analyzes PHP code for dependency injection issues. Detects constructor injection usage, interface dependencies, service locator antipattern, new keyword in business logic.Dependency Injection Check
Analyze PHP code for proper dependency injection patterns.
Detection Patterns
1. New Keyword in Business Logic
// BAD: Hard-coded dependency
class OrderService
{
public function process(Order $order): void
{
$mailer = new Mailer(); // Can't mock this
$mailer->send($order->getCustomer(), 'confirmation');
}
}
// GOOD: Injected dependency
class OrderService
{
public function __construct(
private MailerInterface $mailer,
) {}
public function process(Order $order): void
{
$this->mailer->send($order->getCustomer(), 'confirmation');
}
}
2. Service Locator Antipattern
// BAD: Service locator
class UserService
{
public function register(UserData $data): User
{
$hasher = Container::get(PasswordHasher::class);
$repository = Container::get(UserRepository::class);
$mailer = Container::get(Mailer::class);
// Dependencies are hidden
}
}
// GOOD: Constructor injection
class UserService
{
public function __construct(
private PasswordHasher $hasher,
private UserRepository $repository,
private Mailer $mailer,
) {}
// Dependencies are explicit
}
3. Static Method Calls
// BAD: Static calls can't be mocked
class ReportGenerator
{
public function generate(): Report
{
$data = Database::query('SELECT ...'); // Static
$date = Carbon::now(); // Static
$id = Uuid::uuid4(); // Static
return new Report($data, $date, $id);
}
}
// GOOD: Injectable services
class ReportGenerator
{
public function __construct(
private Connection $database,
private ClockInterface $clock,
private UuidGenerator $uuidGenerator,
) {}
public function generate(): Report
{
$data = $this->database->query('SELECT ...');
$date = $this->clock->now();
$id = $this->uuidGenerator->generate();
return new Report($data, $date, $id);
}
}
4. Missing Interface
// BAD: Concrete class dependency
class PaymentProcessor
{
public function __construct(
private StripeGateway $gateway, // Concrete class
) {}
}
// GOOD: Interface dependency
class PaymentProcessor
{
public function __construct(
private PaymentGatewayInterface $gateway, // Interface
) {}
}
5. Hidden Dependencies
// BAD: Uses global/superglobal
class UserController
{
public function current(): User
{
$userId = $_SESSION['user_id']; // Hidden dependency
return $this->repository->find($userId);
}
}
// GOOD: Explicit dependency
class UserController
{
public function __construct(
private SessionInterface $session,
private UserRepository $repository,
) {}
public function current(): User
{
$userId = $this->session->get('user_id');
return $this->repository->find($userId);
}
}
6. Setter Injection Issues
// BAD: Optional setter injection
class OrderService
{
private ?Logger $logger = null;
public function setLogger(Logger $logger): void
{
$this->logger = $logger;
}
public function process(): void
{
$this->logger?->info('Processing'); // May be null
}
}
// GOOD: Constructor injection
class OrderService
{
public function __construct(
private LoggerInterface $logger,
) {}
public function process(): void
{
$this->logger->info('Processing');
}
}
7. Factory Inside Class
// BAD: Factory logic in service
class NotificationService
{
public function send(string $type, string $message): void
{
$channel = match($type) {
'email' => new EmailChannel(),
'sms' => new SmsChannel(),
'push' => new PushChannel(),
};
$channel->send($message);
}
}
// GOOD: Inject factory
class NotificationService
{
public function __construct(
private ChannelFactory $channelFactory,
) {}
public function send(string $type, string $message): void
{
$channel = $this->channelFactory->create($type);
$channel->send($message);
}
}
8. Environment/Config Access
// BAD: Direct environment access
class ApiClient
{
public function request(): Response
{
$key = getenv('API_KEY'); // Hidden dependency
// ...
}
}
// GOOD: Config injection
class ApiClient
{
public function __construct(
private string $apiKey, // Or ApiConfig object
) {}
}
Grep Patterns
# New keyword in methods
Grep: "new\s+[A-Z]\w+\(" --glob "**/*.php"
# Service locator
Grep: "Container::(get|make)|App::(make|resolve)" --glob "**/*.php"
# Static method calls
Grep: "[A-Z]\w+::\w+\(" --glob "**/*.php"
# Superglobals
Grep: "\$_(GET|POST|SESSION|COOKIE|ENV|SERVER)" --glob "**/*.php"
# getenv/putenv
Grep: "(getenv|putenv)\(" --glob "**/*.php"
Acceptable Uses of New
// OK: Value objects and DTOs
new Money(100, 'USD');
new DateTime('now');
new OrderId($uuid);
// OK: Exceptions
throw new InvalidArgumentException();
// OK: In factories (that's their job)
class UserFactory {
public function create(): User {
return new User();
}
}
Severity Classification
| Pattern | Severity |
|---|---|
| Service locator | 🟠 Major |
| New keyword for services | 🟠 Major |
| Static method calls | 🟠 Major |
| Superglobal access | 🟠 Major |
| Missing interface | 🟡 Minor |
| Setter injection | 🟡 Minor |
Output Format
### DI Issue: [Description]
**Severity:** 🟠/🟡
**Location:** `file.php:line`
**Type:** [Service Locator|New Keyword|Static Call|...]
**Issue:**
[Description of the DI problem]
**Current:**
```php
$mailer = new Mailer();
Suggested:
public function __construct(
private MailerInterface $mailer,
) {}
Testing Impact: Cannot mock Mailer in unit tests. With injection, tests can use MockMailer.
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 面向 PHP 开发者提供依赖注入问题检测,解决代码质量与可测试性痛点
- 覆盖多种常见反模式(服务定位器、静态调用、隐藏依赖等),实用性强
Highlights
- description 明确描述功能与检测模式,触发词完整且边界清晰
Highlights
- 结构清晰,分多个 Phase 并提供 BAD/GOOD 示例对比
- frontmatter 完整,文档长度适中
Highlights
- 提供具体 Grep 命令,模式覆盖全面
- 包含可接受场景说明和严重性分类,输出格式明确
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.
-
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 226, 235
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.