Skip to content

Commit

Permalink
more lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkwiecinski committed Jun 29, 2024
1 parent 6f001ef commit 6080247
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
12 changes: 6 additions & 6 deletions gradle-tasks/staticChecks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ pmd {
ruleSets = []
}

tasks.withType(Checkstyle) {
tasks.withType(Checkstyle).configureEach {
// Specify all files that should be checked
classpath = files()
source "${project.rootDir}"
}

// Execute Checkstyle on all files
task checkstyle(type: Checkstyle) {
tasks.register('checkstyle', Checkstyle) {
}

// Execute Checkstyle on all modified files
task checkstyleCI(type: Checkstyle) {
tasks.register('checkstyleCI', Checkstyle) {
def changedFiles = getChangedFiles()
include changedFiles
}

tasks.withType(Pmd) {
tasks.withType(Pmd).configureEach {
// Specify all files that should be checked
classpath = files()
source "${project.rootDir}"
}

// Execute Checkstyle on all files
task pmd(type: Pmd) {
tasks.register('pmd', Pmd) {
}

// Execute Checkstyle on all modified files
task pmdCI(type: Pmd) {
tasks.register('pmdCI', Pmd) {
def changedFiles = getChangedFiles()
include changedFiles
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ComposerPackageModelImpl implements ComposerPackageModel {
private JsonObject sourceComposerJson;
private final JsonObject sourceComposerJson;

public static final String NAME = "name";
public static final String TYPE = "type";
Expand Down Expand Up @@ -67,12 +68,12 @@ public String[] getAutoloadFiles() {
JsonArray jsonArray = getPropertyValueOfType(FILES, JsonArray.class);
if (jsonArray != null) {
List<String> files = new ArrayList<>();
for(JsonValue value: jsonArray.getValueList()) {
for (JsonValue value : jsonArray.getValueList()) {
if (value instanceof JsonStringLiteral) {
files.add(StringUtils.strip(value.getText(), "\""));
}
}
return files.size() > 0 ? files.toArray(new String[files.size()]) : null;
return !files.isEmpty() ? files.toArray(new String[files.size()]) : null;
}
}

Expand All @@ -86,30 +87,31 @@ public Map<String, String> getAutoloadPsr4() {
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()) {
Map<String, String> map = new HashMap<String, String>();
for (JsonProperty property : jsonObject.getPropertyList()) {
JsonValue value = property.getValue();

if (value != null && value instanceof JsonStringLiteral) {
if (value instanceof JsonStringLiteral) {
map.put(property.getName(), StringUtils.strip(value.getText(), "\""));
}
}

return map.size() > 0 ? map : null;
return !map.isEmpty() ? map : null;
}
}

return null;
}

@Nullable
public <T extends JsonValue> T getPropertyValueOfType(String propertyName, @NotNull Class<T> aClass) {
public <T extends JsonValue> T getPropertyValueOfType(String propertyName,
@NotNull Class<T> aClass) {
JsonProperty property = sourceComposerJson.findProperty(propertyName);
if (property == null) {
return null;
}
JsonValue value = property.getValue();
if (value != null && aClass.isInstance(value)) {
if (aClass.isInstance(value)) {
return aClass.cast(value);
}

Expand All @@ -118,7 +120,10 @@ public <T extends JsonValue> T getPropertyValueOfType(String propertyName, @NotN

@Nullable
private String getStringPropertyValue(String propertyName) {
JsonStringLiteral stringLiteral = getPropertyValueOfType(propertyName, JsonStringLiteral.class);
JsonStringLiteral stringLiteral = getPropertyValueOfType(
propertyName,
JsonStringLiteral.class
);

if (stringLiteral != null) {
return StringUtils.strip(stringLiteral.getText(), "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@

public class CheckIfMagentoPathIsValidActivity implements StartupActivity, ProjectActivity {

public void registerSettings(final @NotNull Project project) {
final Settings settings = Settings.getInstance(project);
final String path = settings.magentoPath;
if (settings.pluginEnabled && (path == null || path.isEmpty())) {
if (MagentoBasePathUtil.isMagentoFolderValid(project.getBasePath())) {
settings.setMagentoPath(project.getBasePath());
return;
}
settings.pluginEnabled = false;
ConfigurationManager.suggestToConfigureMagentoPath(project);
}
}

@Override
public void runActivity(final @NotNull Project project) {
registerSettings(project);
Expand All @@ -43,4 +30,17 @@ public Object execute(@NotNull Project project,
registerSettings(project);
return null;
}

private void registerSettings(final @NotNull Project project) {
final Settings settings = Settings.getInstance(project);
final String path = settings.magentoPath;
if (settings.pluginEnabled && (path == null || path.isEmpty())) {
if (MagentoBasePathUtil.isMagentoFolderValid(project.getBasePath())) {
settings.setMagentoPath(project.getBasePath());
return;
}
settings.pluginEnabled = false;
ConfigurationManager.suggestToConfigureMagentoPath(project);
}
}
}

0 comments on commit 6080247

Please sign in to comment.