create-strategy

为 PHP 8.4 生成策略模式的代码。创建可互换的算法族,包含上下文类、策略接口与具体实现,并附带单元测试。

仓库最近推送
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-strategy":https://skillpi.com/zh/skills/deepskill-e937158cd1d3ab7af66717482836b8864174aa405d24d599044f8c81762d3805。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

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

安装实测待补充

为 PHP 8.4 生成策略模式的代码。创建可互换的算法族,包含上下文类、策略接口与具体实现,并附带单元测试。

0 下载

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

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
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

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

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

场景价值85/100

亮点

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

亮点

  • description 清晰描述功能边界,覆盖策略模式生成的核心需求
结构规范75/100

待提升项

  • 文档结构优化 原报告严重程度:轻微

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

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

亮点

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

待提升项

  • 执行细节补充 原报告严重程度:轻微

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

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

亮点

  • 提供了完整的代码模板和结构说明,参数设计合理
证据可验 (前四项均值)80/100

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

正文静态检测

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

正文未命中当前规则。

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

权限与使用前检查

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

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

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

安全评级与访问范围

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

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