forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexCondition.ql
More file actions
31 lines (27 loc) · 782 Bytes
/
ComplexCondition.ql
File metadata and controls
31 lines (27 loc) · 782 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
30
31
/**
* @name Complex condition
* @description Very complex conditions are difficult to read and may include defects.
* @kind problem
* @problem.severity recommendation
* @precision low
* @id java/complex-condition
* @tags testability
* readability
*/
import java
predicate nontrivialLogicalOperator(BinaryExpr e) {
e instanceof LogicExpr and
(
not e.getParent().(Expr).getKind() = e.getKind() or
e.isParenthesized()
)
}
Expr getSimpleParent(Expr e) {
result = e.getParent() and
not result instanceof MethodAccess
}
from Expr e
where
not e.getParent() instanceof Expr and
strictcount(BinaryExpr op | getSimpleParent*(op) = e and nontrivialLogicalOperator(op)) > 5
select e, "Complex condition: too many logical operations in this expression."