Search for code duplicates in WebStorm/PhpStorm

We’re glad to announce a new code analysis feature that is available in the most recent PhpStorm EAP— Locate Duplicates. This feature lets you quickly find duplicate code fragments and then fix them, therefore reducing the size of your code and making it easier to understand and maintain.

The feature is invoked via Code | Locate Duplicates menu that brings the Code Duplication Analysis Settings dialog where you can adjust the search options.

PhpStorm can detect duplicates in PHP, JavaScript and other code. Variables, functions and literals can be anonymized.

Do not show duplicates simpler than option can be used to exclude duplicates of insignificant size. Anonymize uncommon subexpressions simpler than option is used to anonymize not only single entries like variables or literals, but also short expressions. Default values for these settings are good to begin with but you can of course experiment and find settings that best match your code.

Results of this search are shown in a diff view with code fragments so that you can inspect the results:

Last, but not least fact is that PhpStorm also detects duplicates in CSS code, so you can easily spot similar declarations, and this surely helps find a way through large CSS files. You can adjusted the criteria for declaring the CSS fragments as duplicates, too:

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

This entry was posted in Cool Feature, PhpStorm, WebStorm and tagged , , , , . Bookmark the permalink.

7 Responses to Search for code duplicates in WebStorm/PhpStorm

  1. EugeneOZ says:

    And I’ve already did one refactoring after this inspection :) Thank you!

  2. Bryan Green says:

    Where is ECMAScript used over JavaScript?

  3. ragtek says:

    What’s this for a value in “Do not show dupl. simpler then x” ?
    Wouldn’t it be easier to say “do not whos dupl. < 3 lines" ?

    • Brendan Wood says:

      This is just a guess, but it may be using a tokens instead of lines when matching, which may be more beneficial than matching lines.

  4. Sam says:

    Wow. Thanks for it.

  5. ck3g says:

    How are you do that? In my case Code | Locate Duplicates always disabled. I’ve try to open different files (php, js, html). Menu item still disabled

Comments are closed.