create-template-method

Generate a Template Method pattern implementation for PHP 8.4. Create a base class that defines an abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure, and include unit tests.

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-template-method" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-e7f593941e301c03602402aa53f4a4ee937877bef0eed9f1f620fffacfbcd7fb. 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 Template Method pattern implementation for PHP 8.4. Create a base class that defines an abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure, and include unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.
Audience
| Scenario | Example | |----------|---------| | Common algorithm structure | Data import/export with format variations | | Controlled extension points | Report generation with customizable sections | | Code reuse across variants | Order processing with type-specific steps | | Invariant parts protection | Template rendering with hooks |
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-template-method
description: Generates Template Method pattern for PHP 8.4. Creates abstract algorithm skeleton with customizable steps, allowing subclasses to override specific parts without changing structure. Includes unit tests.

Template Method Pattern Generator

Creates Template Method pattern infrastructure for algorithm skeletons with customizable steps.

When to Use

Scenario Example
Common algorithm structure Data import/export with format variations
Controlled extension points Report generation with customizable sections
Code reuse across variants Order processing with type-specific steps
Invariant parts protection Template rendering with hooks

Component Characteristics

Abstract Template Class

  • Defines algorithm skeleton
  • Implements invariant steps
  • Declares abstract/hook methods
  • Calls methods in sequence

Concrete Implementations

  • Override specific steps
  • Provide algorithm variants
  • Inherit common behavior
  • Maintain overall structure

Hook Methods

  • Optional override points
  • Default empty implementation
  • Allow customization
  • Don't break flow

Generation Process

Step 1: Generate Abstract Template

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

  1. Abstract{Name}Template.php — Algorithm skeleton with template method

Step 2: Generate Concrete Templates

Path: src/Domain/{BoundedContext}/Template/ or src/Application/{BoundedContext}/

  1. {Variant1}{Name}Template.php — First variant implementation
  2. {Variant2}{Name}Template.php — Second variant implementation
  3. {Variant3}{Name}Template.php — Third variant implementation

Step 3: Generate Support Classes (Optional)

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

  1. {Name}Result.php — Result value object
  2. {Name}Config.php — Configuration value object

Step 4: Generate Tests

  1. {Variant}{Name}TemplateTest.php — Individual template tests
  2. Abstract{Name}TemplateTest.php — Template skeleton tests

File Placement

Component Path
Abstract Template src/Domain/{BoundedContext}/Template/
Concrete Templates (Domain logic) src/Domain/{BoundedContext}/Template/
Concrete Templates (App logic) src/Application/{BoundedContext}/
Unit Tests tests/Unit/Domain/{BoundedContext}/Template/

Naming Conventions

Component Pattern Example
Abstract Abstract{Name}Template AbstractDataImporterTemplate
Concrete {Variant}{Name}Template CsvDataImporterTemplate
Template Method execute() or process() execute()
Hook Method before{Step}(), after{Step}() beforeValidation()
Test {ClassName}Test CsvDataImporterTemplateTest

Quick Template Reference

Abstract Template

abstract readonly class Abstract{Name}Template
{
    public function execute({InputType} $input): {OutputType}
    {
        $this->validate($input);
        $data = $this->extract($input);
        $transformed = $this->transform($data);
        $result = $this->load($transformed);
        $this->afterLoad($result);

        return $result;
    }

    abstract protected function extract({InputType} $input): array;
    abstract protected function transform(array $data): array;

    protected function validate({InputType} $input): void
    {
        // Default validation
    }

    protected function afterLoad({OutputType} $result): void
    {
        // Hook method - optional override
    }
}

Concrete Template

final readonly class {Variant}{Name}Template extends Abstract{Name}Template
{
    protected function extract({InputType} $input): array
    {
        // Variant-specific extraction
    }

    protected function transform(array $data): array
    {
        // Variant-specific transformation
    }
}

Usage Example

// Create templates for different formats
$csvImporter = new CsvDataImporterTemplate();
$jsonImporter = new JsonDataImporterTemplate();
$xmlImporter = new XmlDataImporterTemplate();

// Use same interface
$result = $csvImporter->execute($fileContent);

Common Template Method Variants

Domain Variants
Data Import CSV, JSON, XML, Excel
Report Generation PDF, Excel, HTML, Email
Order Processing Standard, Express, International
Document Rendering Markdown, LaTeX, HTML
Payment Flow Card, Bank Transfer, Digital Wallet

Anti-patterns to Avoid

Anti-pattern Problem Solution
Too many abstract methods Hard to implement Use hook methods with defaults
Public template steps Breaks encapsulation Make steps protected/private
Mutable state Side effects Use readonly classes, pass data
Deep inheritance Complexity Limit to 2-3 levels max
Breaking LSP Inconsistent behavior Maintain contract in overrides

References

For complete PHP templates and examples, see:

  • references/templates.md — Abstract Template, Concrete Template, Hook Methods templates
  • references/examples.md — DataImporter, ReportGenerator, OrderProcessor with tests

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 提供完整的模板方法模式生成方案,适用于数据导入、报表生成等多个高频场景
  • 包含抽象模板、具体实现、钩子方法和单元测试的完整架构
  • 具有明确的代码生成路径和命名规范,实用性强
Trigger Precision88/100

Areas to improve

  • 触发场景变体覆盖 Reported severity: Minor

    可补充更多模板方法模式的触发场景变体

    Recommendation: 增加更多领域特定的触发示例,如缓存处理、日志记录等场景

Highlights

  • description 完整描述了核心功能和使用场景
  • 包含详细的适用场景表格和具体示例
  • 触发词清晰准确,边界定义明确
Structure and Standards82/100

Areas to improve

  • 执行出口条件 Reported severity: Minor

    缺少明确的执行完成条件和错误处理说明

    Recommendation: 补充生成完成后的验证步骤和常见错误处理方案

Highlights

  • Phase/步骤划分清晰,包含4个生成阶段
  • 提供完整的文件放置和命名规范
  • 包含端到端代码示例和快速参考模板
Execution Reliability75/100

Areas to improve

  • PHP 8.4 特性说明 Reported severity: Minor

    缺少对 PHP 8.4 特定特性的详细说明和使用指导

    Recommendation: 补充 PHP 8.4 新特性在模板方法模式中的应用说明

  • 依赖管理指导 Reported severity: Minor

    未明确说明如何处理依赖管理和自动加载配置

    Recommendation: 增加 composer.json 配置建议和自动加载设置指导

Highlights

  • 提供完整的代码模板和结构定义
  • 包含单元测试生成和反模式提醒
  • 有明确的最佳实践和Liskov替换原则指导
Evidence Verifiability (mean of the first four)83/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.