Skip to content
This repository has been archived by the owner on Aug 8, 2018. It is now read-only.

squid:S2325 - private methods that don't access instance data should be static #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String flatten(String model, String models) {
return getFlattened(deserialize(model), deserialize(models));
}

private void buildSchemaReferenceMap(JsonNode model, JsonNode models, Map<String, String> modelMap) {
private static void buildSchemaReferenceMap(JsonNode model, JsonNode models, Map<String, String> modelMap) {
Map<JsonNode, JsonNode> refs = new HashMap<>();
findReferences(model, refs);

Expand All @@ -67,7 +67,7 @@ private void buildSchemaReferenceMap(JsonNode model, JsonNode models, Map<String
}
}

private JsonNode getSchema(String schemaName, JsonNode models) {
private static JsonNode getSchema(String schemaName, JsonNode models) {
return models.findPath(schemaName);
}

Expand All @@ -91,7 +91,7 @@ private String getFlattened(JsonNode model, JsonNode models) {
return flattened;
}

private void validate(JsonNode rootNode) {
private static void validate(JsonNode rootNode) {
final JsonSchemaFactory factory;
try {
factory = JsonSchemaFactory.byDefault();
Expand Down Expand Up @@ -126,14 +126,14 @@ private void replaceRefs(JsonNode root, HashMap<String, String> schemaMap) {
/*
* Replace a reference node with an inline reference
*/
private void replaceRef(ObjectNode parent, String schemaName) {
private static void replaceRef(ObjectNode parent, String schemaName) {
parent.set("$ref", new TextNode("#/definitions/" + schemaName));
}

/*
* Find all reference node in the schema tree. Build a map of the reference node to its parent
*/
private void findReferences(JsonNode node, Map<JsonNode, JsonNode> refNodes) {
private static void findReferences(JsonNode node, Map<JsonNode, JsonNode> refNodes) {
JsonNode refNode = node.path("$ref");
if (!refNode.isMissingNode()) {
refNodes.put(refNode, node);
Expand Down Expand Up @@ -161,7 +161,7 @@ JsonNode deserialize(String schemaText) {
* Attempt to serialize an existing schema
* If this fails something is seriously wrong, because this schema has already been saved by the control plane
*/
private String serializeExisting(JsonNode root) {
private static String serializeExisting(JsonNode root) {
try {
return new ObjectMapper().writeValueAsString(root);
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected String buildResourcePath(String basePath, String resourcePath) {
return result;
}

private String trimSlashes(String path) {
private static String trimSlashes(String path) {
return StringUtils.removeEnd(StringUtils.removeStart(path, "/"), "/");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void updateApi(String apiId, Raml raml, JSONObject config) {
cleanupModels(api, this.models);
}

private String getApiName (Raml raml, String fileName) {
private static String getApiName (Raml raml, String fileName) {
String title = raml.getTitle();
return StringUtils.isNotBlank(title) ? title : fileName;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ private void createMethod(final RestApi api, final Resource resource, final Acti
createMethodResponses(api, method, action.getResponses(), update);
}

private void createIntegration(Resource resource, Method method, JSONObject config) {
private static void createIntegration(Resource resource, Method method, JSONObject config) {
if (config == null) {
return;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ private void createIntegration(Resource resource, Method method, JSONObject conf
}
}

private void createIntegrationResponses(Integration integration, JSONObject responses) {
private static void createIntegrationResponses(Integration integration, JSONObject responses) {
if (responses == null) {
return;
}
Expand All @@ -339,7 +339,7 @@ private void createIntegrationResponses(Integration integration, JSONObject resp
}
}

private List<String> jsonObjectToListString (JSONArray json) {
private static List<String> jsonObjectToListString (JSONArray json) {
if (json == null) {
return null;
}
Expand All @@ -355,7 +355,7 @@ private List<String> jsonObjectToListString (JSONArray json) {
return list;
}

private Map<String, String> jsonObjectToHashMapString (JSONObject json) {
private static Map<String, String> jsonObjectToHashMapString (JSONObject json) {
if (json == null) {
return null;
}
Expand Down Expand Up @@ -473,7 +473,7 @@ private String createModel(RestApi api, String mime, MimeType mimeType) {
return null;
}

private String getExpression(String area, String part, String type, String name) {
private static String getExpression(String area, String part, String type, String name) {
return area + "." + part + "." + type + "." + name;
}

Expand All @@ -492,7 +492,7 @@ private void updateMethod(RestApi api, Method method, String type, String name,
method.updateMethod(createPatchDocument(createAddOperation("/requestParameters/" + expression, getStringValue(required))));
}

private String getAuthorizationTypeFromConfig(Resource resource, String method, JSONObject config) {
private static String getAuthorizationTypeFromConfig(Resource resource, String method, JSONObject config) {
if (config == null) {
return "NONE";
}
Expand All @@ -508,7 +508,7 @@ private String getAuthorizationTypeFromConfig(Resource resource, String method,
}
}

private String escapeOperationString(String value) {
private static String escapeOperationString(String value) {
return value.replaceAll("~", "~0").replaceAll("/", "~1");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void updateApi(String apiId, Swagger swagger) {
cleanupModels(api, this.processedModels);
}

private String getApiName(Swagger swagger, String fileName) {
private static String getApiName(Swagger swagger, String fileName) {
String title = swagger.getInfo().getTitle();
return StringUtils.isNotBlank(title) ? title : fileName;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ private void createMethods(final RestApi api, final Resource resource, Path path
});
}

private Map<String, Operation> getOperations(Path path) {
private static Map<String, Operation> getOperations(Path path) {
final Map<String, Operation> ops = new HashMap<>();

addOp(ops, "get", path.getGet());
Expand All @@ -196,7 +196,7 @@ private Map<String, Operation> getOperations(Path path) {
return ops;
}

private void addOp(Map<String, Operation> ops, String method, Operation operation) {
private static void addOp(Map<String, Operation> ops, String method, Operation operation) {
if (operation != null) {
ops.put(method, operation);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ private void createIntegrationResponses(Integration integration, Map<String, Has
});
}

private String getAuthorizationType(Operation op) {
private static String getAuthorizationType(Operation op) {
String authType = "NONE";
if (op.getVendorExtensions() != null) {
Object objectNode = op.getVendorExtensions().get(EXTENSION_AUTH);
Expand Down Expand Up @@ -363,7 +363,7 @@ String generateModelName(Response response) {
return generateModelName(response.getDescription());
}

private String generateModelName(String description) {
private static String generateModelName(String description) {
if (StringUtils.isBlank(description)) {
LOG.warn("No description found for model, will generate a unique model name");
return "model" + UUID.randomUUID().toString().substring(0, 8);
Expand All @@ -373,11 +373,11 @@ private String generateModelName(String description) {
return description.replaceAll(getModelNameSanitizeRegex(), "");
}

private String generateModelName(BodyParameter param) {
private static String generateModelName(BodyParameter param) {
return generateModelName(param.getDescription());
}

private String getModelNameSanitizeRegex() {
private static String getModelNameSanitizeRegex() {
return "[^A-Za-z0-9]";
}

Expand Down Expand Up @@ -454,7 +454,7 @@ private void cleanupResources(RestApi api, String basePath, Map<String, Path> pa
cleanupResources(api, buildResourceSet(paths.keySet(), basePath));
}

private Set<String> buildResourceSet(Set<String> paths, String basePath) {
private static Set<String> buildResourceSet(Set<String> paths, String basePath) {
if (StringUtils.isBlank(basePath)) {
basePath = "/";
}
Expand Down Expand Up @@ -562,12 +562,12 @@ private void createMethodParameters(RestApi api, Method method, List<Parameter>
});
}

private String createRequestParameterExpression(Parameter p) {
private static String createRequestParameterExpression(Parameter p) {
Optional<String> loc = getParameterLocation(p);
return "method.request." + loc.get() + "." + p.getName();
}

private Optional<String> getParameterLocation(Parameter p) {
private static Optional<String> getParameterLocation(Parameter p) {
switch (p.getIn()) {
case "path":
return Optional.of("path");
Expand Down