dykyi-roman/awesome-claude-code/create-prototype

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Generates Prototype pattern implementations for PHP 8.4. Creates deep/shallow copy, clone customization, prototype registries, and immutable object duplication.

Install

npx vskill@latest install dykyi-roman/awesome-claude-code/create-prototype

SKILL.md

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
<?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
<?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
<?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
<?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)

bash
# 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

php
// 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

markdown
### 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]

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
96
Repository forks
25
7-day trend score
23

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dykyi-roman/awesome-claude-code/create-prototype/badge)](https://verified-skill.com/skills/dykyi-roman/awesome-claude-code/create-prototype)

Something wrong with this skill or its page? Tell us.