Skip to content

Commit 7f3f522

Browse files
author
Sergiy Zhovnir
committed
Fixing static tests
1 parent 5956d25 commit 7f3f522

18 files changed

+155
-124
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
@@ -25,25 +25,25 @@ public class NewControllerAction extends AnAction {
2525
/**
2626
* New controller action constructor.
2727
*/
28-
NewControllerAction() {
28+
public NewControllerAction() {
2929
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
3030
}
3131

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

3737
if (view == null) {
3838
return;
3939
}
4040

41-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
4242
if (project == null) {
4343
return;
4444
}
4545

46-
PsiDirectory directory = view.getOrChooseDirectory();
46+
final PsiDirectory directory = view.getOrChooseDirectory();
4747
if (directory == null) {
4848
return;
4949
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.data;
77

8+
@SuppressWarnings({"PMD.DataClass"})
89
public class ControllerFileData {
910
private final String actionDirectory;
1011
private final String actionClassName;
@@ -28,14 +29,14 @@ public class ControllerFileData {
2829
* @param namespace String
2930
*/
3031
public ControllerFileData(
31-
String actionDirectory,
32-
String controllerClassName,
33-
String controllerModule,
34-
String controllerArea,
35-
String httpMethodName,
36-
String acl,
37-
Boolean isInheritClass,
38-
String namespace
32+
final String actionDirectory,
33+
final String controllerClassName,
34+
final String controllerModule,
35+
final String controllerArea,
36+
final String httpMethodName,
37+
final String acl,
38+
final Boolean isInheritClass,
39+
final String namespace
3940
) {
4041
this.actionDirectory = actionDirectory;
4142
this.actionClassName = controllerClassName;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<text value=""/>
7878
</properties>
7979
</component>
80-
<component id="d25a" class="javax.swing.JLabel" binding="controllerParentDirectoryLabel">
80+
<component id="d25a" class="javax.swing.JLabel">
8181
<constraints>
8282
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
8383
</constraints>
@@ -124,7 +124,7 @@
124124
<html.disable class="java.lang.Boolean" value="false"/>
125125
</clientProperties>
126126
</component>
127-
<component id="ad25c" class="javax.swing.JLabel" binding="controllerAreaLabel">
127+
<component id="ad25c" class="javax.swing.JLabel">
128128
<constraints>
129129
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
130130
</constraints>

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp;
1717
import com.magento.idea.magento2plugin.magento.packages.Areas;
1818
import com.magento.idea.magento2plugin.magento.packages.File;
19-
import com.magento.idea.magento2plugin.magento.packages.HttpRequest;
19+
import com.magento.idea.magento2plugin.magento.packages.HttpMethod;
2020
import com.magento.idea.magento2plugin.magento.packages.Package;
2121
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2222
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectory;
@@ -27,26 +27,27 @@
2727
import java.awt.event.WindowEvent;
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
30+
import java.util.List;
3031
import javax.swing.JButton;
3132
import javax.swing.JCheckBox;
3233
import javax.swing.JComponent;
33-
import javax.swing.JLabel;
3434
import javax.swing.JPanel;
3535
import javax.swing.JTextField;
3636
import javax.swing.KeyStroke;
3737

38-
@SuppressWarnings({"PMD.TooManyFields", "PMD.OnlyOneReturn"})
38+
@SuppressWarnings({
39+
"PMD.TooManyFields",
40+
"PMD.ConstructorCallsOverridableMethod"
41+
})
3942
public class NewControllerDialog extends AbstractDialog {
4043
private final NewControllerValidator validator;
4144
private final String moduleName;
45+
private final Project project;
4246
private JPanel contentPane;
4347
private JButton buttonOK;
44-
private Project project;
4548
private JButton buttonCancel;
4649
private FilteredComboBox controllerAreaSelect;
47-
private JLabel controllerAreaLabel;
4850
private FilteredComboBox httpMethodSelect;
49-
private JLabel controllerParentDirectoryLabel;
5051
private JTextField controllerName;
5152
private JTextField controllerParentDir;
5253
private JCheckBox inheritClass;
@@ -61,6 +62,7 @@ public class NewControllerDialog extends AbstractDialog {
6162
* @param directory PsiDirectory
6263
*/
6364
public NewControllerDialog(final Project project, final PsiDirectory directory) {
65+
super();
6466
this.project = project;
6567
this.moduleName = GetModuleNameByDirectory.getInstance(project).execute(directory);
6668
this.validator = NewControllerValidator.getInstance(this);
@@ -78,15 +80,15 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
7880
// call onCancel() when cross is clicked
7981
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
8082
addWindowListener(new WindowAdapter() {
81-
public void windowClosing(WindowEvent e) {
83+
public void windowClosing(final WindowEvent event) {
8284
onCancel();
8385
}
8486
});
8587

8688
// call onCancel() on ESCAPE
8789
contentPane.registerKeyboardAction(
8890
new ActionListener() {
89-
public void actionPerformed(ActionEvent e) {
91+
public void actionPerformed(final ActionEvent event) {
9092
onCancel();
9193
}
9294
},
@@ -169,7 +171,7 @@ public String getActionDirectory() {
169171
* @param directory PsiDirectory
170172
*/
171173
public static void open(final Project project, final PsiDirectory directory) {
172-
NewControllerDialog dialog = new NewControllerDialog(project, directory);
174+
final NewControllerDialog dialog = new NewControllerDialog(project, directory);
173175
dialog.pack();
174176
dialog.centerDialog(dialog);
175177
dialog.setVisible(true);
@@ -245,7 +247,7 @@ protected void onCancel() {
245247
dispose();
246248
}
247249

248-
private ArrayList<String> getAreaList() {
250+
private List<String> getAreaList() {
249251
return new ArrayList<>(
250252
Arrays.asList(
251253
Areas.frontend.toString(),
@@ -254,8 +256,9 @@ private ArrayList<String> getAreaList() {
254256
);
255257
}
256258

259+
@SuppressWarnings({"PMD.UnusedPrivateMethod"})
257260
private void createUIComponents() {
258261
this.controllerAreaSelect = new FilteredComboBox(getAreaList());
259-
this.httpMethodSelect = new FilteredComboBox(HttpRequest.getHttpMethodList());
262+
this.httpMethodSelect = new FilteredComboBox(HttpMethod.getHttpMethodList());
260263
}
261264
}

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

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

18-
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
18+
@SuppressWarnings({
19+
"PMD.OnlyOneReturn",
20+
"PMD.CyclomaticComplexity",
21+
"PMD.NonThreadSafeSingleton",
22+
"PMD.NPathComplexity",
23+
"PMD.FieldNamingConventions"
24+
})
1925
public class CreateAPluginDialogValidator {
2026
private static final String NOT_EMPTY = "validator.notEmpty";
2127
private static final String PLUGIN_CLASS_NAME = "Plugin Class Name";
22-
private static CreateAPluginDialogValidator INSTANCE = null;
28+
private static CreateAPluginDialogValidator INSTANCE;
2329
private final ValidatorBundle validatorBundle;
2430
private final CommonBundle commonBundle;
2531
private CreateAPluginDialog dialog;
@@ -31,7 +37,7 @@ public class CreateAPluginDialogValidator {
3137
*
3238
* @return CreateAPluginDialogValidator
3339
*/
34-
public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialog) {
40+
public static CreateAPluginDialogValidator getInstance(final CreateAPluginDialog dialog) {
3541
if (null == INSTANCE) {
3642
INSTANCE = new CreateAPluginDialogValidator();
3743
}
@@ -43,7 +49,7 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
4349
/**
4450
* Create a plugin dialog validator.
4551
*/
46-
private CreateAPluginDialogValidator() {
52+
public CreateAPluginDialogValidator() {
4753
this.validatorBundle = new ValidatorBundle();
4854
this.commonBundle = new CommonBundle();
4955
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
@SuppressWarnings({
1919
"PMD.OnlyOneReturn",
2020
"PMD.FieldNamingConventions",
21+
"PMD.CyclomaticComplexity",
22+
"PMD.NonThreadSafeSingleton",
2123
"PMD.DataflowAnomalyAnalysis",
2224
"PMD.NPathComplexity"
2325
})
2426
public class CreateAnObserverDialogValidator {
25-
private static CreateAnObserverDialogValidator INSTANCE = null;
27+
private static final String OBSERVER_CLASS_NAME = "Observer Class Name";
28+
private static CreateAnObserverDialogValidator INSTANCE;
2629
private final ValidatorBundle validatorBundle;
2730
private final CommonBundle commonBundle;
2831
private CreateAnObserverDialog dialog;
@@ -64,7 +67,7 @@ public boolean validate(final Project project) {
6467
if (!PhpNameUtil.isValidClassName(observerClassName)) {
6568
final String errorMessage = this.validatorBundle.message(
6669
"validator.class.isNotValid",
67-
"Observer Class Name"
70+
OBSERVER_CLASS_NAME
6871
);
6972
JOptionPane.showMessageDialog(
7073
null,
@@ -79,7 +82,7 @@ public boolean validate(final Project project) {
7982
if (observerClassName.length() == 0) {
8083
final String errorMessage = validatorBundle.message(
8184
"validator.notEmpty",
82-
"Observer Class Name"
85+
OBSERVER_CLASS_NAME
8386
);
8487
JOptionPane.showMessageDialog(
8588
null,
@@ -94,7 +97,7 @@ public boolean validate(final Project project) {
9497
if (!observerClassName.matches(RegExUtil.ALPHANUMERIC)) {
9598
final String errorMessage = validatorBundle.message(
9699
"validator.alphaNumericCharacters",
97-
"Observer Class Name"
100+
OBSERVER_CLASS_NAME
98101
);
99102
JOptionPane.showMessageDialog(
100103
null,
@@ -111,7 +114,7 @@ public boolean validate(final Project project) {
111114
) {
112115
final String errorMessage = validatorBundle.message(
113116
"validator.startWithNumberOrCapitalLetter",
114-
"Observer Class Name"
117+
OBSERVER_CLASS_NAME
115118
);
116119
JOptionPane.showMessageDialog(
117120
null,

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
@SuppressWarnings({
1616
"PMD.OnlyOneReturn",
1717
"PMD.FieldNamingConventions",
18+
"PMD.NonThreadSafeSingleton",
1819
"PMD.DataflowAnomalyAnalysis",
1920
"PMD.NPathComplexity"
2021
})
2122
public class NewBlockValidator {
22-
private static NewBlockValidator INSTANCE = null;
23+
private static final String BLOCK_NAME = "Block Name";
24+
private static NewBlockValidator INSTANCE;
2325
private final ValidatorBundle validatorBundle;
2426
private final CommonBundle commonBundle;
2527
private NewBlockDialog dialog;
@@ -42,7 +44,7 @@ public static NewBlockValidator getInstance(final NewBlockDialog dialog) {
4244
/**
4345
* New block validator constructor.
4446
*/
45-
private NewBlockValidator() {
47+
public NewBlockValidator() {
4648
this.validatorBundle = new ValidatorBundle();
4749
this.commonBundle = new CommonBundle();
4850
}
@@ -59,7 +61,7 @@ public boolean validate() {
5961
if (!PhpNameUtil.isValidClassName(moduleName)) {
6062
final String errorMessage = this.validatorBundle.message(
6163
"validator.class.isNotValid",
62-
"Block Name"
64+
BLOCK_NAME
6365
);
6466
JOptionPane.showMessageDialog(
6567
null,
@@ -74,7 +76,7 @@ public boolean validate() {
7476
if (moduleName.length() == 0) {
7577
final String errorMessage = validatorBundle.message(
7678
"validator.notEmpty",
77-
"Block Name"
79+
BLOCK_NAME
7880
);
7981
JOptionPane.showMessageDialog(
8082
null,
@@ -89,7 +91,7 @@ public boolean validate() {
8991
if (!moduleName.matches(RegExUtil.ALPHANUMERIC)) {
9092
final String errorMessage = validatorBundle.message(
9193
"validator.alphaNumericCharacters",
92-
"Block Name"
94+
BLOCK_NAME
9395
);
9496
JOptionPane.showMessageDialog(
9597
null,
@@ -106,7 +108,7 @@ public boolean validate() {
106108
) {
107109
final String errorMessage = validatorBundle.message(
108110
"validator.startWithNumberOrCapitalLetter",
109-
"Block Name"
111+
BLOCK_NAME
110112
);
111113
JOptionPane.showMessageDialog(
112114
null,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"PMD.OnlyOneReturn",
1717
"PMD.FieldNamingConventions",
1818
"PMD.DataflowAnomalyAnalysis",
19+
"PMD.NonThreadSafeSingleton",
1920
"PMD.NPathComplexity"
2021
})
2122
public class NewControllerValidator {
2223
private static final String ACTION_NAME = "Action Name";
23-
private static NewControllerValidator INSTANCE = null;
24+
private static NewControllerValidator INSTANCE;
2425
private final ValidatorBundle validatorBundle;
2526
private final CommonBundle commonBundle;
2627
private NewControllerDialog dialog;
@@ -32,7 +33,7 @@ public class NewControllerValidator {
3233
*
3334
* @return NewControllerValidator
3435
*/
35-
public static NewControllerValidator getInstance(NewControllerDialog dialog) {
36+
public static NewControllerValidator getInstance(final NewControllerDialog dialog) {
3637
if (null == INSTANCE) {
3738
INSTANCE = new NewControllerValidator();
3839
}
@@ -44,7 +45,7 @@ public static NewControllerValidator getInstance(NewControllerDialog dialog) {
4445
/**
4546
* New controller validator constructor.
4647
*/
47-
private NewControllerValidator() {
48+
public NewControllerValidator() {
4849
this.validatorBundle = new ValidatorBundle();
4950
this.commonBundle = new CommonBundle();
5051
}
@@ -120,7 +121,7 @@ public boolean validate() {
120121
return false;
121122
}
122123

123-
String controllerName = dialog.getControllerName();
124+
final String controllerName = dialog.getControllerName();
124125

125126
if (!PhpNameUtil.isValidNamespaceName(controllerName)) {
126127
final String errorMessage = this.validatorBundle.message(

0 commit comments

Comments
 (0)