Search code examples
rector

Can a rule get current file name?


To debug / reporting purpose, before a refactor, we need to print the current file name in a rule refactor method.

Here we do a LOT of highly specific filtering, so I need to dump filenames where filter passes BEFORE doing any changes, so rector reporting will not output nothing.

Can a rector rule access current parsed file name?


Solution

  • Found !

    in the rule we can use

    $this->file->getFilePath()
    

    Also, in the refactor method we can also see line of current node

    $node->getLine()