Skip to content

Commit

Permalink
fix pmd issues
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkwiecinski committed Jun 29, 2024
1 parent a35aa9c commit f3efc91
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public class ComposerPackageModelImpl implements ComposerPackageModel {
private final JsonObject sourceComposerJson;
private static final int VENDOR_AND_PACKAGE_PARTS_LENGTH = 2;

public static final String NAME = "name";
public static final String TYPE = "type";
Expand All @@ -28,7 +29,7 @@ public class ComposerPackageModelImpl implements ComposerPackageModel {
public static final String PSR4 = "psr4";
public static final String FILES = "file";

public ComposerPackageModelImpl(@NotNull JsonObject sourceComposerJson) {
public ComposerPackageModelImpl(@NotNull final JsonObject sourceComposerJson) {
this.sourceComposerJson = sourceComposerJson;
}

Expand All @@ -47,10 +48,10 @@ public String getType() {
@Nullable
@Override
public String getVendor() {
String nameProperty = getStringPropertyValue(NAME);
final String nameProperty = getStringPropertyValue(NAME);
if (nameProperty != null) {
String[] vendorAndPackage = nameProperty.split("/");
if (vendorAndPackage.length == 2) {
final String[] vendorAndPackage = nameProperty.split("/");
if (vendorAndPackage.length == VENDOR_AND_PACKAGE_PARTS_LENGTH) {
return vendorAndPackage[0];
}
}
Expand All @@ -67,55 +68,56 @@ public String getVersion() {
@Nullable
@Override
public String[] getAutoloadFiles() {
JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
final JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
if (autoloadObject != null) {
JsonArray jsonArray = getPropertyValueOfType(FILES, JsonArray.class);
if (jsonArray != null) {
List<String> files = new ArrayList<>();
for (JsonValue value : jsonArray.getValueList()) {
if (value instanceof JsonStringLiteral) {
files.add(StringUtils.strip(value.getText(), "\""));
}
return new String[0];
}

final JsonArray jsonArray = getPropertyValueOfType(FILES, JsonArray.class);
if (jsonArray != null) {
final List<String> files = new ArrayList<>();
for (final JsonValue value : jsonArray.getValueList()) {
if (value instanceof JsonStringLiteral) {
files.add(StringUtils.strip(value.getText(), "\""));
}
return !files.isEmpty() ? files.toArray(new String[files.size()]) : null;
}
return files.isEmpty() ? new String[0] : files.toArray(new String[0]);
}

return null;
return new String[0];
}

@Nullable
@Override
public Map<String, String> getAutoloadPsr4() {
JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
if (autoloadObject != null) {
JsonObject jsonObject = getPropertyValueOfType(PSR4, JsonObject.class);
if (jsonObject != null) {
Map<String, String> map = new HashMap<String, String>();
for (JsonProperty property : jsonObject.getPropertyList()) {
JsonValue value = property.getValue();

if (value instanceof JsonStringLiteral) {
map.put(property.getName(), StringUtils.strip(value.getText(), "\""));
}
}
final JsonObject autoloadObject = getPropertyValueOfType(AUTOLOAD, JsonObject.class);
final Map<String, String> map = new HashMap<>();
if (autoloadObject == null) {
return map;
}

return !map.isEmpty() ? map : null;
final JsonObject jsonObject = getPropertyValueOfType(PSR4, JsonObject.class);
if (jsonObject != null) {
for (final JsonProperty property : jsonObject.getPropertyList()) {
final JsonValue value = property.getValue();
if (value instanceof JsonStringLiteral) {
map.put(property.getName(), StringUtils.strip(value.getText(), "\""));
}
}
}

return null;
return map;
}

@Nullable
@Override
public <T extends JsonValue> T getPropertyValueOfType(String propertyName,
@NotNull Class<T> thisClass) {
JsonProperty property = sourceComposerJson.findProperty(propertyName);
public <T extends JsonValue> T getPropertyValueOfType(final String propertyName,
@NotNull final Class<T> thisClass) {
final JsonProperty property = sourceComposerJson.findProperty(propertyName);
if (property == null) {
return null;
}
JsonValue value = property.getValue();
final JsonValue value = property.getValue();
if (thisClass.isInstance(value)) {
return thisClass.cast(value);
}
Expand All @@ -124,8 +126,8 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName,
}

@Nullable
private String getStringPropertyValue(String propertyName) {
JsonStringLiteral stringLiteral = getPropertyValueOfType(
private String getStringPropertyValue(final String propertyName) {
final JsonStringLiteral stringLiteral = getPropertyValueOfType(
propertyName,
JsonStringLiteral.class
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void runActivity(final @NotNull Project project) {

@Nullable
@Override
public Object execute(@NotNull Project project,
@NotNull Continuation<? super Unit> continuation) {
public Object execute(@NotNull final Project project,
@NotNull final Continuation<? super Unit> continuation) {
registerSettings(project);
return null;
}
Expand Down

0 comments on commit f3efc91

Please sign in to comment.