88import org .apache .commons .lang3 .StringUtils ;
99import org .jetbrains .annotations .NotNull ;
1010import org .jetbrains .annotations .Nullable ;
11+
1112import java .util .ArrayList ;
1213import java .util .HashMap ;
1314import java .util .List ;
1415import java .util .Map ;
1516
1617public class ComposerPackageModelImpl implements ComposerPackageModel {
17- private JsonObject sourceComposerJson ;
18+ private final JsonObject sourceComposerJson ;
1819
1920 public static final String NAME = "name" ;
2021 public static final String TYPE = "type" ;
@@ -67,12 +68,12 @@ public String[] getAutoloadFiles() {
6768 JsonArray jsonArray = getPropertyValueOfType (FILES , JsonArray .class );
6869 if (jsonArray != null ) {
6970 List <String > files = new ArrayList <>();
70- for (JsonValue value : jsonArray .getValueList ()) {
71+ for (JsonValue value : jsonArray .getValueList ()) {
7172 if (value instanceof JsonStringLiteral ) {
7273 files .add (StringUtils .strip (value .getText (), "\" " ));
7374 }
7475 }
75- return files .size () > 0 ? files .toArray (new String [files .size ()]) : null ;
76+ return ! files .isEmpty () ? files .toArray (new String [files .size ()]) : null ;
7677 }
7778 }
7879
@@ -86,30 +87,31 @@ public Map<String, String> getAutoloadPsr4() {
8687 if (autoloadObject != null ) {
8788 JsonObject jsonObject = getPropertyValueOfType (PSR4 , JsonObject .class );
8889 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 ()) {
9192 JsonValue value = property .getValue ();
9293
93- if (value != null && value instanceof JsonStringLiteral ) {
94+ if (value instanceof JsonStringLiteral ) {
9495 map .put (property .getName (), StringUtils .strip (value .getText (), "\" " ));
9596 }
9697 }
9798
98- return map .size () > 0 ? map : null ;
99+ return ! map .isEmpty () ? map : null ;
99100 }
100101 }
101102
102103 return null ;
103104 }
104105
105106 @ 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 ) {
107109 JsonProperty property = sourceComposerJson .findProperty (propertyName );
108110 if (property == null ) {
109111 return null ;
110112 }
111113 JsonValue value = property .getValue ();
112- if (value != null && aClass .isInstance (value )) {
114+ if (aClass .isInstance (value )) {
113115 return aClass .cast (value );
114116 }
115117
@@ -118,7 +120,10 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName, @NotN
118120
119121 @ Nullable
120122 private String getStringPropertyValue (String propertyName ) {
121- JsonStringLiteral stringLiteral = getPropertyValueOfType (propertyName , JsonStringLiteral .class );
123+ JsonStringLiteral stringLiteral = getPropertyValueOfType (
124+ propertyName ,
125+ JsonStringLiteral .class
126+ );
122127
123128 if (stringLiteral != null ) {
124129 return StringUtils .strip (stringLiteral .getText (), "\" " );
0 commit comments