-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMostlyDuplicateMethod.ql
More file actions
29 lines (27 loc) · 1021 Bytes
/
MostlyDuplicateMethod.ql
File metadata and controls
29 lines (27 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @name Mostly duplicate method
* @description There is another method that shares a lot of the code with this method. Extract the code to a common superclass or delegate to improve sharing.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/similar-method
* @tags testability
* maintainability
* useless-code
* statistical
* non-attributable
*/
import csharp
import CodeDuplication
from Method m, int covered, int total, Method other, int percent
where
duplicateStatements(m, other, covered, total) and
covered != total and
m.getNumberOfLinesOfCode() > 5 and
covered * 100 / total = percent and
percent > 80 and
not duplicateMethod(m, other) and
not classLevelDuplication(m.getDeclaringType(), other.getDeclaringType()) and
not fileLevelDuplication(m.getFile(), other.getFile())
select m, percent + "% of the statements in " + m.getName() + " are duplicated in $@.",
other, other.getDeclaringType().getName() + "." + other.getName()