Rector: Rectors for tombstones and code cleanup

Created on 14 Aug 2020  Â·  6Comments  Â·  Source: rectorphp/rector

Feature Request

Hello Tomas!

I created this Tombstones for PHP library and finally managed to create a stable release. I'd like to provide some automation to

1) add tombstones to a codebase
2) remove dead code from the codebase based on the results from the tombstone library

Since Rector is the standard library for PHP code migrations now, I thought it would be a good thing to use the Rector platform, rather than building my own little code migrations tool. We've actually been talking about this library a while ago on Twitter.

Would that be something you'd be interested in to include in Rector or should I rather provide the rectors as a 3rd party package? What do you think?

All 6 comments

Hi,

thanks for suggestion. I'd need more information

  • Is that AST based?
  • Does it remove code the same way Rector does (run vendor/bin/rector → code is changed :heavy_check_mark: )
  • How would practital minimal usage look like?

Yes, it it AST-based. The rectors would be adding/removing code.

In detail, the feature would require 2 rectors:

Rector 1 would add tombstone() function calls to each public method. There could be potentially additional filtering options, which public method to target.

public function foo() {
    // ... Some code here
}

Result after rector was applied:

public function foo() {
    tombstone();
    // ... Some code here
}

Rector 2 would take a result from the tombstone library (transfer format TBD), providing the information which methods are detected as "dead code". The rector would remove these dead methods from the code.

Now that I've thought a little bit about it, I believe it might make more sense to provide these rectors as a 3rd party package. It is quite a "special interest" use-case.

I see. So it's something like this https://tomasvotruba.com/blog/2019/11/11/from-0-doc-types-to-full-type-declaration-with-dynamic-analysis/, just not for types, but for dead code detection?

If so, I like it! Could you send PR with 1st simplest rule and test case? That will give me deeper practical context.

I see. So it's something like this https://tomasvotruba.com/blog/2019/11/11/from-0-doc-types-to-full-type-declaration-with-dynamic-analysis/, just not for types, but for dead code detection?

Yep, exactly. The approach is the same, the application is different.

Will send you a PR as soon as I find time looking into it.

Thank you

Closing as idea accepted :+1: and to keep issue tracker priorities focused.

Was this page helpful?
0 / 5 - 0 ratings