1

I just found out about the tool PHPMD and I notice that it's really useful, the thing is that I read the documentation about creating custom rules and stuff, but it just talks about using software metrics from PHPDepend.

I would like to know if it's possible to implement a specific rule to check for duplicated code?

I notice that I can also use the Abstract Syntax Tree of a specific node in my custom rule, but maybe that won't help me much right?

Because to check for duplicated code I need to compare several different function/method nodes, and the apply method is called once for each node?

How could I extend PHPMD to achieve deep code analysis like this? I wanna go far beyond software metrics..

Thank you!

TiagoM
  • 3,458
  • 4
  • 42
  • 83
  • 1
    [phpcpd](https://github.com/sebastianbergmann/phpcpd) is a better tool to search for duplicated code – Mark Baker Oct 23 '16 at 13:00
  • right I know that, but is it possible to achieve this using PHPMD? and how? because I am doing a master thesis and I am evaluating PHPMD and need to do some extensions to it , thank you ! I am trying to avoid other tools, especially because phpcpd it has only that purpose, I am looking for generic solutions for reverse engineering purposes , thank you ! – TiagoM Oct 23 '16 at 13:15
  • 1
    Well you're wanting to use PHPMD for something that it was never intended for; PHPMD is written specifically to report on software metrics; that's its purpose, and adding custom rules is all about software metric rules (not about unrelated functionality like copy/paste).... so there aren't really any guidelines for changing the intrinisc purpose of phpmd – Mark Baker Oct 23 '16 at 13:20
  • 1
    Personally, I might look at options for taking the outputs from the two different toolsets and merging them into a single output – Mark Baker Oct 23 '16 at 13:21
  • Thanks for your input @MarkBaker ! I get what you mean , make a proper answer about using the same information you gave, and I will be glad to accept it as answer ;) – TiagoM Oct 23 '16 at 13:25

0 Answers0