ResponseStatusCodeRector crashes on first-class callable of a method named assert*
还没有人认领这个 Issue。
评估
调研方向
崩溃发生在 rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php:processMethodCall() 会将任何以 assert 开头的方法名路由到 processAssertMethodCall(),后者会对一等 callable 调用 getArgs()。首先阅读这两个方法,然后为一等 callable 添加提前返回。在 php -d zend.assertions=1 下,issue 中的复现文件被跳过且没有错误,并且有一个规则测试 fixture 覆盖该情况,即为完成。
由索引模型根据 Issue 内容生成。
描述
Bug Report
| Subject | Details |
|---|---|
| Rector version | Rector 2.8.3 (also 2.5.7) |
ResponseStatusCodeRector crashes when it visits a first-class callable whose method name starts with assert, for example $validator->assert(...). This is a common pattern with validation libraries such as PSL (Psl\Type\string()->assert(...)).
processMethodCall() sends every method call whose name starts with assert to processAssertMethodCall():
processAssertMethodCall() then calls getArgs() without a first-class callable check, and the php-parser assertion fails:
[ERROR] Could not process "src/Example.php" file, due to:
"System error: "assert(!$this->isPartialFunctionApplication())"
Stack trace:
#0 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php(50): assert()
#1 vendor/rector/rector/vendor/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php(155): PhpParser\Node\Expr\CallLike->getArgs()
#2 vendor/rector/rector/vendor/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php(105): Rector\Symfony\CodeQuality\Rector\BinaryOp\ResponseStatusCodeRector->processAssertMethodCall()
#3 vendor/rector/rector/vendor/rector/rector-symfony/rules/CodeQuality/Rector/BinaryOp/ResponseStatusCodeRector.php(94): Rector\Symfony\CodeQuality\Rector\BinaryOp\ResponseStatusCodeRector->processMethodCall()
In Rector 2.5.7 the message is assert(!$this->isFirstClassCallable()). The crash needs zend.assertions = 1, which is the PHP CLI default in development setups.
Minimal PHP Code Causing Issue
<?php
final class Validator
{
public function assert(mixed $value): string
{
return (string) $value;
}
}
$validator = new Validator();
$values = array_map($validator->assert(...), ['a', 'b']);
<?php
use Rector\Config\RectorConfig;
use Rector\Symfony\CodeQuality\Rector\BinaryOp\ResponseStatusCodeRector;
return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withRules([ResponseStatusCodeRector::class]);
Run: php -d zend.assertions=1 vendor/bin/rector process --dry-run
Expected Behaviour
Rector should skip the node. A first-class callable has no arguments to inspect. A guard at the start of processMethodCall() would fix it. isPartialFunctionApplication() also covers first-class callables in the php-parser version that Rector 2.8.3 bundles:
if ($methodCall->isPartialFunctionApplication()) {
return null;
}
- 主要语言
- PHP
- 星标
- 10.5k
- 派生
- 742
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rectorphp/rector 的其他 Issue
-
bug
难度 4/5 3-5 天 新手友好度 40/100
-
bug
难度 3/5 半天 新手友好度 55/100
-
[PHPUnit] AddInstanceofAssertForNullableInstanceRector enters an infinite loop on a test trait可能已有人在做 @samsonasik 今天认领。 未关闭bug
难度 4/5 1-2 天 新手友好度 25/100
-
bug
难度 3/5 1-2 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 52/100
相似的 Issue
-
Issue: ready for confirmation Reported on 2.4.9 Triage: Dev.Experience
难度 2/5 1-3 小时 新手友好度 70/100
magento/magento2#41773 · 1 条评论 ·
维护者通常 5 天内回复
-
[BUG] Add bounds validation for numberOfContestants in TeamsGroup::apiCreate()可能已有人在做 @RAJJADHAV10 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
omegaup/omegaup#10512 · 1 条评论 ·
维护者通常 5 天内回复
-
documentation good first issue
难度 2/5 1-3 小时 新手友好度 72/100
sorocharge/sorocharge-php#14 ·
-
难度 2/5 1-3 小时 新手友好度 66/100
filesender/filesender#2898 ·
维护者通常 1 天内回复
-
cleanup
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复