Conditions | 9 |
Total Lines | 60 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | package com.hltech.vaunt.validator.schema; |
||
21 | public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
||
22 | List<String> errors = new ArrayList<>(); |
||
23 | |||
24 | if (!isValid(consumerSchema.get$ref(), providerSchema.get$ref())) { |
||
25 | errors.add(String.format(ERROR_FORMAT, |
||
26 | consumerSchema.getId(), |
||
27 | "$ref", |
||
28 | consumerSchema.get$ref(), |
||
29 | providerSchema.get$ref())); |
||
30 | } |
||
31 | |||
32 | if (!isValid(consumerSchema.get$schema(), providerSchema.get$schema())) { |
||
33 | errors.add(String.format(ERROR_FORMAT, |
||
34 | consumerSchema.getId(), |
||
35 | "$schema", |
||
36 | consumerSchema.get$schema(), |
||
37 | providerSchema.get$schema())); |
||
38 | } |
||
39 | |||
40 | if (!isArrayValid(consumerSchema.getDisallow(), providerSchema.getDisallow(), Object::equals)) { |
||
41 | errors.add(String.format(ERROR_FORMAT, |
||
42 | consumerSchema.getId(), |
||
43 | "disallow", |
||
44 | jsonArrayToString(consumerSchema.getDisallow()), |
||
45 | jsonArrayToString(providerSchema.getDisallow()))); |
||
46 | } |
||
47 | |||
48 | if (!isArrayValid(consumerSchema.getExtends(), providerSchema.getExtends(), Object::equals)) { |
||
49 | errors.add(String.format(ERROR_FORMAT, |
||
50 | consumerSchema.getId(), |
||
51 | "extends", |
||
52 | jsonArrayToString(consumerSchema.getExtends()), |
||
53 | jsonArrayToString(providerSchema.getExtends()))); |
||
54 | } |
||
55 | |||
56 | if (isRequired(consumerSchema) && !isRequired(providerSchema)) { |
||
57 | errors.add(String.format(ERROR_FORMAT, |
||
58 | consumerSchema.getId(), |
||
59 | "required", |
||
60 | consumerSchema.getRequired(), |
||
61 | providerSchema.getRequired())); |
||
62 | } |
||
63 | |||
64 | if (!isValid(consumerSchema.getReadonly(), providerSchema.getReadonly())) { |
||
65 | errors.add(String.format(ERROR_FORMAT, |
||
66 | consumerSchema.getId(), |
||
67 | "readonly", |
||
68 | consumerSchema.getReadonly(), |
||
69 | providerSchema.getReadonly())); |
||
70 | } |
||
71 | |||
72 | if (!isValid(consumerSchema.getDescription(), providerSchema.getDescription())) { |
||
73 | errors.add(String.format(ERROR_FORMAT, |
||
74 | consumerSchema.getId(), |
||
75 | "description", |
||
76 | consumerSchema.getDescription(), |
||
77 | providerSchema.getDescription())); |
||
78 | } |
||
79 | |||
80 | return errors; |
||
81 | } |
||
148 |