8
8
import org .apache .commons .lang3 .StringUtils ;
9
9
import org .jetbrains .annotations .NotNull ;
10
10
import org .jetbrains .annotations .Nullable ;
11
+
11
12
import java .util .ArrayList ;
12
13
import java .util .HashMap ;
13
14
import java .util .List ;
14
15
import java .util .Map ;
15
16
16
17
public class ComposerPackageModelImpl implements ComposerPackageModel {
17
- private JsonObject sourceComposerJson ;
18
+ private final JsonObject sourceComposerJson ;
18
19
19
20
public static final String NAME = "name" ;
20
21
public static final String TYPE = "type" ;
@@ -67,12 +68,12 @@ public String[] getAutoloadFiles() {
67
68
JsonArray jsonArray = getPropertyValueOfType (FILES , JsonArray .class );
68
69
if (jsonArray != null ) {
69
70
List <String > files = new ArrayList <>();
70
- for (JsonValue value : jsonArray .getValueList ()) {
71
+ for (JsonValue value : jsonArray .getValueList ()) {
71
72
if (value instanceof JsonStringLiteral ) {
72
73
files .add (StringUtils .strip (value .getText (), "\" " ));
73
74
}
74
75
}
75
- return files .size () > 0 ? files .toArray (new String [files .size ()]) : null ;
76
+ return ! files .isEmpty () ? files .toArray (new String [files .size ()]) : null ;
76
77
}
77
78
}
78
79
@@ -86,30 +87,31 @@ public Map<String, String> getAutoloadPsr4() {
86
87
if (autoloadObject != null ) {
87
88
JsonObject jsonObject = getPropertyValueOfType (PSR4 , JsonObject .class );
88
89
if (jsonObject != null ) {
89
- Map <String , String > map = new HashMap <String , String >();
90
- for (JsonProperty property : jsonObject .getPropertyList ()) {
90
+ Map <String , String > map = new HashMap <String , String >();
91
+ for (JsonProperty property : jsonObject .getPropertyList ()) {
91
92
JsonValue value = property .getValue ();
92
93
93
- if (value != null && value instanceof JsonStringLiteral ) {
94
+ if (value instanceof JsonStringLiteral ) {
94
95
map .put (property .getName (), StringUtils .strip (value .getText (), "\" " ));
95
96
}
96
97
}
97
98
98
- return map .size () > 0 ? map : null ;
99
+ return ! map .isEmpty () ? map : null ;
99
100
}
100
101
}
101
102
102
103
return null ;
103
104
}
104
105
105
106
@ Nullable
106
- public <T extends JsonValue > T getPropertyValueOfType (String propertyName , @ NotNull Class <T > aClass ) {
107
+ public <T extends JsonValue > T getPropertyValueOfType (String propertyName ,
108
+ @ NotNull Class <T > aClass ) {
107
109
JsonProperty property = sourceComposerJson .findProperty (propertyName );
108
110
if (property == null ) {
109
111
return null ;
110
112
}
111
113
JsonValue value = property .getValue ();
112
- if (value != null && aClass .isInstance (value )) {
114
+ if (aClass .isInstance (value )) {
113
115
return aClass .cast (value );
114
116
}
115
117
@@ -118,7 +120,10 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName, @NotN
118
120
119
121
@ Nullable
120
122
private String getStringPropertyValue (String propertyName ) {
121
- JsonStringLiteral stringLiteral = getPropertyValueOfType (propertyName , JsonStringLiteral .class );
123
+ JsonStringLiteral stringLiteral = getPropertyValueOfType (
124
+ propertyName ,
125
+ JsonStringLiteral .class
126
+ );
122
127
123
128
if (stringLiteral != null ) {
124
129
return StringUtils .strip (stringLiteral .getText (), "\" " );
0 commit comments