1111import com .intellij .openapi .fileTypes .FileTypes ;
1212import com .intellij .openapi .project .Project ;
1313import com .intellij .openapi .ui .ComboBox ;
14- import com .intellij .psi .PsiDirectory ;
1514import com .intellij .psi .PsiFile ;
1615import com .intellij .ui .EditorTextField ;
1716import com .jetbrains .php .PhpIndex ;
3433import com .magento .idea .magento2plugin .magento .packages .Areas ;
3534import com .magento .idea .magento2plugin .magento .packages .DiArgumentType ;
3635import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
37- import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
3836import java .awt .event .ActionListener ;
3937import java .awt .event .KeyEvent ;
4038import java .awt .event .WindowAdapter ;
5452import org .jetbrains .annotations .NonNls ;
5553import org .jetbrains .annotations .NotNull ;
5654
55+ @ SuppressWarnings ({
56+ "PMD.TooManyFields" ,
57+ "PMD.UnusedPrivateField" ,
58+ "PMD.ExcessiveImports" ,
59+ "PMD.AvoidInstantiatingObjectsInLoops"
60+ })
5761public class NewArgumentInjectionDialog extends AbstractDialog {
5862
5963 private static final String TARGET_AREA = "Target Area" ;
@@ -64,9 +68,7 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
6468 private static final String CONST_VALUE = "Target Constant" ;
6569
6670 private final @ NotNull Project project ;
67- private final String moduleName ;
6871 private final PhpClass targetClass ;
69- private final Parameter targetParameter ;
7072
7173 private JPanel contentPane ;
7274 private JButton buttonCancel ;
@@ -130,7 +132,7 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
130132 private JButton addArrayValueBtn ;
131133 private JTextArea arrayView ;
132134
133- final DiArrayValueData arrayValues ;
135+ private final DiArrayValueData arrayValues ;
134136
135137 // labels
136138 private JLabel argumentTypeLabel ;//NOPMD
@@ -152,22 +154,24 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
152154 * New argument injection dialog constructor.
153155 *
154156 * @param project Project
155- * @param directory PsiDirectory
156157 * @param targetClass PhpClass
157158 * @param parameter Parameter
158159 */
160+ @ SuppressWarnings ({
161+ "PMD.AccessorMethodGeneration" ,
162+ "PMD.ExcessiveMethodLength" ,
163+ "PMD.CognitiveComplexity" ,
164+ "PMD.CyclomaticComplexity" ,
165+ })
159166 public NewArgumentInjectionDialog (
160167 final @ NotNull Project project ,
161- final @ NotNull PsiDirectory directory ,
162168 final @ NotNull PhpClass targetClass ,
163169 final @ NotNull Parameter parameter
164170 ) {
165171 super ();
166172
167173 this .project = project ;
168174 this .targetClass = targetClass ;
169- this .targetParameter = parameter ;
170- this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
171175 arrayValues = new DiArrayValueData ();
172176
173177 setContentPane (contentPane );
@@ -197,7 +201,7 @@ public void windowClosing(final WindowEvent event) {
197201 addComponentListener (new FocusOnAFieldListener (() -> targetModule .requestFocusInWindow ()));
198202
199203 targetClassField .setText (targetClass .getPresentableFQN ());
200- targetArgument .setText (targetParameter .getName ());
204+ targetArgument .setText (parameter .getName ());
201205
202206 // make all value panes invisible
203207 objectValuePane .setVisible (false );
@@ -335,18 +339,16 @@ public void documentChanged(final @NotNull DocumentEvent event) {
335339 * Open a new argument injection dialog.
336340 *
337341 * @param project Project
338- * @param directory PsiDirectory
339342 * @param targetClass PhpClass
340343 * @param parameter Parameter
341344 */
342345 public static void open (
343346 final @ NotNull Project project ,
344- final @ NotNull PsiDirectory directory ,
345347 final @ NotNull PhpClass targetClass ,
346348 final @ NotNull Parameter parameter
347349 ) {
348350 final NewArgumentInjectionDialog dialog =
349- new NewArgumentInjectionDialog (project , directory , targetClass , parameter );
351+ new NewArgumentInjectionDialog (project , targetClass , parameter );
350352 dialog .pack ();
351353 dialog .centerDialog (dialog );
352354 dialog .setVisible (true );
@@ -397,7 +399,7 @@ private void onOK() {
397399 /**
398400 * Create custom components and fill their entries.
399401 */
400- @ SuppressWarnings ({"PMD.UnusedPrivateMethod" , "PMD.AvoidInstantiatingObjectsInLoops" })
402+ @ SuppressWarnings ({"PMD.UnusedPrivateMethod" })
401403 private void createUIComponents () {
402404 targetModule = new FilteredComboBox (new ModuleIndex (project ).getEditableModuleNames ());
403405 targetArea = new ComboBox <>();
@@ -425,9 +427,10 @@ private void createUIComponents() {
425427 booleanValue .addItem (new ComboBoxItemData ("" , " --- Select Value --- " ));
426428 booleanValue .addItem (new ComboBoxItemData ("false" , "False" ));
427429 booleanValue .addItem (new ComboBoxItemData ("true" , "True" ));
430+ final String selectConstantText = " --- Select Constant --- " ;
428431
429- initParameterConstValue .addItem (new ComboBoxItemData ("" , " --- Select Constant --- " ));
430- constantValue .addItem (new ComboBoxItemData ("" , " --- Select Constant --- " ));
432+ initParameterConstValue .addItem (new ComboBoxItemData ("" , selectConstantText ));
433+ constantValue .addItem (new ComboBoxItemData ("" , selectConstantText ));
431434
432435 initParameterTypeValue = new EditorTextField ("" , project , FileTypes .PLAIN_TEXT );
433436 constantTypeValue = new EditorTextField ("" , project , FileTypes .PLAIN_TEXT );
@@ -479,7 +482,7 @@ private List<String> getConstantsNames(final @NotNull String fqn) {
479482 final Collection <PhpClass > classes = phpIndex .getClassesByFQN (fqn );
480483 PhpClass clazz = null ;
481484
482- if (!interfaces .isEmpty ()) {
485+ if (!interfaces .isEmpty ()) { // NOPMD
483486 clazz = interfaces .iterator ().next ();
484487 } else if (!classes .isEmpty ()) {
485488 clazz = classes .iterator ().next ();
@@ -509,7 +512,7 @@ private void populateSubArrayKeyCombobox() {
509512 subArrayKey .addItem (new ComboBoxItemData ("" , " --- Top Array --- " ));
510513 populateSubArrayKeyCombobox (arrayValues , "" );
511514
512- if (subArrayKey .getItemCount () > 1 ) {
515+ if (subArrayKey .getItemCount () > 1 ) { // NOPMD
513516 subArrayKeyLabel .setVisible (true );
514517 subArrayKey .setVisible (true );
515518 }
@@ -564,6 +567,7 @@ private void changeViewBySelectedArgumentType(final String itemValue) {
564567 }
565568 }
566569
570+ @ SuppressWarnings ({"PMD.CognitiveComplexity" , "PMD.CyclomaticComplexity" })
567571 private @ NotNull String getArgumentValue () {
568572 final ComboBoxItemData item = (ComboBoxItemData ) argumentType .getSelectedItem ();
569573
0 commit comments