create-strategy

Generate Strategy pattern code for PHP 8.4. Create a family of interchangeable algorithms, including a context class, strategy interface and concrete implementations, with 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-strategy" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-e937158cd1d3ab7af66717482836b8864174aa405d24d599044f8c81762d3805. 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 Strategy pattern code for PHP 8.4. Create a family of interchangeable algorithms, including a context class, strategy interface and concrete implementations, with unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Strategy pattern for PHP 8.4. Creates interchangeable algorithm families with context class, strategy interface, and concrete implementations. Includes unit tests.
Audience
| Scenario | Example | |----------|---------| | Multiple algorithms | Pricing, tax, shipping calculation | | Runtime selection | Payment processing based on amount | | Avoiding conditionals | Replace switch/if-else chains | | Algorithm families | Sorting, compression, encryption |
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-strategy
description: Generates Strategy pattern for PHP 8.4. Creates interchangeable algorithm families with context class, strategy interface, and concrete implementations. Includes unit tests.

Strategy Pattern Generator

Creates Strategy pattern infrastructure for interchangeable algorithm families.

When to Use

Scenario Example
Multiple algorithms Pricing, tax, shipping calculation
Runtime selection Payment processing based on amount
Avoiding conditionals Replace switch/if-else chains
Algorithm families Sorting, compression, encryption

Component Characteristics

StrategyInterface

  • Defines algorithm contract
  • Single method for execution
  • Supports method for selection

Strategy Resolver

  • Resolves appropriate strategy
  • Based on input criteria
  • Falls back to default

Concrete Strategies

  • Implement specific algorithms
  • Interchangeable via interface
  • Encapsulate algorithm details

Generation Process

Step 1: Generate Strategy Interface

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

  1. {Name}StrategyInterface.php — Algorithm contract with supports method

Step 2: Generate Concrete Strategies

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

  1. {Variant1}{Name}Strategy.php — First algorithm implementation
  2. {Variant2}{Name}Strategy.php — Second algorithm implementation
  3. Default{Name}Strategy.php — Fallback implementation

Step 3: Generate Resolver

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

  1. {Name}StrategyResolver.php — Strategy selection logic

Step 4: Generate Service (Optional)

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

  1. {Name}Service.php — Facade using resolver

Step 5: Generate Tests

  1. {Variant}{Name}StrategyTest.php — Individual strategy tests
  2. {Name}StrategyResolverTest.php — Resolver tests

File Placement

Component Path
Strategy Interface src/Domain/{BoundedContext}/Strategy/
Concrete Strategies src/Domain/{BoundedContext}/Strategy/
Resolver src/Domain/{BoundedContext}/Strategy/
Unit Tests tests/Unit/Domain/{BoundedContext}/Strategy/

Naming Conventions

Component Pattern Example
Interface {Name}StrategyInterface PricingStrategyInterface
Concrete {Variant}{Name}Strategy BulkPricingStrategy
Context {Name}Context PricingContext
Resolver {Name}StrategyResolver PricingStrategyResolver
Test {ClassName}Test BulkPricingStrategyTest

Quick Template Reference

Strategy Interface

interface {Name}StrategyInterface
{
    public function execute({InputType} $input): {OutputType};
    public function supports({InputType} $input): bool;
}

Concrete Strategy

final readonly class {Variant}{Name}Strategy implements {Name}StrategyInterface
{
    public function execute({InputType} $input): {OutputType}
    {
        {algorithmImplementation}
    }

    public function supports({InputType} $input): bool
    {
        return {condition};
    }
}

Strategy Resolver

final readonly class {Name}StrategyResolver
{
    public function __construct(
        private iterable $strategies,
        private {Name}StrategyInterface $defaultStrategy
    ) {}

    public function resolve({InputType} $input): {Name}StrategyInterface
    {
        foreach ($this->strategies as $strategy) {
            if ($strategy->supports($input)) {
                return $strategy;
            }
        }
        return $this->defaultStrategy;
    }
}

Usage Example

// Configure strategies
$resolver = new PricingStrategyResolver(
    strategies: [
        new BulkPricingStrategy(),      // 15% off for 100+ items
        new PromotionalPricingStrategy(), // Active promotion discount
        new VipPricingStrategy(),        // VIP customer discount
    ],
    defaultStrategy: new RegularPricingStrategy()
);

// Use in service
$strategy = $resolver->resolve($pricingContext);
$price = $strategy->calculatePrice($pricingContext);

Common Strategy Examples

Domain Strategies
Pricing Regular, Bulk, Promotional, VIP
Shipping Standard, Express, Free, International
Tax US, EU, Exempt, Zero-rated
Payment Credit Card, PayPal, Bank Transfer
Discount Percentage, Fixed, Buy-One-Get-One

Anti-patterns to Avoid

Anti-pattern Problem Solution
Stateful Strategies Side effects Make strategies readonly
Fat Context Too much coupling Minimal context interface
Missing Resolver Manual strategy selection Use resolver pattern
Over-engineering Single algorithm Don't use pattern
Leaky Abstraction Strategy-specific types Use shared interfaces

References

For complete PHP templates and examples, see:

  • references/templates.md — Strategy Interface, Concrete Strategy, Resolver, Context templates
  • references/examples.md — Pricing, Shipping, Tax strategies and 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

  • 提供完整的 PHP 8.4 策略模式生成方案,涵盖接口、实现、解析器和测试
  • 适用于多种业务场景(定价、支付、物流等),具有广泛实用价值
Trigger Precision90/100

Highlights

  • description 清晰描述功能边界,覆盖策略模式生成的核心需求
Structure and Standards75/100

Areas to improve

  • 文档结构优化 Reported severity: Minor

    文档内容完整但长度超过500行,且 When to Use 和示例章节未使用独立标题

    Recommendation: 建议将文档拆分为多个子章节并使用更清晰的标题结构,控制单文件长度

Highlights

  • 生成流程分步骤说明清晰,包含命名规范、模板和反模式指导
Execution Reliability70/100

Areas to improve

  • 执行细节补充 Reported severity: Minor

    缺少对文件写入、依赖注入等实际执行细节的说明

    Recommendation: 建议补充实际执行时的文件操作说明和依赖管理指导

Highlights

  • 提供了完整的代码模板和结构说明,参数设计合理
Evidence Verifiability (mean of the first four)80/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.