create-iterator

Generate an iterator pattern implementation for PHP 8.4. The purpose is to provide sequential access to aggregate elements without exposing the underlying representation, including code for an iterator interface and iterable collection, with accompanying 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-iterator" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-b709c1e857257ba6de3d3b181e6c52383923750702b87f023a77d178a260028b. 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 an iterator pattern implementation for PHP 8.4. The purpose is to provide sequential access to aggregate elements without exposing the underlying representation, including code for an iterator interface and iterable collection, with accompanying unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Iterator pattern for PHP 8.4. Creates sequential access to aggregate elements without exposing underlying representation, with iterator interface and iterable collections. Includes unit tests.
Audience
| Scenario | Example | |----------|---------| | Traverse collections | Order items, user lists, product catalog | | Multiple traversal algorithms | Forward, backward, filtered iteration | | Unified collection interface | Standardize iteration across different types | | Hide collection structure | Encapsulate internal representation |
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-iterator
description: Generates Iterator pattern for PHP 8.4. Creates sequential access to aggregate elements without exposing underlying representation, with iterator interface and iterable collections. Includes unit tests.

Iterator Pattern Generator

Creates Iterator pattern infrastructure for sequential access to collection elements.

When to Use

Scenario Example
Traverse collections Order items, user lists, product catalog
Multiple traversal algorithms Forward, backward, filtered iteration
Unified collection interface Standardize iteration across different types
Hide collection structure Encapsulate internal representation

Component Characteristics

Iterator Interface

  • Extends \Iterator or \IteratorAggregate
  • Provides current(), next(), key(), valid()
  • Enables foreach compatibility
  • Type-safe element access

Concrete Iterator

  • Implements traversal algorithm
  • Maintains iteration state
  • Provides filtering/transformation
  • Resets to beginning via rewind()

Iterable Collection

  • Implements \IteratorAggregate
  • Returns iterator via getIterator()
  • Encapsulates collection data
  • Supports type-safe operations

Generation Process

Step 1: Generate Iterator Interface (Optional)

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

  1. {Name}IteratorInterface.php — Custom iterator contract (extends \Iterator)

Step 2: Generate Concrete Iterator

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

  1. {Name}Iterator.php — Iterator implementation with traversal logic
  2. Filtered{Name}Iterator.php — Filtered variant (optional)

Step 3: Generate Iterable Collection

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

  1. {Name}Collection.php — Collection implementing \IteratorAggregate

Step 4: Generate Value Objects (Optional)

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

  1. {Element}.php — Collection element type

Step 5: Generate Tests

  1. {Name}IteratorTest.php — Iterator behavior tests
  2. {Name}CollectionTest.php — Collection tests

File Placement

Component Path
Iterator Interface src/Domain/{BoundedContext}/Iterator/
Concrete Iterator src/Domain/{BoundedContext}/Iterator/
Collection src/Domain/{BoundedContext}/Collection/
Value Objects src/Domain/{BoundedContext}/ValueObject/
Unit Tests tests/Unit/Domain/{BoundedContext}/

Naming Conventions

Component Pattern Example
Iterator Interface {Name}IteratorInterface OrderIteratorInterface
Concrete Iterator {Name}Iterator OrderIterator
Filtered Iterator Filtered{Name}Iterator FilteredUserIterator
Collection {Name}Collection OrderCollection
Test {ClassName}Test OrderIteratorTest

Quick Template Reference

Iterator (using \Iterator)

final class {Name}Iterator implements \Iterator
{
    private int $position = 0;

    public function __construct(
        private readonly array $items
    ) {}

    public function current(): {ElementType}
    {
        return $this->items[$this->position];
    }

    public function next(): void
    {
        ++$this->position;
    }

    public function key(): int
    {
        return $this->position;
    }

    public function valid(): bool
    {
        return isset($this->items[$this->position]);
    }

    public function rewind(): void
    {
        $this->position = 0;
    }
}

Iterable Collection (using \IteratorAggregate)

final readonly class {Name}Collection implements \IteratorAggregate, \Countable
{
    /**
     * @param array<{ElementType}> $items
     */
    public function __construct(
        private array $items = []
    ) {}

    public function getIterator(): \Traversable
    {
        return new {Name}Iterator($this->items);
    }

    public function count(): int
    {
        return count($this->items);
    }
}

Usage Example

// Create collection
$orders = new OrderCollection([
    new Order(id: '1', total: 100),
    new Order(id: '2', total: 200),
    new Order(id: '3', total: 50),
]);

// Iterate with foreach
foreach ($orders as $order) {
    echo $order->total();
}

// Filtered iteration
$filtered = new FilteredOrderIterator(
    orders: $orders,
    filter: fn(Order $o) => $o->total() > 100
);

foreach ($filtered as $order) {
    // Only orders with total > 100
}

Common Iterator Patterns

Domain Iterators
Collections OrderCollection, UserCollection, ProductCollection
Filtering ActiveUserIterator, PendingOrderIterator
Pagination PaginatedResultIterator, PageIterator
Tree Structures DepthFirstIterator, BreadthFirstIterator
Composite RecursiveIterator, FlatteningIterator

Anti-patterns to Avoid

Anti-pattern Problem Solution
Mutable iterator state leak External modification Use readonly collections
Breaking foreach contract Invalid implementation Implement all \Iterator methods
Expensive current() Performance issues Cache current element
Missing rewind() Can't iterate twice Implement proper rewind()
Violating LSP Inconsistent behavior Follow SPL iterator contracts

References

For complete PHP templates and examples, see:

  • references/templates.md — Iterator, IteratorAggregate, Filtered Iterator templates
  • references/examples.md — OrderCollection, UserIterator, Pagination 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

  • 提供 PHP 8.4 迭代器模式的完整生成方案,覆盖接口、实现、集合、测试等全流程
  • 适用于广泛的 PHP 开发场景,能显著提升开发效率和代码规范性
Trigger Precision90/100

Highlights

  • description 明确描述了核心功能(为 PHP 8.4 生成迭代器模式)
  • 包含关键触发词如 Iterator pattern、sequential access、unit tests,边界清晰
Structure and Standards95/100

Highlights

  • 文档结构完整,包含使用场景、组件特性、生成步骤、文件位置、命名规范、模板参考、示例、常见模式和反模式
  • 分步骤清晰,有端到端示例,frontmatter 完整,符合规范
Execution Reliability90/100

Highlights

  • 提供了完整的代码模板和使用示例,组件职责明确
  • 遵循 PHP SPL 标准,无明显执行漏洞,可靠性高
Evidence Verifiability (mean of the first four)90/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.