check-encapsulation

Analyze encapsulation violations in PHP code. Detect public mutable state, exposed internal implementations, violations of the 'command–query separation' principle, misuse of getters/setters, and breaches of information hiding.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

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-encapsulation" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-3a652009a4fc933bc631c69a94bb752483e0dfc2135f95abb1aaf241f89a7e7c. 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 encapsulation violations in PHP code. Detect public mutable state, exposed internal implementations, violations of the 'command–query separation' principle, misuse of getters/setters, and breaches of information hiding.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Analyzes PHP code for encapsulation violations. Detects public mutable state, exposed internals, Tell Don't Ask violations, getter/setter abuse, and information hiding breaches.
Audience
Reviewing Domain layer entities and aggregates Detecting anemic domain models Checking for Law of Demeter violations Auditing collection exposure patterns Evaluating getter/behavior ratio in entities
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: check-encapsulation
description: Analyzes PHP code for encapsulation violations. Detects public mutable state, exposed internals, Tell Don't Ask violations, getter/setter abuse, and information hiding breaches.

Encapsulation Analyzer

Overview

This skill analyzes PHP codebases for encapsulation violations — situations where internal state is exposed, getters/setters replace behavior, or the "Tell, Don't Ask" principle is violated.

When to Use

  • Reviewing Domain layer entities and aggregates
  • Detecting anemic domain models
  • Checking for Law of Demeter violations
  • Auditing collection exposure patterns
  • Evaluating getter/behavior ratio in entities

Encapsulation Principles

Principle Description Violation Indicator
Information Hiding Internal state not exposed Public properties, many getters
Tell Don't Ask Objects perform actions, not expose data Getter chains, external decisions
Behavioral Richness Objects have behavior, not just data Anemic domain model
Invariant Protection State changes validate constraints Public setters without validation

Analysis Approach

  1. Phase 1 — Public Mutable State: Scan Domain entities for non-readonly public properties
  2. Phase 2 — Getter/Setter Abuse: Count getters vs behavior methods, flag anemic entities
  3. Phase 3 — Tell Don't Ask: Detect getter chains and external conditionals on object state
  4. Phase 4 — Collection Exposure: Find methods returning internal arrays/collections directly
  5. Phase 5 — Exposed Internals: Check for reflection usage, debug methods, mutable object returns
  6. Phase 6 — Constructor Issues: Flag too many dependencies, complex construction without factories

Detection Rules

ID Pattern Grep Target
ENC-01 Public mutable props public string\|public int\|public array in Domain (exclude readonly)
ENC-02 Setter methods public function set[A-Z] in Entity/Aggregate
ENC-03 Getter chains ->get[A-Z].*->get[A-Z].*->get[A-Z]
ENC-04 External conditionals if \(\$.*->get[A-Z].*===
ENC-05 Switch on state switch \(\$.*->get[A-Z]\|match \(\$.*->get[A-Z]
ENC-06 Collection return public function get.*\(\): array in Entity
ENC-07 Doctrine exposure public function get.*\(\): Collection in Domain
ENC-08 Reflection access ReflectionClass\|ReflectionProperty\|setAccessible
ENC-09 Debug exposure public function toArray\(\)\|dump\(\)\|debug\(\) in Domain
ENC-10 Complex construction new [A-Z].*Entity\(\|new [A-Z].*Aggregate\( in Application

Severity Classification

Issue Severity
Public mutable state in Entity Critical
Collection mutated externally Critical
Anemic entity (ratio > 5.0) Critical
Tell Don't Ask violation Major
Getter chain (3+ levels) Major
Internal array returned Major
Setter in Aggregate Minor
Reflection in non-test code Minor

Report Format

# Encapsulation Analysis Report

## Summary

| Issue Type | Critical | Warning | Info |
|------------|----------|---------|------|
| Public Mutable State | N | N | - |
| Getter/Setter Abuse | N | N | N |
| Tell Don't Ask | N | N | - |
| Collection Exposure | N | N | - |
| Exposed Internals | N | N | N |

**Encapsulation Score: X%**

## Findings

### [ID]: [Title]
- **File:** `path:line`
- **Issue:** [Description]
- **Code:** [Problematic snippet]
- **Expected:** [Correct pattern]
- **Skills:** [Related generator skills]

## Getter/Behavior Ratio

| Entity | Getters | Setters | Behavior | Ratio | Status |
|--------|---------|---------|----------|-------|--------|

**Target:** Ratio < 2.0

## Refactoring Recommendations

### Immediate
1. Make all entity properties private
2. Replace setters with behavior methods
3. Return collection copies, not references

### Short-term
4. Extract Value Objects for validated data
5. Add factory methods for complex construction
6. Remove getter chains (add shortcut methods)

### Long-term
7. Review anemic entities for missing behavior
8. Consider CQRS to separate read/write models

Integration

Works with:

  • detect-code-smells — Feature Envy, Anemic Model
  • structural-auditor — DDD compliance
  • create-entity — Generate rich entities
  • create-value-object — Encapsulated value types

References

  • references/patterns.md — detailed detection patterns with code examples, report format samples, metrics examples, and rich entity template
  • "Tell, Don't Ask" — Martin Fowler
  • "Anemic Domain Model" — Martin Fowler
  • "Object-Oriented Software Construction" (Bertrand Meyer)
  • "Elegant Objects" (Yegor Bugayenko)

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value68/100

Highlights

  • 针对 PHP 领域模型封装问题的专业分析工具,解决贫血模型、信息泄露等明确痛点
  • 提供 10 条具体检测规则与严重性分级,具备工程实用性
Trigger Precision85/100

Highlights

  • 触发描述清晰,覆盖 Public Mutable State、Getter/Setter Abuse 等多种封装违规场景
  • Detection Rules 提供具体 grep 模式,边界定义明确
Structure and Standards92/100

Highlights

  • 结构完整,包含 6 阶段分析流程与端到端报告示例
  • frontmatter 规范,文档长度适中,排版清晰
Execution Reliability75/100

Areas to improve

  • 缺少误报处理机制说明 Reported severity: Minor

    未说明如何处理误报、是否支持配置文件排除特定路径或规则

    Recommendation: 建议补充误报处理策略,如添加配置文件支持规则排除或路径忽略

Highlights

  • 严重性分类合理,Critical/Major/Minor 定义清晰
  • 报告格式包含具体修复建议与相关技能集成指引
Evidence Verifiability (mean of the first four)80/100

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.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

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.