Passed
Push — master ( 886a8d...e81f81 )
by Filip
02:36
created

validate(JsonSchema,JsonSchema)   D

Complexity

Conditions 13

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 14
dl 0
loc 27
rs 4.2
c 1
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like com.hltech.vaunt.validator.VauntSchemaValidator.validate(JsonSchema,JsonSchema) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package com.hltech.vaunt.validator;
2
3
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
4
import com.google.common.collect.Lists;
5
6
import java.util.ArrayList;
7
import java.util.List;
8
9
public class VauntSchemaValidator {
10
11
    public static List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) {
12
13
        if (consumerSchema.isBooleanSchema() && providerSchema.isBooleanSchema()) {
14
            return new ArrayList<>();
15
        }
16
17
        if (consumerSchema.isIntegerSchema() && providerSchema.isIntegerSchema()) {
18
            return new ArrayList<>();
19
        }
20
21
        if (consumerSchema.isNumberSchema() && providerSchema.isNumberSchema()) {
22
            return new ArrayList<>();
23
        }
24
25
        if (consumerSchema.isStringSchema() && providerSchema.isStringSchema()) {
26
            return StringSchemaValidator.validate(consumerSchema.asStringSchema(), providerSchema.asStringSchema());
27
        }
28
29
        if (consumerSchema.isArraySchema() && providerSchema.isArraySchema()) {
30
            return new ArrayList<>();
31
        }
32
33
        if (consumerSchema.isObjectSchema() && providerSchema.isObjectSchema()) {
34
            return ObjectSchemaValidator.validate(consumerSchema.asObjectSchema(), providerSchema.asObjectSchema());
35
        }
36
37
        return Lists.newArrayList("error");
38
    }
39
}
40