[Feature Request] Create generator for matrix values.

未关闭 适合新手
#497 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

先阅读 MatrixInterface 和 Matrix 的实现,然后检查 getBlockCount() 和 getBlockValue() 的使用方式及测试情况。添加一个生成器,用于产出值为 1 的块的行索引和列索引;完成标准是调用方可以像 issue 中所示那样使用 foreach 迭代,并且该行为有测试覆盖。

由索引模型根据 Issue 内容生成。

描述

When using MatrixInterface, you often write code like this:

$matrix = ...
$blockCount = $matrix->getBlockCount();
for ($rowIndex = 0; $rowIndex < $blockCount; ++$rowIndex) {
    for ($columnIndex = 0; $columnIndex < $blockCount; ++$columnIndex) {
        if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) {
            // ...
        }
    }
}

It would be nice to create a new function (a generator) that returns the row and column indices only for valid values:

interface MatrixInterface {

    /**
     * @return \Generator<array{0: int, 1: int}>
     */ 
    public function getIndexes(): \Generator;

}

And the implementation:

final readonly class Matrix implements MatrixInterface {

    #[\Override]
    public function getIndexes(): \Generator {
        $blockCount = $this->getBlockCount();
        for ($rowIndex = 0; $rowIndex < $blockCount; ++$rowIndex) {
            for ($columnIndex = 0; $columnIndex < $blockCount; ++$columnIndex) {
                if (1 === $this->getBlockValue($rowIndex, $columnIndex)) {
                   yield [$rowIndex, $columnIndex];
                }
            }
        }
    }
}

Then use as follow:

$matrix = ...
foreach ($matrix->getIndexes() as [$rowIndex, $columnIndex]) {
    // ...
}
主要语言
PHP
星标
4.8k
派生
766
平均合并
10 小时 51 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

endroid/qr-code 的其他 Issue

查看 endroid/qr-code 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。