tombstone icon indicating copy to clipboard operation
tombstone copied to clipboard

Automation to Place Tombstones and Clean-Up Dead Code

Open scheb opened this issue 3 years ago • 2 comments

Idea

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.

In detail, it would need to provide 2 rectors:

1. Setting Tombstones

The first rector 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
}

2. Deleting Dead Code

The second rector 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.


If this idea would be useful to you, give it a +1

scheb avatar Aug 17 '20 11:08 scheb

Maybe you can also add a Rector rule to remove tombstones, for example after deleting dead code we want to remove all tombstones (for performance reasons maybe) and uninstall scheb/tombstone.

jawira avatar Sep 11 '22 09:09 jawira

@jawira You could easily do that with a regex ;)

scheb avatar Sep 13 '22 07:09 scheb