-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathInappropriateIntimacy.ql
64 lines (55 loc) · 1.97 KB
/
InappropriateIntimacy.ql
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @name Inappropriate intimacy
* @description Two otherwise unrelated classes that share too much information about each other are
* difficult to maintain, change and understand.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/coupled-types
* @tags maintainability
* modularity
*/
import csharp
predicate enclosingRefType(Variable v, RefType type) {
v.(Field).getDeclaringType() = type or
v.(LocalScopeVariable).getDeclaringType() = type
}
predicate remoteVarAccess(RefType source, RefType target, VariableAccess va) {
va.getEnclosingCallable().getDeclaringType() = source and
enclosingRefType(va.getTarget(), target) and
source != target
}
predicate remoteFunAccess(RefType source, RefType target, Call fc) {
fc.getEnclosingCallable().getDeclaringType() = source and
target = fc.getTarget().getDeclaringType()
}
predicate candidateTypePair(RefType source, RefType target) {
remoteVarAccess(source, target, _) or remoteFunAccess(source, target, _)
}
predicate variableDependencyCount(RefType source, RefType target, int res) {
candidateTypePair(source, target) and
res = count(VariableAccess va | remoteVarAccess(source, target, va))
}
predicate functionDependencyCount(RefType source, RefType target, int res) {
candidateTypePair(source, target) and
res = count(Call fc | remoteFunAccess(source, target, fc))
}
predicate dependencyCount(RefType source, RefType target, int res) {
exists(int varCount, int funCount |
variableDependencyCount(source, target, varCount) and
functionDependencyCount(source, target, funCount) and
res = varCount + funCount and
res > 15
)
}
from RefType a, RefType b, int ca, int cb
where
dependencyCount(a, b, ca) and
dependencyCount(b, a, cb) and
ca > 15 and
cb > 15 and
ca >= cb and
a != b
select a,
"Type " + a.getName() + " is too closely tied to $@ (" + ca.toString() +
" dependencies one way and " + cb.toString() + " the other).", b, b.getName()