create-prototype

Generate a Prototype pattern implementation for PHP 8.4. Includes deep and shallow copy strategies, customizable clone behavior, a prototype registry, and cloning approaches for immutable objects.

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 "create-prototype" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-9b6e5d840465852d069746dc2c6e91c4063ed0bab7548b2b08153e67eafe582e. 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

Generate a Prototype pattern implementation for PHP 8.4. Includes deep and shallow copy strategies, customizable clone behavior, a prototype registry, and cloning approaches for immutable objects.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.
Inputs and outputs
```markdown
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-prototype
description: Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.

Prototype Pattern Generator

Generate Prototype pattern implementations for PHP 8.4 with proper deep/shallow copy semantics.

Pattern Overview

Prototype creates new objects by cloning existing instances, avoiding costly construction and enabling runtime object configuration.

Generation Templates

1. Basic Prototype with Clone

<?php

declare(strict_types=1);

namespace {Namespace}\Domain\{Context};

// Cloning is opted into via the __clone() magic method — PHP has no Cloneable interface
final class {Name}
{
    public function __construct(
        private readonly {IdType} $id,
        private string $title,
        private array $metadata,
        private \DateTimeImmutable $createdAt,
    ) {}

    public function __clone(): void
    {
        // Deep copy mutable objects
        $this->createdAt = clone $this->createdAt;
        // Arrays are copied by value (shallow), but nested objects need cloning
        $this->metadata = array_map(
            fn (mixed $item) => is_object($item) ? clone $item : $item,
            $this->metadata,
        );
    }

    public function withTitle(string $title): self
    {
        $clone = clone $this;
        $clone->title = $title;
        return $clone;
    }

    public function withMetadata(array $metadata): self
    {
        $clone = clone $this;
        $clone->metadata = $metadata;
        return $clone;
    }
}

2. Prototype Registry

<?php

declare(strict_types=1);

namespace {Namespace}\Domain\{Context};

final class {Name}PrototypeRegistry
{
    /** @var array<string, {Name}> */
    private array $prototypes = [];

    public function register(string $key, {Name} $prototype): void
    {
        $this->prototypes[$key] = $prototype;
    }

    public function create(string $key): {Name}
    {
        if (!isset($this->prototypes[$key])) {
            throw new \InvalidArgumentException(
                sprintf('Prototype "%s" not registered. Available: %s', $key, implode(', ', array_keys($this->prototypes))),
            );
        }

        return clone $this->prototypes[$key];
    }

    public function has(string $key): bool
    {
        return isset($this->prototypes[$key]);
    }

    /** @return list<string> */
    public function keys(): array
    {
        return array_keys($this->prototypes);
    }
}

3. Immutable Value Object Prototype

<?php

declare(strict_types=1);

namespace {Namespace}\Domain\{Context}\ValueObject;

final readonly class {Name}
{
    public function __construct(
        private string $currency,
        private int $amount,
        private string $locale,
    ) {}

    // Immutable "clone" via named constructors
    public function withAmount(int $amount): self
    {
        return new self(
            currency: $this->currency,
            amount: $amount,
            locale: $this->locale,
        );
    }

    public function withCurrency(string $currency): self
    {
        return new self(
            currency: $currency,
            amount: $this->amount,
            locale: $this->locale,
        );
    }

    // Factory from prototype
    public static function fromPrototype(self $prototype, int $amount): self
    {
        return new self(
            currency: $prototype->currency,
            amount: $amount,
            locale: $prototype->locale,
        );
    }
}

4. Deep Clone with Object Graph

<?php

declare(strict_types=1);

namespace {Namespace}\Domain\{Context};

final class {Name}
{
    /** @var list<{ChildType}> */
    private array $children;

    private ?{IdType} $pendingId = null;

    public function __construct(
        private readonly {IdType} $id,
        private {ConfigType} $config,
        array $children = [],
    ) {
        $this->children = $children;
    }

    public function __clone(): void
    {
        // PHP 8.3+: __clone() may reassign a readonly property of the object being cloned
        if ($this->pendingId !== null) {
            $this->id = $this->pendingId;
            $this->pendingId = null;
        }

        // Deep clone config object
        $this->config = clone $this->config;

        // Deep clone collection of children
        $this->children = array_map(
            fn ({ChildType} $child): {ChildType} => clone $child,
            $this->children,
        );
    }

    public function duplicate({IdType} $newId): self
    {
        $this->pendingId = $newId;

        try {
            return clone $this;
        } finally {
            $this->pendingId = null;
        }
    }
}

Detection Patterns (Audit)

# Missing __clone on classes with mutable properties
Grep: "class.*\{" --glob "**/Domain/**/*.php"
# Then check for mutable object properties without __clone

# Shallow copy issues (clone without __clone)
Grep: "clone \$this" --glob "**/*.php"
Grep: "function __clone" --glob "**/*.php"

# Manual copy-paste construction (prototype candidate)
Grep: "new self\(.*\$this->" --glob "**/*.php"

# Prototype registry candidates
Grep: "array.*prototype|registry.*clone" --glob "**/*.php"

Anti-Patterns to Avoid

// BAD: Serialization for deep copy (slow, breaks resources)
$clone = unserialize(serialize($original));

// BAD: No __clone with mutable objects
$clone = clone $original;
$clone->getAddress()->setCity('New'); // Modifies original!

// BAD: Clone readonly object without proper handling
final readonly class Order
{
    // Cannot modify properties after clone!
    // Use "with" methods returning new instances instead
}

Output Format

### Prototype Pattern: {Name}

**Files Generated:**
- `src/Domain/{Context}/{Name}.php` — Prototype with __clone
- `src/Domain/{Context}/{Name}PrototypeRegistry.php` — Registry (if needed)

**Clone Strategy:**
- Deep copy: [list mutable properties]
- Shallow copy: [list immutable/scalar properties]
- Readonly: [list readonly properties — use with* methods]

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value82/100

Highlights

  • 提供 PHP 8.4 原型模式的完整实现方案,涵盖深拷贝、浅拷贝、克隆定制、原型注册表等高级特性
  • 包含检测模式和反模式指导,帮助用户识别和避免常见错误
  • 代码模板质量高,符合现代 PHP 开发规范
Trigger Precision58/100

Areas to improve

  • 触发词不全 Reported severity: Minor

    description 描述了功能但未提供具体触发指令示例,用户不清楚如何触发该 Skill

    Recommendation: 在 description 或 skill_body 开头添加触发示例,如:'当用户请求"生成 PHP 原型模式"或"创建深拷贝类"时触发'

Structure and Standards76/100

Areas to improve

  • 缺少 When to Use 章节 Reported severity: Minor

    文档未明确说明该 Skill 的适用场景和使用时机

    Recommendation: 在 Pattern Overview 后添加 'When to Use' 章节,说明何时应该使用原型模式

  • 缺少端到端示例 Reported severity: Minor

    虽然有代码模板,但缺少完整的用户交互示例展示从触发到生成结果的完整流程

    Recommendation: 添加一个完整的端到端示例,展示用户输入和 Skill 输出的对应关系

Highlights

  • 文档结构清晰,包含多个实用模板和检测模式
  • frontmatter 完整,代码示例详细且符合 PHP 8.4 规范
Execution Reliability72/100

Areas to improve

  • 模板占位符未说明 Reported severity: Minor

    代码模板中包含 {Namespace}、{Context}、{Name} 等占位符,但未提供替换说明

    Recommendation: 在 Output Format 前添加占位符说明章节,解释每个占位符的含义和替换规则

Highlights

  • 代码实现基于 PHP 8.4 最新语法,可靠性高
  • 正确处理了 readonly 属性的克隆问题,覆盖主要异常场景
Evidence Verifiability (mean of the first four)72/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.