cyril-verloop/iterator

迭代器实用工具。

3.1.1 2022-04-06 09:51 UTC

This package is auto-updated.

Last update: 2024-09-13 08:51:03 UTC


README

一个简单的PHP迭代器抽象类,需要PHP 8.0以上。

License Type coverage Minimum PHP version

安装

作为Composer依赖项

在您的项目目录中运行

user@host project$ composer require "cyril-verloop/iterator"

用于开发目的

user@host ~$ cd [PATH_WHERE_TO_PUT_THE_PROJECT] # E.g. ~/projects/
user@host projects$ git clone https://github.com/cyrilverloop/iterator.git
user@host projects$ cd iterator
user@host iterator$ composer install -o
user@host datatables$ phive install --trust-gpg-keys 4AA394086372C20A,12CE0F1D262429A5,31C7E470E2138192,8AC0BAA79732DD42,C5095986493B4AA0

使用方法

您需要扩展抽象类,并且可以添加参数和返回类型。

<?php

declare(strict_types=1);

namespace MyNamespace;

use MyNamespace\Item;

class Items extends IntPosition
{
    public function add(Item $item): void
    {
        $this->list[count($this->list)] = $item;
    }

    public function current(): Item
    {
        return parent::current();
    }
}

然后,您可以在foreach循环中使用它

$items->add($item1);
$items->add($item2);

foreach($items as $item) {
    // Do something.
}

持续集成

测试

要运行测试

user@host iterator$ ./tools/phpunit -c ./ci/phpunit.xml

生成的输出将在./ci/phpunit/中。查看./ci/phpunit/html/index.html以获取代码覆盖率,以及查看./ci/phpunit/testdox.html以获取通过/失败测试的详细列表。

要运行变异测试,您必须先运行PHPUnit,然后

user@host doctrine-entities$ ./tools/infection -c./ci/infection.json

生成的输出将在./ci/infection/中。

静态分析

要进行静态分析

user@host iterator$ ./tools/psalm -c ./ci/psalm.xml [--report=./psalm/psalm.txt --output-format=text]

如果要将输出保存在文件中而不是屏幕上,请使用"--report=./psalm/psalm.txt --output-format=text"。

PHPDoc

要生成PHPDoc

user@host iterator$ ./tools/phpdocumentor --config ./ci/phpdoc.xml

生成的HTML文档将保存在./ci/phpdoc/中。

标准

本项目中所有PHP文件都遵循PSR-12。要缩进代码

user@host doctrine-entities$ ./tools/phpcbf --standard=PSR12 --extensions=php -p ./src/ ./tests/