Skip to content

Commit dfeeb95

Browse files
author
Sergiy Zhovnir
committed
Added code adjustments
1 parent ab18bcf commit dfeeb95

18 files changed

+312
-255
lines changed

src/com/magento/idea/magento2plugin/actions/generation/NewControllerAction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewControllerDialog;
1818
import org.jetbrains.annotations.NotNull;
1919

20-
@SuppressWarnings({"PMD.OnlyOneReturn"})
20+
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
2121
public class NewControllerAction extends AnAction {
22-
public static String ACTION_NAME = "Magento 2 Controller";
23-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 controller";
22+
public static final String ACTION_NAME = "Magento 2 Controller";
23+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 controller";
2424

2525
/**
2626
* New controller action constructor.
@@ -31,8 +31,8 @@ public class NewControllerAction extends AnAction {
3131

3232
@Override
3333
public void actionPerformed(@NotNull AnActionEvent e) {
34-
DataContext dataContext = e.getDataContext();
35-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
34+
final DataContext dataContext = e.getDataContext();
35+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
3636

3737
if (view == null) {
3838
return;

src/com/magento/idea/magento2plugin/actions/generation/data/ControllerFileData.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
package com.magento.idea.magento2plugin.actions.generation.data;
77

88
public class ControllerFileData {
9-
private String actionDirectory;
10-
private String actionClassName;
11-
private String controllerModule;
12-
private String controllerArea;
13-
private String httpMethodName;
14-
private String acl;
15-
private Boolean isInheritClass;
16-
private String namespace;
9+
private final String actionDirectory;
10+
private final String actionClassName;
11+
private final String controllerModule;
12+
private final String controllerArea;
13+
private final String httpMethodName;
14+
private final String acl;
15+
private final Boolean isInheritClass;
16+
private final String namespace;
1717

1818
/**
1919
* Controller data file constructor.

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
import javax.swing.JTextField;
3535
import javax.swing.KeyStroke;
3636

37+
@SuppressWarnings({"PMD.TooManyFields", "PMD.OnlyOneReturn"})
3738
public class NewControllerDialog extends AbstractDialog {
3839
private final NewControllerValidator validator;
39-
private final PsiDirectory baseDir;
40-
private final GetModuleNameByDirectory getModuleNameByDir;
4140
private final String moduleName;
4241
private JPanel contentPane;
4342
private JButton buttonOK;
@@ -60,12 +59,10 @@ public class NewControllerDialog extends AbstractDialog {
6059
* @param project Project
6160
* @param directory PsiDirectory
6261
*/
63-
public NewControllerDialog(Project project, PsiDirectory directory) {
62+
public NewControllerDialog(final Project project, final PsiDirectory directory) {
6463
this.project = project;
65-
this.baseDir = directory;
6664
this.moduleName = GetModuleNameByDirectory.getInstance(project).execute(directory);
6765
this.validator = NewControllerValidator.getInstance(this);
68-
this.getModuleNameByDir = GetModuleNameByDirectory.getInstance(project);
6966

7067
setContentPane(contentPane);
7168
setModal(true);
@@ -170,7 +167,7 @@ public String getActionDirectory() {
170167
* @param project Project
171168
* @param directory PsiDirectory
172169
*/
173-
public static void open(Project project, PsiDirectory directory) {
170+
public static void open(final Project project, final PsiDirectory directory) {
174171
NewControllerDialog dialog = new NewControllerDialog(project, directory);
175172
dialog.pack();
176173
dialog.centerDialog(dialog);
@@ -200,7 +197,7 @@ private PsiFile generateFile() {
200197
}
201198

202199
private void suggestControllerDirectory() {
203-
String area = getArea();
200+
final String area = getArea();
204201
if (area.equals(Package.Areas.adminhtml.toString())) {
205202
controllerParentDir.setText(ControllerBackendPhp.DEFAULT_DIR);
206203
return;
@@ -209,32 +206,24 @@ private void suggestControllerDirectory() {
209206
}
210207

211208
private void toggleAdminPanel() {
212-
String area = getArea();
209+
final String area = getArea();
213210
if (area.equals(Package.Areas.adminhtml.toString()) && inheritClass.isSelected()) {
214211
adminPanel.setVisible(true);
215212
return;
216213
}
217214
adminPanel.setVisible(false);
218215
}
219216

220-
private String getModuleIdentifierPath() {
221-
String[]parts = moduleName.split(Package.VENDOR_MODULE_NAME_SEPARATOR);
222-
if (parts[0] == null || parts[1] == null || parts.length > 2) {
223-
return null;
224-
}
225-
return parts[0] + File.separator + parts[1];
226-
}
227-
228217
private String getNamespace() {
229-
String[]parts = moduleName.split(Package.VENDOR_MODULE_NAME_SEPARATOR);
218+
final String[]parts = moduleName.split(Package.VENDOR_MODULE_NAME_SEPARATOR);
230219
if (parts[0] == null || parts[1] == null || parts.length > 2) {
231220
return null;
232221
}
233-
String directoryPart = getControllerDirectory().replace(
222+
final String directoryPart = getControllerDirectory().replace(
234223
File.separator,
235224
Package.FQN_SEPARATOR
236225
);
237-
String controllerPart = Package.FQN_SEPARATOR + getControllerName();
226+
final String controllerPart = Package.FQN_SEPARATOR + getControllerName();
238227

239228
return String.format(
240229
"%s%s%s%s%s%s",

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/CreateAPluginDialogValidator.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import java.util.List;
1616
import javax.swing.JOptionPane;
1717

18-
@SuppressWarnings({"PMD.OnlyOneReturn"})
18+
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
1919
public class CreateAPluginDialogValidator {
20+
private static final String NOT_EMPTY = "validator.notEmpty";
21+
private static final String PLUGIN_CLASS_NAME = "Plugin Class Name";
2022
private static CreateAPluginDialogValidator INSTANCE = null;
21-
private ValidatorBundle validatorBundle;
22-
private CommonBundle commonBundle;
23+
private final ValidatorBundle validatorBundle;
24+
private final CommonBundle commonBundle;
2325
private CreateAPluginDialog dialog;
2426

2527
/**
@@ -41,7 +43,7 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
4143
/**
4244
* Create a plugin dialog validator.
4345
*/
44-
public CreateAPluginDialogValidator() {
46+
private CreateAPluginDialogValidator() {
4547
this.validatorBundle = new ValidatorBundle();
4648
this.commonBundle = new CommonBundle();
4749
}
@@ -53,14 +55,14 @@ public CreateAPluginDialogValidator() {
5355
*
5456
* @return Boolean
5557
*/
56-
public boolean validate(Project project) {
57-
String errorTitle = commonBundle.message("common.error");
58-
String pluginClassName = dialog.getPluginClassName();
58+
public boolean validate(final Project project) {
59+
final String errorTitle = commonBundle.message("common.error");
60+
final String pluginClassName = dialog.getPluginClassName();
5961

6062
if (!PhpNameUtil.isValidClassName(pluginClassName)) {
61-
String errorMessage = this.validatorBundle.message(
63+
final String errorMessage = this.validatorBundle.message(
6264
"validator.class.isNotValid",
63-
"Plugin Class Name"
65+
PLUGIN_CLASS_NAME
6466
);
6567
JOptionPane.showMessageDialog(
6668
null,
@@ -73,9 +75,9 @@ public boolean validate(Project project) {
7375
}
7476

7577
if (pluginClassName.length() == 0) {
76-
String errorMessage = validatorBundle.message(
77-
"validator.notEmpty",
78-
"Plugin Class Name"
78+
final String errorMessage = validatorBundle.message(
79+
NOT_EMPTY,
80+
PLUGIN_CLASS_NAME
7981
);
8082
JOptionPane.showMessageDialog(
8183
null,
@@ -88,9 +90,9 @@ public boolean validate(Project project) {
8890
}
8991

9092
if (!pluginClassName.matches(RegExUtil.ALPHANUMERIC)) {
91-
String errorMessage = validatorBundle.message(
93+
final String errorMessage = validatorBundle.message(
9294
"validator.alphaNumericCharacters",
93-
"Plugin Class Name"
95+
PLUGIN_CLASS_NAME
9496
);
9597
JOptionPane.showMessageDialog(
9698
null,
@@ -105,9 +107,9 @@ public boolean validate(Project project) {
105107
if (!Character.isUpperCase(pluginClassName.charAt(0))
106108
&& !Character.isDigit(pluginClassName.charAt(0))
107109
) {
108-
String errorMessage = validatorBundle.message(
110+
final String errorMessage = validatorBundle.message(
109111
"validator.startWithNumberOrCapitalLetter",
110-
"Plugin Class Name"
112+
PLUGIN_CLASS_NAME
111113
);
112114
JOptionPane.showMessageDialog(
113115
null,
@@ -119,10 +121,10 @@ public boolean validate(Project project) {
119121
return false;
120122
}
121123

122-
String pluginDirectory = dialog.getPluginDirectory();
124+
final String pluginDirectory = dialog.getPluginDirectory();
123125
if (pluginDirectory.length() == 0) {
124-
String errorMessage = validatorBundle.message(
125-
"validator.notEmpty",
126+
final String errorMessage = validatorBundle.message(
127+
NOT_EMPTY,
126128
"Plugin Directory"
127129
);
128130
JOptionPane.showMessageDialog(
@@ -136,7 +138,7 @@ public boolean validate(Project project) {
136138
}
137139

138140
if (!pluginDirectory.matches(RegExUtil.DIRECTORY)) {
139-
String errorMessage = validatorBundle.message(
141+
final String errorMessage = validatorBundle.message(
140142
"validator.directory.isNotValid",
141143
"Plugin Directory"
142144
);
@@ -150,10 +152,10 @@ public boolean validate(Project project) {
150152
return false;
151153
}
152154

153-
String pluginName = dialog.getPluginName();
155+
final String pluginName = dialog.getPluginName();
154156
if (pluginName.length() == 0) {
155-
String errorMessage = validatorBundle.message(
156-
"validator.notEmpty",
157+
final String errorMessage = validatorBundle.message(
158+
NOT_EMPTY,
157159
"Plugin Name"
158160
);
159161
JOptionPane.showMessageDialog(
@@ -167,7 +169,7 @@ public boolean validate(Project project) {
167169
}
168170

169171
if (!pluginName.matches(RegExUtil.IDENTIFIER)) {
170-
String errorMessage = validatorBundle.message(
172+
final String errorMessage = validatorBundle.message(
171173
"validator.identifier",
172174
"Plugin Name"
173175
);
@@ -181,10 +183,10 @@ public boolean validate(Project project) {
181183
return false;
182184
}
183185

184-
String sortOrder = dialog.getPluginSortOrder();
186+
final String sortOrder = dialog.getPluginSortOrder();
185187
if (sortOrder.length() == 0) {
186-
String errorMessage = validatorBundle.message(
187-
"validator.notEmpty",
188+
final String errorMessage = validatorBundle.message(
189+
NOT_EMPTY,
188190
"Sort Order"
189191
);
190192
JOptionPane.showMessageDialog(
@@ -198,7 +200,7 @@ public boolean validate(Project project) {
198200
}
199201

200202
if (!sortOrder.matches(RegExUtil.NUMERIC)) {
201-
String errorMessage = validatorBundle.message(
203+
final String errorMessage = validatorBundle.message(
202204
"validator.onlyNumbers",
203205
"Sort Order"
204206
);
@@ -212,10 +214,10 @@ public boolean validate(Project project) {
212214
return false;
213215
}
214216

215-
String pluginModule = dialog.getPluginModule();
217+
final String pluginModule = dialog.getPluginModule();
216218
if (pluginModule.length() == 0) {
217-
String errorMessage = validatorBundle.message(
218-
"validator.notEmpty",
219+
final String errorMessage = validatorBundle.message(
220+
NOT_EMPTY,
219221
"Plugin Module"
220222
);
221223
JOptionPane.showMessageDialog(
@@ -228,9 +230,9 @@ public boolean validate(Project project) {
228230
return false;
229231
}
230232

231-
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
233+
final List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
232234
if (!allModulesList.contains(pluginModule)) {
233-
String errorMessage = validatorBundle.message(
235+
final String errorMessage = validatorBundle.message(
234236
"validator.module.noSuchModule",
235237
pluginModule
236238
);

0 commit comments

Comments
 (0)