Skip to content

Commit b47e5ed

Browse files
Static fixes
1 parent b4d26e7 commit b47e5ed

32 files changed

+180
-115
lines changed

src/com/magento/idea/magento2plugin/bundles/AbstractBundle.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,38 @@
1010

1111
public abstract class AbstractBundle {
1212

13-
abstract public String getBundleName();
14-
15-
public String message(String key, Object... params) {
16-
ResourceBundle BUNDLE = ResourceBundle.getBundle(getBundleName());
17-
18-
return CommonBundle.message(BUNDLE, key, params);
13+
public abstract String getBundleName();
14+
15+
/**
16+
* Get bundle message.
17+
*
18+
* @param key String
19+
* @param params Object[]
20+
*
21+
* @return String
22+
*/
23+
public String message(final String key, final Object... params) {
24+
final ResourceBundle bundle = ResourceBundle.getBundle(getBundleName());
25+
26+
return CommonBundle.message(bundle, key, params);
1927
}
2028

21-
public String messageOrDefault(String key, String defaultValue, Object... params) {
22-
ResourceBundle BUNDLE = ResourceBundle.getBundle(getBundleName());
23-
24-
return CommonBundle.messageOrDefault(BUNDLE, key, defaultValue, params);
29+
/**
30+
* Get message or default value.
31+
*
32+
* @param key String
33+
* @param defaultValue String
34+
* @param params Object[]
35+
*
36+
* @return String
37+
*/
38+
public String messageOrDefault(
39+
final String key,
40+
final String defaultValue,
41+
final Object... params
42+
) {
43+
final ResourceBundle bundle = ResourceBundle.getBundle(getBundleName());
44+
45+
return CommonBundle.messageOrDefault(bundle, key, defaultValue, params);
2546
}
2647
}

src/com/magento/idea/magento2uct/execution/DefaultExecutor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,21 @@ public DefaultExecutor(
5959
public void run() {
6060
FileDocumentManager.getInstance().saveAllDocuments();
6161

62-
ConsoleView view = createConsole();
62+
final ConsoleView view = createConsole();
6363
view.attachToProcess(myProcess);
6464

6565
myProcess.startNotify();
6666
}
6767

68+
/**
69+
* Get process.
70+
*
71+
* @return ProcessHandler
72+
*/
73+
public ProcessHandler getMyProcess() {
74+
return myProcess;
75+
}
76+
6877
/**
6978
* Create console view.
7079
*
@@ -119,7 +128,7 @@ private static JComponent createConsolePanel(
119128
final ConsoleView view,
120129
final DefaultActionGroup actionGroup
121130
) {
122-
JPanel panel = new JPanel();
131+
final JPanel panel = new JPanel();
123132
final ActionToolbar actionToolbar = ActionManager
124133
.getInstance()
125134
.createActionToolbar(
@@ -136,7 +145,7 @@ private static JComponent createConsolePanel(
136145
}
137146

138147
@Override
139-
public void dispose() {
148+
public void dispose() {//NOPMD
140149
}
141150

142151
private class StopAction extends AnAction implements DumbAware {
@@ -151,13 +160,15 @@ public StopAction() {
151160

152161
@Override
153162
public void actionPerformed(final @NotNull AnActionEvent event) {
154-
myProcess.destroyProcess();
163+
DefaultExecutor.this.getMyProcess().destroyProcess();
155164
}
156165

157166
@Override
158167
public void update(final @NotNull AnActionEvent event) {
159168
event.getPresentation().setVisible(true);
160-
event.getPresentation().setEnabled(!myProcess.isProcessTerminated());
169+
event.getPresentation().setEnabled(
170+
!DefaultExecutor.this.getMyProcess().isProcessTerminated()
171+
);
161172
}
162173
}
163174
}

src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.jetbrains.annotations.NotNull;
3737
import org.jetbrains.annotations.Nullable;
3838

39+
@SuppressWarnings({"PMD.NPathComplexity", "PMD.ExcessiveImports", "PMD.CognitiveComplexity"})
3940
public class GenerateUctReportCommand {
4041

4142
private final Project project;
@@ -73,11 +74,9 @@ public void processTerminated(final @NotNull ProcessEvent event) {
7374
/**
7475
* Execute command.
7576
*/
77+
@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.AvoidInstantiatingObjectsInLoops"})
7678
public void execute() {
7779
output.write("Upgrade compatibility tool\n");
78-
final UctInspectionManager inspectionManager = new UctInspectionManager(project);
79-
final UctReportOutputUtil outputUtil = new UctReportOutputUtil(output);
80-
8180
final PsiDirectory rootDirectory = getTargetPsiDirectory();
8281

8382
if (rootDirectory == null) {
@@ -96,6 +95,7 @@ public void execute() {
9695
settingsService.getTargetVersion()
9796
);
9897
final ReportBuilder reportBuilder = new ReportBuilder(project);
98+
final UctReportOutputUtil outputUtil = new UctReportOutputUtil(output);
9999

100100
ApplicationManager.getApplication().executeOnPooledThread(() -> {
101101
ApplicationManager.getApplication().runReadAction(() -> {
@@ -111,6 +111,9 @@ public void execute() {
111111
continue;
112112
}
113113
final String filename = psiFile.getVirtualFile().getPath();
114+
final UctInspectionManager inspectionManager = new UctInspectionManager(
115+
project
116+
);
114117
final UctProblemsHolder fileProblemsHolder = inspectionManager.run(psiFile);
115118

116119
if (fileProblemsHolder == null) {

src/com/magento/idea/magento2uct/execution/ReindexUctCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void processTerminated(final @NotNull ProcessEvent event) {
6767
*
6868
* @param version SupportedVersion
6969
*/
70+
@SuppressWarnings({"PMD.CognitiveComplexity", "PMD.AvoidInstantiatingObjectsInLoops"})
7071
public void execute(final @NotNull SupportedVersion version) {
7172
if (project.getBasePath() == null) {
7273
return;

src/com/magento/idea/magento2uct/execution/output/ReportBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.LinkedList;
3030
import java.util.List;
3131
import java.util.Locale;
32-
3332
import org.jetbrains.annotations.NotNull;
3433
import org.json.simple.JSONObject;
3534

@@ -87,6 +86,7 @@ public void addSummary(final Summary summary) {
8786
*
8887
* @return JsonFile
8988
*/
89+
@SuppressWarnings({"PMD.NPathComplexity", "PMD.CyclomaticComplexity"})
9090
public JsonFile build() {
9191
if (report.getIssues().isEmpty() || report.getSummary() == null) {
9292
return null;

src/com/magento/idea/magento2uct/execution/output/Summary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class Summary {
2020
private int processedModules;
2121
private long processStartedTime;
2222
private long processEndedTime;
23-
private int phpWarnings = 0;
24-
private int phpErrors = 0;
25-
private int phpCriticalErrors = 0;
23+
private int phpWarnings;
24+
private int phpErrors;
25+
private int phpCriticalErrors;
2626

2727
/**
2828
* Summary.

src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public void printProblemFile(final @NotNull String filePath) {
5757
* @param code int
5858
*/
5959
public void printIssue(final @NotNull ProblemDescriptor descriptor, final int code) {
60-
final String errorMessage = descriptor.getDescriptionTemplate().substring(6).trim();
6160
final SupportedIssue issue = SupportedIssue.getByCode(code);
6261

6362
if (issue == null) {
6463
return;
6564
}
65+
final String errorMessage = descriptor.getDescriptionTemplate().substring(6).trim();
6666

6767
final String output = ISSUE_FORMAT
6868
.replace("{SEVERITY}", issue.getLevel().getFormattedLabel())
@@ -79,6 +79,7 @@ public void printIssue(final @NotNull ProblemDescriptor descriptor, final int co
7979
*
8080
* @param summary Summary
8181
*/
82+
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
8283
public void printSummary(final Summary summary) {
8384
if (!summary.hasProblems()) {
8485
stdout.print(stdout.wrapInfo("Couldn't find modules to analyse").concat("\n"));
@@ -115,14 +116,15 @@ public void printSummary(final Summary summary) {
115116
printSummarySeparator(longestKey + 2, longestValue + 2);
116117

117118
for (final Map.Entry<String, String> summaryEntry : summaryMap.entrySet()) {
118-
String header = summaryEntry.getKey();
119+
final StringBuilder header = new StringBuilder(summaryEntry.getKey());
119120
final String value = " " + summaryEntry.getValue();
120121

121122
if (header.length() < longestKey) {
122-
header += " ".repeat(longestKey - header.length());
123+
header.append(" ".repeat(longestKey - header.length()));
123124
}
124125
stdout.print(
125-
" " + stdout.wrapSummary(header).concat(" ").concat(value).concat("\n")
126+
" " + stdout.wrapSummary(header.toString())
127+
.concat(" ").concat(value).concat("\n")
126128
);
127129
}
128130
printSummarySeparator(longestKey + 2, longestValue + 2);

src/com/magento/idea/magento2uct/execution/process/DefaultAnalysisHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public DefaultAnalysisHandler(final @NotNull Project project) {
3030
new ProcessAdapter() {
3131
@Override
3232
public void startNotified(final @NotNull ProcessEvent event) {
33-
execute();
33+
DefaultAnalysisHandler.this.execute();
3434
}
3535
}
3636
);
@@ -39,7 +39,7 @@ public void startNotified(final @NotNull ProcessEvent event) {
3939
/**
4040
* Run the main analysis process.
4141
*/
42-
private void execute() {
42+
public void execute() {
4343
final GenerateUctReportCommand command = new GenerateUctReportCommand(
4444
project,
4545
new OutputWrapper(this),

src/com/magento/idea/magento2uct/execution/process/OutputWrapper.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
public final class OutputWrapper implements AnsiEscapeDecoder.ColoredTextAcceptor {
1717

18-
public static final String INFO_WRAPPER = "<info>{text}</info>";
19-
public static final String WARNING_WRAPPER = "<warning>{text}</warning>";
20-
public static final String ERROR_WRAPPER = "<error>{text}</error>";
21-
public static final String CRITICAL_WRAPPER = "<critical>{text}</critical>";
22-
public static final String SUMMARY_WRAPPER = "<summary>{text}</summary>";
18+
public static final String TEXT_PLACEHOLDER = "{text}";
19+
public static final String INFO_WRAPPER = "<info>" + TEXT_PLACEHOLDER + "</info>";
20+
public static final String WARNING_WRAPPER = "<warning>" + TEXT_PLACEHOLDER + "</warning>";
21+
public static final String ERROR_WRAPPER = "<error>" + TEXT_PLACEHOLDER + "</error>";
22+
public static final String CRITICAL_WRAPPER = "<critical>" + TEXT_PLACEHOLDER + "</critical>";
23+
public static final String SUMMARY_WRAPPER = "<summary>" + TEXT_PLACEHOLDER + "</summary>";
2324

2425
private final ProcessHandler processHandler;
2526
private final AnsiEscapeDecoder myAnsiEscapeDecoder = new AnsiEscapeDecoder();
@@ -104,7 +105,7 @@ public void write(final @NotNull String text) {
104105
* @return String
105106
*/
106107
public String wrapInfo(final @NotNull String text) {
107-
return INFO_WRAPPER.replace("{text}", text);
108+
return INFO_WRAPPER.replace(TEXT_PLACEHOLDER, text);
108109
}
109110

110111
/**
@@ -115,7 +116,7 @@ public String wrapInfo(final @NotNull String text) {
115116
* @return String
116117
*/
117118
public String wrapError(final @NotNull String text) {
118-
return ERROR_WRAPPER.replace("{text}", text);
119+
return ERROR_WRAPPER.replace(TEXT_PLACEHOLDER, text);
119120
}
120121

121122
/**
@@ -126,7 +127,7 @@ public String wrapError(final @NotNull String text) {
126127
* @return String
127128
*/
128129
public String wrapCritical(final @NotNull String text) {
129-
return CRITICAL_WRAPPER.replace("{text}", text);
130+
return CRITICAL_WRAPPER.replace(TEXT_PLACEHOLDER, text);
130131
}
131132

132133
/**
@@ -137,7 +138,7 @@ public String wrapCritical(final @NotNull String text) {
137138
* @return String
138139
*/
139140
public String wrapSummary(final @NotNull String text) {
140-
return SUMMARY_WRAPPER.replace("{text}", text);
141+
return SUMMARY_WRAPPER.replace(TEXT_PLACEHOLDER, text);
141142
}
142143

143144
/**

src/com/magento/idea/magento2uct/execution/process/ReindexHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ReindexHandler(
4040
new ProcessAdapter() {
4141
@Override
4242
public void startNotified(final @NotNull ProcessEvent event) {
43-
execute(version);
43+
ReindexHandler.this.execute(version);
4444
}
4545
}
4646
);
@@ -51,7 +51,7 @@ public void startNotified(final @NotNull ProcessEvent event) {
5151
*
5252
* @param version SupportedVersion
5353
*/
54-
private void execute(final @NotNull SupportedVersion version) {
54+
public void execute(final @NotNull SupportedVersion version) {
5555
final ReindexUctCommand command = new ReindexUctCommand(
5656
project,
5757
directory,

0 commit comments

Comments
 (0)