create-builder

为 PHP 8.4 生成 Builder 模式实现,使用流式接口和验证支持逐步构建对象。包含对应的单元测试示例。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-builder":https://skillpi.com/zh/skills/deepskill-0ef1c1cd4b13e67ef9a5bf9837ed81de062ba204c63099588f1fa83fa624b356。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 8.4 生成 Builder 模式实现,使用流式接口和验证支持逐步构建对象。包含对应的单元测试示例。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
软件、账号及付费要求
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: create-builder
description: Generates Builder pattern for PHP 8.4. Creates step-by-step object construction with fluent interface and validation. Includes unit tests.

Builder Pattern Generator

Creates Builder pattern infrastructure for step-by-step construction of complex objects.

When to Use

Scenario Example
Many constructor parameters Order with 10+ fields
Optional parameters Email with optional CC, BCC
Complex validation Build-time validation
Step-by-step construction Query building
Multiple representations Different order types

Component Characteristics

Builder Interface

  • Defines building steps
  • Returns self for fluent interface
  • Has build() method for final product

Concrete Builder

  • Implements building steps
  • Maintains product state
  • Validates before building

Director (Optional)

  • Defines construction order
  • Reusable build sequences
  • Hides complexity from client

Generation Process

Step 1: Analyze Requirements

Determine:

  • Target product class
  • Required vs optional properties
  • Validation rules
  • Whether Director is needed

Step 2: Generate Builder Components

Path: src/Domain/{BoundedContext}/Builder/

  1. {Name}BuilderInterface.php — Builder contract
  2. {Name}Builder.php — Concrete builder implementation
  3. BuilderValidationException.php — Validation exception
  4. {Name}Director.php — Optional director for common builds

Step 3: Generate Tests

Path: tests/Unit/Domain/{BoundedContext}/Builder/

  1. {Name}BuilderTest.php — Builder functionality tests

File Placement

Component Path
Builder Interface src/Domain/{BoundedContext}/Builder/
Concrete Builder src/Domain/{BoundedContext}/Builder/
Director src/Domain/{BoundedContext}/Builder/
Exception src/Domain/{BoundedContext}/Builder/
Unit Tests tests/Unit/Domain/{BoundedContext}/Builder/

Naming Conventions

Component Pattern Example
Interface {Name}BuilderInterface OrderBuilderInterface
Concrete Builder {Name}Builder OrderBuilder
Director {Name}Director OrderDirector
Exception BuilderValidationException BuilderValidationException
Test {ClassName}Test OrderBuilderTest

Quick Template Reference

Builder Interface

interface {Name}BuilderInterface
{
    public function with{Property1}({Type1} $value): self;
    public function with{Property2}({Type2} $value): self;
    public function build(): {Product};
    public function reset(): self;
}

Concrete Builder

final class {Name}Builder implements {Name}BuilderInterface
{
    private ?{Type1} ${property1} = null;
    private ?{Type2} ${property2} = null;
    private array $errors = [];

    public function with{Property1}({Type1} $value): self
    {
        $this->{property1} = $value;
        return $this;
    }

    public function build(): {Product}
    {
        $this->validate();
        if ($this->errors !== []) {
            throw new BuilderValidationException($this->errors);
        }
        return new {Product}(...);
    }

    public function reset(): self
    {
        $this->{property1} = null;
        $this->errors = [];
        return $this;
    }
}

Director

final readonly class {Name}Director
{
    public function __construct(private {Name}BuilderInterface $builder) {}

    public function buildMinimal{Name}(/* required params */): {Product}
    {
        return $this->builder
            ->reset()
            ->with{Required1}($value1)
            ->build();
    }

    public function buildFull{Name}(/* all params */): {Product}
    {
        return $this->builder
            ->reset()
            ->with{Property1}($value1)
            ->with{Property2}($value2)
            ->build();
    }
}

Usage Example

// Direct builder usage
$order = (new OrderBuilder())
    ->forCustomer($customerId)
    ->withShippingAddress($address)
    ->addItem($item1)
    ->addItem($item2)
    ->withDiscountCode('SAVE10')
    ->build();

// Using Director
$director = new OrderDirector(new OrderBuilder());
$minimalOrder = $director->buildMinimalOrder($customerId, $address, $item);
$giftOrder = $director->buildGiftOrder($customerId, $shipping, $billing, $items, 'Happy Birthday!');

Anti-patterns to Avoid

Anti-pattern Problem Solution
No Validation Invalid objects built Validate in build()
Mutable Product Product can change after build Return immutable objects
Missing Reset Builder state persists Add reset() method
Too Many Steps Hard to use Use Director or defaults
No Fluent Interface Verbose client code Return self from setters

References

For complete PHP templates and examples, see:

  • references/templates.md — Builder, QueryBuilder templates
  • references/examples.md — OrderBuilder, EmailBuilder examples and tests

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值75/100

亮点

  • 提供 PHP 8.4 Builder 模式的完整生成能力
  • 适用于复杂对象构建、可选参数、验证等实际开发场景
  • 包含单元测试生成,提升代码质量
触发精准90/100

亮点

  • description 明确描述了核心功能:生成 Builder 模式、流式接口、验证、单元测试
  • 触发词完整,边界清晰,用户能准确理解 Skill 用途
结构规范95/100

亮点

  • 文档结构完整,包含使用场景、组件特性、生成流程、文件位置、命名规范等
  • 提供了详细的代码模板和使用示例
  • frontmatter 完整,单文件结构合理
执行可靠70/100

待提升项

  • 工具来源不明 原报告严重程度:轻微

    文档提供了完整的代码模板和文件结构说明,但未明确说明生成这些文件的具体工具或方法

    改进建议:建议补充说明生成 Builder 文件的具体工具或 CLI 命令,提升执行可靠性

亮点

  • 提供了完整的 Builder 模式实现模板
  • 包含验证机制和异常处理设计
  • 给出了 Director 模式的实现方案
证据可验 (前四项均值)83/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

翻译待完成,请参阅来源文档。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。