Skip to content

Conversation

@zhoupeng-zh
Copy link
Contributor

reset方法接收paths参数允许array和string类型,在reset方法中调用的resetMigrations方法的接收参数paths只允许array类型,在reset方法中未对paths的数据类型进行处理。
调用reset方法时,若paths参数为string类型,会报错“Hyperf\Database\Migrations\Migrator::resetMigrations(): Argument #2 ($paths) must be of type array, string given”,因此使用Arr::wrap()方法对paths参数进行处理,确保传递的参数为array类型。

@huangdijia
Copy link
Member

代码审查评论

概述

此PR修复了Migrator::reset()方法中的类型不匹配错误,解决方案使用Arr::wrap()确保参数始终为数组类型。

分析结果

✅ 问题识别正确

  • reset()接受array|string类型,但resetMigrations()只接受array类型
  • 错误信息清楚地显示了类型不匹配问题

✅ 解决方案质量良好

  • 使用Arr::wrap()是规范化混合类型为数组的合适解决方案
  • 修复最小化且遵循Laravel/Hyperf约定
  • 未引入破坏性更改

✅ 代码风格良好

  • 遵循现有代码格式
  • 使用已导入的Arr

建议

  1. 验证测试覆盖率是否包含字符串输入情况
  2. 考虑为字符串输入添加测试用例(如果尚未覆盖)

安全与性能

  • 无安全影响
  • Arr::wrap()开销可忽略

最终评估

✅ 推荐通过 - 这是一个清晰、专注的错误修复,解决了合理的类型不匹配问题,遵循框架约定并保持向后兼容性。

@limingxinleo limingxinleo changed the base branch from 3.1 to master July 15, 2025 13:30
@limingxinleo limingxinleo changed the title Fixed bug that the type of parameter is not matching when string type Fixed bug that Hyperf\Database\Migrations\Migrator::reset() cannot support string paths. Jul 15, 2025
@limingxinleo limingxinleo merged commit 42916f2 into hyperf:master Jul 15, 2025
70 of 71 checks passed
@zhoupeng-zh zhoupeng-zh deleted the dev branch July 15, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants