savinmikhail/annotate_throws_rector
Composer 安装命令:
composer require --dev savinmikhail/annotate_throws_rector
包简介
Rector rule to add missing @throws tags for direct throws and inter-class propagation
关键字:
README 文档
README
Rector extension that adds missing @throws tags for:
- direct
throwexpressions in class methods - propagation through same-class calls like
$this->foo(),self::foo(),static::foo() - propagation through inter-class calls when the callee already has
@throws
Current MVP scope:
- class methods only
- inter-class propagation relies on existing callee docblocks
- repeated Rector runs can gradually converge the call graph across files
- caught exceptions inside
try/catchare not propagated - unchecked/wide exceptions are skipped by default
- existing
@throwstags are preserved and deduplicated - no removal of stale
@throwstags yet
Install
composer require --dev savinmikhail/annotate_throws_rector
Configure
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use SavinMikhail\AnnotateThrowsRector\AnnotateThrowsRector; return RectorConfig::configure() ->phpstanConfig(__DIR__ . '/phpstan.neon') ->withRules([ AnnotateThrowsRector::class, ]);
If you want to include unchecked exceptions too:
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use SavinMikhail\AnnotateThrowsRector\AnnotateThrowsRector; return RectorConfig::configure() ->phpstanConfig(__DIR__ . '/phpstan.neon') ->withConfiguredRule(AnnotateThrowsRector::class, [ AnnotateThrowsRector::INCLUDE_UNCHECKED => true, AnnotateThrowsRector::EXCLUDED_EXCEPTION_CLASSES => [ \Throwable::class, \Exception::class, \Error::class, \RuntimeException::class, \LogicException::class, ], ]);
When phpstanConfig() is provided, the rule reuses PHPStan checked/unchecked exception policy. The local EXCLUDED_EXCEPTION_CLASSES list is applied on top.
Example
final class InterviewRunner { public function process(): void { $this->normalize(); } public function normalize(): void { throw new \JsonException('Boom'); } }
becomes
final class InterviewRunner { /** * @throws \JsonException */ public function process(): void { $this->normalize(); } /** * @throws \JsonException */ public function normalize(): void { throw new \JsonException('Boom'); } }
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-20