Code Duplication Blocks in HTML,PHP and Drupal

456 views
Skip to first unread message

citr...@gmail.com

unread,
Feb 6, 2017, 12:36:25 AM2/6/17
to SonarQube
When we scanned our PHP web application We found of a lot of duplications in Code. While checking crosschecking SonarQube Duplication it is found the following:

  1. Similar code snippets with different id/class with quotes considered as duplicated Code 
  2. Drupal code blocks for Menu, Blocks within arrays considered as duplicated code. hook menu items are similar in variables but the difference is only with strings 
Can we remove this kind of reporting of duplication like we disable some rules or something like that ? We do not want to increase the number of duplication percentage by considering this kind of code ?

G. Ann Campbell

unread,
Feb 6, 2017, 3:10:32 PM2/6/17
to SonarQube, citr...@gmail.com
Hi,

First, please be aware that the standard courtesies (Hi, Thanks, ...) are appreciated in this group.

To answer your question, you have the ability to set duplications exclusions: Administration > Analysis Scope > Duplication Exclusions. The setting allows you to set a file path pattern describing the paths to the files that should be ignored by duplications detection.


Ann

GEO VL CItrus

unread,
Feb 9, 2017, 6:44:33 AM2/9/17
to G. Ann Campbell, SonarQube
Hi Ann,

Thanks for consideration
We found that from these we can ignore files. My problem is with code blocks
For example:

 In drupal hook_menu all contents are similar except the statements inside quotes

 $items['path/to/page1'] = array(
    'title' => 'My form',
    'page callback' => 'hook_page_function1',
    'access arguments' => array('access content'),
    'description' => 'My form',
    'type' => MENU_CALLBACK,
  );
 $items['path/to/page2'] = array(
    'title' => 'My form 2',
    'page callback' => 'hook_page_function2',
    'access arguments' => array('access content'),
    'description' => 'My form 2',
    'type' => MENU_CALLBACK,
  );


In HTML 

  <div id="firstdiv"><?php print $data; ?></div>
  <div id="seconddiv"><?php print $data; ?></div>

see the two sections in each code reported as duplicated in sonarqube
My Doubt is that is any way to remove these areas during scanning  from our drupal code  and html code not entire file 

Thanks 
Geo

G. Ann Campbell

unread,
Feb 9, 2017, 9:22:58 AM2/9/17
to GEO VL CItrus, SonarQube
Gah! Didn't "Reply All"...



---
G. Ann CAMPBELL | SonarSource
Product Manager

On Thu, Feb 9, 2017 at 8:26 AM, G. Ann Campbell <ann.ca...@sonarsource.com> wrote:
Hi Geo,

I'm afraid you're right.


Ann



---
G. Ann CAMPBELL | SonarSource
Product Manager

GEO VL CItrus

unread,
Feb 10, 2017, 6:16:29 AM2/10/17
to G. Ann Campbell, SonarQube
Hello Ann,

Is there any plan to include such Code Snippet pattern duplication exclusion way in SonarQube?
Or do we need to add such code in particular files and exclude the file from scanning ?
Because in almost all custom drupal modules module_hook functions keep exactly same pattern except strings and reported as duplicated 

Thanks 
Geo 

G. Ann Campbell

unread,
Feb 10, 2017, 7:22:07 AM2/10/17
to GEO VL CItrus, SonarQube
Hi Geo,

Sorry, there are currently no plans to expand exclusions.


Ann



---
G. Ann CAMPBELL | SonarSource
Product Manager

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/OpfCuBN9A1I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/CAO4URXtJsR%2B%2B3f_KjHXDAVW5trvHkwZ5F1Qi7HMmNFe3yd8R8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages