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.
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: