-
Notifications
You must be signed in to change notification settings - Fork 1
リファクタリングのサンプル実装 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
リファクタリングのサンプル実装 #1
Conversation
hirokinoue
commented
Mar 16, 2025
- 先日会話したリファクタリングのサンプル実装です。closeしていただいて構いません。
- 要点は2つです。
- NodeFinderを利用するようにした。
- Function_とClassMethodを個別に分析する代わりにFunctionLikeを分析するようにした。
- 処理がシンプルになるのと引き換えに、解析結果にクラス名が出力されないようになっており、クラス名を出力する仕様を維持するにはもう一工夫必要です。
- FunctionLikeを分析対象とする場合、その具象に応じたテストケースを追加するのが望ましいと思います。(テストの追加は未実施です)
src/Parse/VariableParser.php
Outdated
{ | ||
$foundFunctions = $this->getFunctions($stmts); | ||
return array_map(function (FunctionLike $function) { | ||
$functionIdentifier = $function->name->name ?? $function->getType() . '@' . $function->getStartLine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数名がない場合に便宜的な名前をつけるようにしています。
test/VariableParserTest.php
Outdated
// $this->assertEquals('Clazz::bigFunction', $functions[0]->name); | ||
$this->assertEquals('bigFunction', $functions[0]->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
クラス名が出力されなくなったことをテストに反映しました。クラス名の出力を維持する場合、元に戻す必要があります。
@hirokinoue |