-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathAvoidRelativePathCheck.java
More file actions
54 lines (42 loc) · 1.86 KB
/
AvoidRelativePathCheck.java
File metadata and controls
54 lines (42 loc) · 1.86 KB
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
package fr.cnumr.php.checks;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.php.api.tree.SeparatedList;
import org.sonar.plugins.php.api.tree.Tree;
import org.sonar.plugins.php.api.tree.expression.ExpressionTree;
import org.sonar.plugins.php.api.tree.expression.FunctionCallTree;
import org.sonar.plugins.php.api.tree.expression.LiteralTree;
import org.sonar.plugins.php.api.tree.expression.ParenthesisedExpressionTree;
import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
import java.util.*;
@Rule(
key = "GRSP0008",
name = "Developpement",
description = AvoidRelativePathCheck.ERROR_MESSAGE,
priority = Priority.MINOR,
tags = {"bug"})
public class AvoidRelativePathCheck extends PHPSubscriptionCheck {
public static final String ERROR_MESSAGE = "Avoid using relative path, prefer using absolute path";
private static final Map<String, Collection<Integer>> linesWithIssuesByFile = new HashMap<>();
@Override
public List<Tree.Kind> nodesToVisit() {
return Collections.singletonList(Tree.Kind.FUNCTION_CALL);
}
@Override
public void visitNode(Tree tree) {
FunctionCallTree method = (FunctionCallTree) tree;
checkIssue(method);
}
public void checkIssue(FunctionCallTree functionCallTree) {
if(functionCallTree.callee().toString().equals("include") || functionCallTree.callee().toString().equals("require")){
ParenthesisedExpressionTree expressionTree = (ParenthesisedExpressionTree) functionCallTree.arguments().get(0);
if(!expressionTree.expression().toString().startsWith("\"/")){
repport(functionCallTree);
return;
}
}
}
private void repport(FunctionCallTree functionCallTree) {
context().newIssue(this, functionCallTree, ERROR_MESSAGE);
}
}