用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Dev-Toolbelt/dev-team-agents --skill object-calisthenics命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | object-calisthenics |
| description | Object Calisthenics — 9 rules for encapsulation and OOP simplicity. |
9 rules for better object-oriented code. Apply as many as the project's context justifies — they are constraints, not commandments.
Each method should have at most one if, for, while nesting level. Extract deeper logic into private methods.
// Bad
function processOrders($orders) {
foreach ($orders as $order) {
if ($order->isActive()) {
foreach ($order->items as $item) {
// logic here
}
}
}
}
// Good
function processOrders($orders) {
foreach ($orders as $order) {
$this->processActiveOrder($order);
}
}
else KeywordUse early returns, guard clauses, or strategy pattern instead.
// Bad
if ($user->isAdmin()) {
return $this->adminView();
} else {
return $this->guestView();
}
// Good
if ($user->isAdmin()) {
return $this->adminView();
}
return $this->guestView();
Primitives that have behavior or validation belong in a Value Object.
// Bad: string passed around, validated in multiple places
function sendEmail(string $email) { ... }
// Good: validation lives in the Value Object
function sendEmail(Email $email) { ... }
Apply when the primitive has: validation rules, formatting, or business meaning.
A class that contains a collection should have no other instance variables.
// Bad: array mixed with other data
class Order {
private array $items;
private string $status;
}
// Good: collection has its own class
class OrderItems {
private array $items;
public function totalPrice(): Money { ... }
public function count(): int { ... }
}
Don't chain calls through multiple objects. Talk only to your immediate neighbors.
// Bad: violates LoD
$city = $order->getCustomer()->getAddress()->getCity();
// Good: ask, don't reach
$city = $order->customerCity();
Names should be clear and complete. Abbreviations hide intent.
// Bad
$ord, $usr, $mgr, $calc
// Good
$order, $user, $manager, $calculator
If a name is too long, the class might be doing too much.
If a class grows beyond this, extract responsibilities.
Classes with fewer instance variables have stronger cohesion. This forces decomposition into smaller, focused objects.
// Bad
class Customer {
private string $name;
private string $email;
private string $street;
private string $city;
private string $country;
}
// Good
class Customer {
private Name $name;
private Email $email;
private Address $address;
}
Don't expose internals. Tell objects to do things rather than asking for their data.
// Bad: asking for data, processing outside the object
$discount = $product->getPrice() * $product->getDiscountRate();
// Good: tell the object to calculate its own discount
$discount = $product->calculateDiscount();
Start with Rules 1, 2, and 6 — they have the highest impact with the least resistance.
Rules 3, 4, and 8 are most valuable in domain-heavy code (business logic, entities, value objects).
Rules 5, 7, and 9 guide long-term architecture — apply gradually.
In code reviews, flag violations by rule number: [OC-Rule-2] Else clause can be removed with early return.