Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hirokinoue
Copy link
Contributor

  • 先日会話したリファクタリングのサンプル実装です。closeしていただいて構いません。
  • 要点は2つです。
    • NodeFinderを利用するようにした。
    • Function_とClassMethodを個別に分析する代わりにFunctionLikeを分析するようにした。
  • 処理がシンプルになるのと引き換えに、解析結果にクラス名が出力されないようになっており、クラス名を出力する仕様を維持するにはもう一工夫必要です。
  • FunctionLikeを分析対象とする場合、その具象に応じたテストケースを追加するのが望ましいと思います。(テストの追加は未実施です)

{
$foundFunctions = $this->getFunctions($stmts);
return array_map(function (FunctionLike $function) {
$functionIdentifier = $function->name->name ?? $function->getType() . '@' . $function->getStartLine();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数名がない場合に便宜的な名前をつけるようにしています。

Comment on lines 41 to 42
// $this->assertEquals('Clazz::bigFunction', $functions[0]->name);
$this->assertEquals('bigFunction', $functions[0]->name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

クラス名が出力されなくなったことをテストに反映しました。クラス名の出力を維持する場合、元に戻す必要があります。

@hirokinoue hirokinoue marked this pull request as ready for review March 16, 2025 15:49
@smeghead
Copy link
Owner

@hirokinoue
ClassMethodを探した場合にクラス名を取得するために、NodeFinderでの検索を諦めて、FindingVisitorを拡張することで ClassMethodのattributeに 'className' としてクラス名を保存するようにしてみました。

@smeghead smeghead self-requested a review March 17, 2025 13:42
@smeghead smeghead merged commit 3e89db7 into smeghead:main Mar 17, 2025
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.

2 participants