20
20
21
21
public class ComposerPackageModelImpl implements ComposerPackageModel {
22
22
private final JsonObject sourceComposerJson ;
23
+ private static final int VENDOR_AND_PACKAGE_PARTS_LENGTH = 2 ;
23
24
24
25
public static final String NAME = "name" ;
25
26
public static final String TYPE = "type" ;
@@ -28,7 +29,7 @@ public class ComposerPackageModelImpl implements ComposerPackageModel {
28
29
public static final String PSR4 = "psr4" ;
29
30
public static final String FILES = "file" ;
30
31
31
- public ComposerPackageModelImpl (@ NotNull JsonObject sourceComposerJson ) {
32
+ public ComposerPackageModelImpl (@ NotNull final JsonObject sourceComposerJson ) {
32
33
this .sourceComposerJson = sourceComposerJson ;
33
34
}
34
35
@@ -47,10 +48,10 @@ public String getType() {
47
48
@ Nullable
48
49
@ Override
49
50
public String getVendor () {
50
- String nameProperty = getStringPropertyValue (NAME );
51
+ final String nameProperty = getStringPropertyValue (NAME );
51
52
if (nameProperty != null ) {
52
- String [] vendorAndPackage = nameProperty .split ("/" );
53
- if (vendorAndPackage .length == 2 ) {
53
+ final String [] vendorAndPackage = nameProperty .split ("/" );
54
+ if (vendorAndPackage .length == VENDOR_AND_PACKAGE_PARTS_LENGTH ) {
54
55
return vendorAndPackage [0 ];
55
56
}
56
57
}
@@ -67,55 +68,56 @@ public String getVersion() {
67
68
@ Nullable
68
69
@ Override
69
70
public String [] getAutoloadFiles () {
70
- JsonObject autoloadObject = getPropertyValueOfType (AUTOLOAD , JsonObject .class );
71
+ final JsonObject autoloadObject = getPropertyValueOfType (AUTOLOAD , JsonObject .class );
71
72
if (autoloadObject != null ) {
72
- JsonArray jsonArray = getPropertyValueOfType (FILES , JsonArray .class );
73
- if (jsonArray != null ) {
74
- List <String > files = new ArrayList <>();
75
- for (JsonValue value : jsonArray .getValueList ()) {
76
- if (value instanceof JsonStringLiteral ) {
77
- files .add (StringUtils .strip (value .getText (), "\" " ));
78
- }
73
+ return new String [0 ];
74
+ }
75
+
76
+ final JsonArray jsonArray = getPropertyValueOfType (FILES , JsonArray .class );
77
+ if (jsonArray != null ) {
78
+ final List <String > files = new ArrayList <>();
79
+ for (final JsonValue value : jsonArray .getValueList ()) {
80
+ if (value instanceof JsonStringLiteral ) {
81
+ files .add (StringUtils .strip (value .getText (), "\" " ));
79
82
}
80
- return !files .isEmpty () ? files .toArray (new String [files .size ()]) : null ;
81
83
}
84
+ return files .isEmpty () ? new String [0 ] : files .toArray (new String [0 ]);
82
85
}
83
86
84
- return null ;
87
+ return new String [ 0 ] ;
85
88
}
86
89
87
90
@ Nullable
88
91
@ Override
89
92
public Map <String , String > getAutoloadPsr4 () {
90
- JsonObject autoloadObject = getPropertyValueOfType (AUTOLOAD , JsonObject .class );
91
- if (autoloadObject != null ) {
92
- JsonObject jsonObject = getPropertyValueOfType (PSR4 , JsonObject .class );
93
- if (jsonObject != null ) {
94
- Map <String , String > map = new HashMap <String , String >();
95
- for (JsonProperty property : jsonObject .getPropertyList ()) {
96
- JsonValue value = property .getValue ();
97
-
98
- if (value instanceof JsonStringLiteral ) {
99
- map .put (property .getName (), StringUtils .strip (value .getText (), "\" " ));
100
- }
101
- }
93
+ final JsonObject autoloadObject = getPropertyValueOfType (AUTOLOAD , JsonObject .class );
94
+ final Map <String , String > map = new HashMap <>();
95
+ if (autoloadObject == null ) {
96
+ return map ;
97
+ }
102
98
103
- return !map .isEmpty () ? map : null ;
99
+ final JsonObject jsonObject = getPropertyValueOfType (PSR4 , JsonObject .class );
100
+ if (jsonObject != null ) {
101
+ for (final JsonProperty property : jsonObject .getPropertyList ()) {
102
+ final JsonValue value = property .getValue ();
103
+ if (value instanceof JsonStringLiteral ) {
104
+ map .put (property .getName (), StringUtils .strip (value .getText (), "\" " ));
105
+ }
104
106
}
105
107
}
106
108
107
- return null ;
109
+ return map ;
108
110
}
109
111
110
112
@ Nullable
111
113
@ Override
112
- public <T extends JsonValue > T getPropertyValueOfType (String propertyName ,
113
- @ NotNull Class <T > thisClass ) {
114
- JsonProperty property = sourceComposerJson .findProperty (propertyName );
114
+ public <T extends JsonValue > T getPropertyValueOfType (final String propertyName ,
115
+ @ NotNull final Class <T > thisClass ) {
116
+ final JsonProperty property = sourceComposerJson .findProperty (propertyName );
115
117
if (property == null ) {
116
118
return null ;
117
119
}
118
- JsonValue value = property .getValue ();
120
+ final JsonValue value = property .getValue ();
119
121
if (thisClass .isInstance (value )) {
120
122
return thisClass .cast (value );
121
123
}
@@ -124,8 +126,8 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName,
124
126
}
125
127
126
128
@ Nullable
127
- private String getStringPropertyValue (String propertyName ) {
128
- JsonStringLiteral stringLiteral = getPropertyValueOfType (
129
+ private String getStringPropertyValue (final String propertyName ) {
130
+ final JsonStringLiteral stringLiteral = getPropertyValueOfType (
129
131
propertyName ,
130
132
JsonStringLiteral .class
131
133
);
0 commit comments