sarah,
@sarah@phpc.social avatar

How do people locate and remove dead code from their projects in PHP these days?

afilina,
@afilina@phpc.social avatar

@sarah I'd start by logging which files are loaded in production. For old code that doesn't have a central entry point, it's quite common to have entire folders of unused scripts. After removing those files, I use the various dead code detectors mentioned in the other comments.

alessandrolai,
@alessandrolai@phpc.social avatar

@sarah if you're thinking about used code but maybe unused in prod (think: dead but tested feature), you could use the tombstone pattern: https://packagist.org/packages/scheb/tombstone

Crell,
@Crell@phpc.social avatar

@sarah PHPStorm highlights unused functions/methods in gray. It's... not perfect (some things I know are called dynamically in ways it wouldn't be able to catch, and neither would Rector) but is pretty good.

mwop,
@mwop@phpc.social avatar

@Crell @sarah intelephense and NLS in nvim both highlight unused properties, methods, and variables. And tools like psalm or phpstan will tell you, too.

heiglandreas,
@heiglandreas@phpc.social avatar

@sarah I built a plugin a while back for PHPStan that analyzes which code is used where. Finding unused functions should be possible then as well....

https://gitlab.com/stella-maris/callmap

jclermont,
@jclermont@phpc.social avatar

@sarah Rector with the dead code set is a great first pass.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • magazineikmin
  • InstantRegret
  • tacticalgear
  • ethstaker
  • rosin
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • Durango
  • thenastyranch
  • ngwrru68w68
  • tester
  • normalnudes
  • cisconetworking
  • Leos
  • love
  • cubers
  • osvaldo12
  • mdbf
  • anitta
  • provamag3
  • modclub
  • GTA5RPClips
  • megavids
  • JUstTest
  • All magazines