create-null-object

Generate a Null Object pattern for PHP 8.4, creating safe default implementations to eliminate null checks and including 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-null-object" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-dacd9bf8c5bba4c3789a87e7503a4a7d0f25310cb5bffc715e8ee64276edc2a3. 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 Null Object pattern for PHP 8.4, creating safe default implementations to eliminate null checks and including unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Null Object pattern for PHP 8.4. Creates safe default implementations eliminating null checks. Includes unit tests.
Audience
| Scenario | Example | |----------|---------| | Optional dependencies | Logger, Cache, Notifier | | Missing entities | Customer, User, Product | | Feature toggles | Disabled feature returns null object | | Default implementations | No-op defaults |
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
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

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

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

Highlights

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

Highlights

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

Highlights

  • 提供了完整的生成流程和模板参考
  • 包含接口、空对象、真实实现的标准模板
  • neutral return values 表格清晰,usage example 展示了实际应用场景
Evidence Verifiability (mean of the first four)88/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.