Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying repeated code within PHP project

I have a single PHP file within a legacy project that is at least a few thousand lines long. It is predominantly separated up into a number of different conditional blocks by a switch statement with about 10 cases. Within each case there is what appears to be a very similar - if not exact duplicate - block of code. What methods are available for me identifying these blocks of code as being either the same - or close to the same - so I can abstract that code out and begin to refactor the entire file? I know this is possible in very manual terms (separate each case statement in the code into individual files and Diff) but i'm interested in what tools i could be using to speed this process up.

Thanks.

like image 998
robjmills Avatar asked Sep 23 '10 13:09

robjmills


1 Answers

You can use phpcpd.

phpcpd is a Copy/Paste Detector (CPD) for PHP code. It scans a PHP project for duplicated code.

Further resources:

  • http://qualityassuranceinphpprojects.com/pages/tools.html
like image 102
Gordon Avatar answered Nov 01 '22 10:11

Gordon