Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate code: How to find and remove with tools

I am managing a group of three interns working on a php project. They seem to be not good at refactoring and are using duplicate code in multiple places. I am looking for a tool which I can use to find this duplicate code so I can show them.

This would make my job easier, and the project more elegant and less prone to errors. Any leads?

like image 362
Abhishek Avatar asked Aug 02 '11 07:08

Abhishek


People also ask

How do I find duplication codes?

Duplicate code can be hard to find, especially in a large project. But PMD's Copy/Paste Detector (CPD) can find it for you! CPD works with Java, JSP, C/C++, C#, Go, Kotlin, Ruby, Swift and many more languages. It can be used via command-line, or via an Ant task.

How do I refactor a repeated code?

If the duplicate code is inside a constructor, use Pull Up Constructor Body. If the duplicate code is similar but not completely identical, use Form Template Method. If two methods do the same thing but use different algorithms, select the best algorithm and apply Substitute Algorithm.


1 Answers

PMD is a good tool to find code duplication. Here is a link to the site.

like image 121
Anantha Sharma Avatar answered Dec 03 '22 00:12

Anantha Sharma