create-null-object

为 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-null-object":https://skillpi.com/zh/skills/deepskill-dacd9bf8c5bba4c3789a87e7503a4a7d0f25310cb5bffc715e8ee64276edc2a3。安装前核对上游来源和版本: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-null-object
description: Generates Null Object pattern for PHP 8.4. Creates safe default implementations eliminating null checks. Includes unit tests.

Null Object Pattern Generator

Creates Null Object pattern infrastructure for eliminating null checks.

When to Use

Scenario Example
Optional dependencies Logger, Cache, Notifier
Missing entities Customer, User, Product
Feature toggles Disabled feature returns null object
Default implementations No-op defaults

Component Characteristics

Interface

  • Defines expected behavior
  • Shared by real and null implementations
  • Enables polymorphic usage

Null Object

  • Implements interface with no-op behavior
  • Returns neutral values
  • Never throws on calls

Benefits

  • Eliminates null checks
  • Follows Liskov Substitution
  • Simplifies client code

Generation Process

Step 1: Generate Interface

Path: src/Domain/{BoundedContext}/

  1. {Name}Interface.php — Interface with isNull() method

Step 2: Generate Null Object

Path: src/Domain/{BoundedContext}/

  1. Null{Name}.php — Null implementation returning neutral values

Step 3: Generate Real Implementation

Path: src/Domain/{BoundedContext}/

  1. {Name}.php — Real implementation with business logic

Step 4: Generate Tests

  1. Null{Name}Test.php — Null object behavior tests

File Placement

Component Path
Interface src/Domain/{BoundedContext}/
Null Object src/Domain/{BoundedContext}/
Real Implementation src/Domain/{BoundedContext}/
Unit Tests tests/Unit/Domain/{BoundedContext}/

Naming Conventions

Component Pattern Example
Interface {Name}Interface CustomerInterface
Real Implementation {Name} Customer
Null Object Null{Name} NullCustomer
Test {ClassName}Test NullCustomerTest

Neutral Return Values

Type Neutral Value
string '' (empty string)
int 0
float 0.0
bool false
array []
void No return
Object Empty/default instance
Collection Empty collection

Quick Template Reference

Interface

interface {Name}Interface
{
    public function {method1}(): {returnType1};
    public function {method2}({params}): {returnType2};
    public function isNull(): bool;
}

Null Object

final readonly class Null{Name} implements {Name}Interface
{
    public function {method1}(): {returnType1}
    {
        return {neutralValue1};
    }

    public function isNull(): bool
    {
        return true;
    }
}

Real Implementation

final readonly class {Name} implements {Name}Interface
{
    public function __construct({properties}) {}

    public function {method1}(): {returnType1}
    {
        return {realImplementation};
    }

    public function isNull(): bool
    {
        return false;
    }
}

Usage Example

Repository Returning Null Object

final readonly class DoctrineCustomerRepository implements CustomerRepositoryInterface
{
    public function findById(CustomerId $id): CustomerInterface
    {
        $row = $this->connection->fetchAssociative(
            'SELECT * FROM customers WHERE id = :id',
            ['id' => $id->toString()]
        );

        if ($row === false) {
            return new NullCustomer();
        }

        return $this->hydrate($row);
    }
}

Client Code Without Null Checks

final readonly class CreateOrderUseCase
{
    public function execute(CreateOrderCommand $command): Order
    {
        $customer = $this->customers->findById($command->customerId);

        // No null check needed - NullCustomer returns 0.0
        $discount = $customer->getDiscount();

        $order = Order::create(
            customerId: $customer->id(),
            items: $command->items,
            discount: $discount
        );

        return $order;
    }
}

Anti-patterns to Avoid

Anti-pattern Problem Solution
Throwing in Null Unexpected exceptions Return neutral values
No isNull() Can't detect null object Add isNull method
Different Interface LSP violation Same interface as real
Side Effects Unexpected behavior Pure no-op methods
Complex Logic Not a null object Keep simple and neutral

References

For complete PHP templates and examples, see:

  • references/templates.md — Interface, NullObject, Real Implementation, NullLogger, NullCache templates
  • references/examples.md — NullCustomer, NullNotifier, Repository integration examples and tests

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

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

场景价值78/100

亮点

  • 提供完整的 Null Object 模式生成方案,适用于 PHP 8.4 开发场景
  • 能有效消除空值检查,提升代码健壮性和可维护性
  • 包含接口、空对象、真实实现和测试的完整生成流程
触发精准92/100

亮点

  • description 明确描述了生成 Null Object 模式的核心功能
  • 包含 PHP 8.4 版本信息、安全默认实现、消除空值检查等关键信息
  • 触发词精准完整,边界清晰
结构规范95/100

亮点

  • 文档结构清晰,包含完整的生成流程和模板参考
  • 有详细的步骤划分、端到端示例和避坑指南
  • frontmatter 完整,单文件未超过 500 行
执行可靠88/100

亮点

  • 提供了完整的生成流程和模板参考
  • 包含接口、空对象、真实实现的标准模板
  • neutral return values 表格清晰,usage example 展示了实际应用场景
证据可验 (前四项均值)88/100

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

正文静态检测

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

正文未命中当前规则。

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

权限与使用前检查

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

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

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

安全评级与访问范围

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

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