views:

154

answers:

3

Are there any tools available that can scan multiple .php files and report back duplicated lines/chunks of code?

It doesn't have to be really smart but basically give me a starting point for manual scans to improve the codebase of some of my apps.

+1  A: 

"Duplicated code is the most pervasive and pungent smell in software." - Martin Fowler

See SD CloneDR, a tool for finding duplicated code across large systems. It finds both exact copies, and near-miss clones (cloned code that has been edited). The CloneDR is driven by language syntax, not text, so it will find clones if the text has been reformatted or variable names changed. Its actually really smart.

You can see a number of CloneDR reports for various languages at the site. For PHP, there's a CloneDR run on the popular web framework Joomla.

Ira Baxter
Ooooooo nice! Thanks for posting :-)
Jamie
+3  A: 

Depending on your specific needs you could use phpcpd or CPD. The former will probably be less accurate then the latter, but just test them and see which you like.

BTW They could also be used with CI (Continuous Integration) packages like Hudson or phpUnderControl.

wimvds
Could the people that are downvoting this please give a reason?
wimvds
Cheers phpcpd turned out to be exactly what I needed!
Toby
I suggest you check the quality of the phpcpd output, compared to the CloneDR. (I have a personal interest here, being the author of CloneDR, but the difference in what these two tools detect is astonishing, in favor of CloneDR IMHO. You can check this yourself, the the CloneDR answer and example of CloneDR applied to Joomla.
Ira Baxter
A: 

You could also roll your own with Reflection.

Inkspeak