Skip to content

Commit f3efc91

Browse files
fix pmd issues
1 parent a35aa9c commit f3efc91

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

src/com/magento/idea/magento2plugin/magento/packages/ComposerPackageModelImpl.java

+36-34
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
public class ComposerPackageModelImpl implements ComposerPackageModel {
2222
private final JsonObject sourceComposerJson;
23+
private static final int VENDOR_AND_PACKAGE_PARTS_LENGTH = 2;
2324

2425
public static final String NAME = "name";
2526
public static final String TYPE = "type";
@@ -28,7 +29,7 @@ public class ComposerPackageModelImpl implements ComposerPackageModel {
2829
public static final String PSR4 = "psr4";
2930
public static final String FILES = "file";
3031

31-
public ComposerPackageModelImpl(@NotNull JsonObject sourceComposerJson) {
32+
public ComposerPackageModelImpl(@NotNull final JsonObject sourceComposerJson) {
3233
this.sourceComposerJson = sourceComposerJson;
3334
}
3435

@@ -47,10 +48,10 @@ public String getType() {
4748
@Nullable
4849
@Override
4950
public String getVendor() {
50-
String nameProperty = getStringPropertyValue(NAME);
51+
final String nameProperty = getStringPropertyValue(NAME);
5152
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) {
5455
return vendorAndPackage[0];
5556
}
5657
}
@@ -67,55 +68,56 @@ public String getVersion() {
6768
@Nullable
6869
@Override
6970
public String[] getAutoloadFiles() {
70-
JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
71+
final JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
7172
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(), "\""));
7982
}
80-
return !files.isEmpty() ? files.toArray(new String[files.size()]) : null;
8183
}
84+
return files.isEmpty() ? new String[0] : files.toArray(new String[0]);
8285
}
8386

84-
return null;
87+
return new String[0];
8588
}
8689

8790
@Nullable
8891
@Override
8992
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+
}
10298

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+
}
104106
}
105107
}
106108

107-
return null;
109+
return map;
108110
}
109111

110112
@Nullable
111113
@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);
115117
if (property == null) {
116118
return null;
117119
}
118-
JsonValue value = property.getValue();
120+
final JsonValue value = property.getValue();
119121
if (thisClass.isInstance(value)) {
120122
return thisClass.cast(value);
121123
}
@@ -124,8 +126,8 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName,
124126
}
125127

126128
@Nullable
127-
private String getStringPropertyValue(String propertyName) {
128-
JsonStringLiteral stringLiteral = getPropertyValueOfType(
129+
private String getStringPropertyValue(final String propertyName) {
130+
final JsonStringLiteral stringLiteral = getPropertyValueOfType(
129131
propertyName,
130132
JsonStringLiteral.class
131133
);

src/com/magento/idea/magento2plugin/project/startup/CheckIfMagentoPathIsValidActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public void runActivity(final @NotNull Project project) {
2525

2626
@Nullable
2727
@Override
28-
public Object execute(@NotNull Project project,
29-
@NotNull Continuation<? super Unit> continuation) {
28+
public Object execute(@NotNull final Project project,
29+
@NotNull final Continuation<? super Unit> continuation) {
3030
registerSettings(project);
3131
return null;
3232
}

0 commit comments

Comments
 (0)