Skip to content

Commit 9063ab1

Browse files
committed
Support for PHP-CS-Fixer 2.0 #22
1 parent 1bad4a7 commit 9063ab1

File tree

13 files changed

+397
-104
lines changed

13 files changed

+397
-104
lines changed

nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
javac.source=1.6
1+
javac.source=1.8
22
javac.compilerargs=-Xlint -Xlint:-serial
33
license.file=license.txt
44
nbm.homepage=https://bitbucket.org/junichi11/netbeans-php-cs-fixer

src/org/netbeans/modules/php/phpcsfixer/commands/PhpCsFixer.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ public final class PhpCsFixer {
7373
private static final String SELF_UPDATE_COMMAND = "self-update"; // NOI18N
7474
//parameters
7575
public static final String DRY_RUN_PARAM = "--dry-run"; // NOI18N
76+
// 1.x
7677
public static final String CONFIG_PARAM = "--config=%s"; // NOI18N
7778
public static final String LEVEL_PARAM = "--level=%s"; // NOI18N
7879
public static final String FIXERS_PARAM = "--fixers=%s"; // NOI18N
80+
// 2.x
81+
public static final String RULES_PARAM = "--rules=%s"; // NOI18N
7982
private static final List<String> DEFAULT_PARAMS = Arrays.asList(
8083
"--ansi", // NOI18N
8184
"--no-interaction"); // NOI18N
@@ -107,7 +110,7 @@ public Future<Integer> fix(PhpModule phpModule, String... params) {
107110
}
108111

109112
public Future<Integer> fixDryRun(PhpModule phpModule, String... params) {
110-
List<String> allParams = new ArrayList<String>(params.length + 1);
113+
List<String> allParams = new ArrayList<>(params.length + 1);
111114
allParams.addAll(Arrays.asList(params));
112115
allParams.add(DRY_RUN_PARAM);
113116
return runCommand(phpModule, FIX_COMMAND, Bundle.PhpCsFixer_run(FIX_COMMAND + " " + DRY_RUN_PARAM), allParams);
@@ -132,7 +135,7 @@ private Future<Integer> runCommand(PhpModule phpModule, String command, String t
132135
}
133136

134137
private List<String> mergeParameters(String command, List<String> defaultParams, List<String> params) {
135-
List<String> allParams = new ArrayList<String>(defaultParams.size() + params.size() + 1);
138+
List<String> allParams = new ArrayList<>(defaultParams.size() + params.size() + 1);
136139
allParams.add(command);
137140
allParams.addAll(params);
138141
allParams.addAll(defaultParams);
@@ -160,13 +163,9 @@ private ExecutionDescriptor getDescriptor(PhpModule phpModule) {
160163
if (phpModule != null) {
161164
final FileObject sourceDirectory = phpModule.getSourceDirectory();
162165
if (sourceDirectory != null) {
163-
descriptor = descriptor
164-
.postExecution(new Runnable() {
165-
@Override
166-
public void run() {
167-
// refresh sources after running command
168-
sourceDirectory.refresh();
169-
}
166+
descriptor = descriptor.postExecution(() -> {
167+
// refresh sources after running command
168+
sourceDirectory.refresh();
170169
});
171170
}
172171
}

src/org/netbeans/modules/php/phpcsfixer/options/Bundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ PhpCsFixerPanel.downloadButton.text=Download...
1313
PhpCsFixerOptionsPanel.verboseCheckBox.text=--verbose
1414
PhpCsFixerOptionsPanel.diffCheckBox.text=--diff
1515
PhpCsFixerOptionsPanel.dryRunLabel.text=--dry-run
16+
PhpCsFixerOptionsPanel.versionLabel.text=Version:
17+
PhpCsFixerOptionsPanel.rulesCheckBox.text=--rules=
18+
PhpCsFixerOptionsPanel.rulesTextField.text=

src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptions.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public final class PhpCsFixerOptions {
5959
private static final PhpCsFixerOptions INSTANCE = new PhpCsFixerOptions();
6060
private static final String PREFERENCES_PATH = "php-cs-fixer"; // NOI18N
6161
private static final String PHP_CS_FIXER_PATH = "php-cs-fixer.path"; // NOI18N
62+
private static final String PHP_CS_FIXER_VERSION = "php-cs-fixer.version"; // NOI18N
6263
private static final String RUN_ON_SAVE = "run.on.save"; // NOI18N
6364
// php-cs-fixer options
6465
private static final String USE_LEVEL = "use.level"; // NOI18N
@@ -67,12 +68,18 @@ public final class PhpCsFixerOptions {
6768
private static final String CONFIG = "config"; // NOI18N
6869
private static final String USE_FIXERS = "use.fixers"; // NOI18N
6970
private static final String FIXERS = "fixers"; // NOI18N
71+
// 2.x
72+
private static final String USE_RULES = "use.rules"; // NOI18N
73+
private static final String RULES = "rules"; // NOI18N
74+
// common
7075
private static final String USE_CUSTOM = "use.custom"; // NOI18N
7176
private static final String CUSTOM = "custom"; // NOI18N
7277
private static final String VERBOSE = "verbose"; // NOI18N
7378
private static final String DIFF = "diff"; // NOI18N
7479
private volatile boolean phpcsfixerSearched = false;
7580

81+
public static final int LATEST_VERSION = 2;
82+
7683
private PhpCsFixerOptions() {
7784
}
7885

@@ -107,6 +114,19 @@ public void setPhpCsFixerPath(String path) {
107114
getPreferences().put(PHP_CS_FIXER_PATH, path);
108115
}
109116

117+
public int getVersion() {
118+
int version = getPreferences().getInt(PHP_CS_FIXER_VERSION, 1);
119+
if (version <= 0 || LATEST_VERSION < version) {
120+
version = LATEST_VERSION;
121+
}
122+
return version;
123+
}
124+
125+
public void setVersion(int version) {
126+
getPreferences().putInt(PHP_CS_FIXER_VERSION, version);
127+
}
128+
129+
// version 1.x
110130
public boolean useLevel() {
111131
return getPreferences().getBoolean(USE_LEVEL, false);
112132
}
@@ -155,6 +175,24 @@ public void setFixers(String fixers) {
155175
getPreferences().put(FIXERS, fixers);
156176
}
157177

178+
// 2.x
179+
public boolean useRules() {
180+
return getPreferences().getBoolean(USE_RULES, false);
181+
}
182+
183+
public void setRules(boolean use) {
184+
getPreferences().putBoolean(USE_RULES, use);
185+
}
186+
187+
public String getRules() {
188+
return getPreferences().get(RULES, ""); // NOI18N
189+
}
190+
191+
public void setRules(String rules) {
192+
getPreferences().put(RULES, rules);
193+
}
194+
195+
// common
158196
public boolean useCustom() {
159197
return getPreferences().getBoolean(USE_CUSTOM, false);
160198
}
@@ -196,15 +234,21 @@ public void setDiff(boolean isDiff) {
196234
}
197235

198236
public List<String> getAllOptions() {
199-
List<String> all = new ArrayList<String>();
200-
if (useLevel() && !getLevel().isEmpty()) {
201-
all.add(String.format(PhpCsFixer.LEVEL_PARAM, getLevel()));
202-
}
203-
if (useConfig() && !getConfig().isEmpty()) {
204-
all.add(String.format(PhpCsFixer.CONFIG_PARAM, getConfig()));
205-
}
206-
if (useFixers() && !getFixers().isEmpty()) {
207-
all.add(String.format(PhpCsFixer.FIXERS_PARAM, getFixers()));
237+
List<String> all = new ArrayList<>();
238+
if (getVersion() == 2) {
239+
if (useRules() && !getRules().isEmpty()) {
240+
all.add(String.format(PhpCsFixer.RULES_PARAM, getRules()));
241+
}
242+
} else {
243+
if (useLevel() && !getLevel().isEmpty()) {
244+
all.add(String.format(PhpCsFixer.LEVEL_PARAM, getLevel()));
245+
}
246+
if (useConfig() && !getConfig().isEmpty()) {
247+
all.add(String.format(PhpCsFixer.CONFIG_PARAM, getConfig()));
248+
}
249+
if (useFixers() && !getFixers().isEmpty()) {
250+
all.add(String.format(PhpCsFixer.FIXERS_PARAM, getFixers()));
251+
}
208252
}
209253
if (useCustom() && !getCustom().isEmpty()) {
210254
all.add(getCustom());

src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptionsPanel.form

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,46 @@
1919
<Group type="102" attributes="0">
2020
<EmptySpace max="-2" attributes="0"/>
2121
<Group type="103" groupAlignment="0" attributes="0">
22+
<Group type="102" alignment="0" attributes="0">
23+
<Component id="dryRunLabel" min="-2" max="-2" attributes="0"/>
24+
<EmptySpace max="-2" attributes="0"/>
25+
<Component id="dryRunSeparator" max="32767" attributes="0"/>
26+
</Group>
27+
<Group type="102" attributes="0">
28+
<Group type="103" groupAlignment="0" attributes="0">
29+
<Component id="runOnSaveCheckBox" min="-2" max="-2" attributes="0"/>
30+
<Group type="102" alignment="0" attributes="0">
31+
<Component id="verboseCheckBox" min="-2" max="-2" attributes="0"/>
32+
<EmptySpace max="-2" attributes="0"/>
33+
<Component id="diffCheckBox" min="-2" max="-2" attributes="0"/>
34+
</Group>
35+
</Group>
36+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
37+
</Group>
2238
<Group type="102" alignment="0" attributes="0">
2339
<Group type="103" groupAlignment="0" attributes="0">
2440
<Component id="levelCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
2541
<Component id="configCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
2642
<Component id="fixersCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
2743
<Component id="customCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
44+
<Component id="versionLabel" alignment="0" min="-2" max="-2" attributes="0"/>
45+
<Component id="rulesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
2846
</Group>
2947
<EmptySpace type="separate" max="-2" attributes="0"/>
3048
<Group type="103" groupAlignment="0" attributes="0">
3149
<Component id="fixersTextField" alignment="0" max="32767" attributes="0"/>
50+
<Component id="customTextField" alignment="0" max="32767" attributes="0"/>
3251
<Group type="102" attributes="0">
33-
<Group type="103" groupAlignment="0" attributes="0">
34-
<Component id="levelComboBox" alignment="0" min="-2" pref="140" max="-2" attributes="0"/>
52+
<Group type="103" groupAlignment="0" max="-2" attributes="0">
53+
<Component id="levelComboBox" alignment="0" max="32767" attributes="0"/>
3554
<Component id="configComboBox" alignment="0" min="-2" pref="140" max="-2" attributes="0"/>
55+
<Component id="versionComboBox" alignment="0" min="-2" max="-2" attributes="0"/>
3656
</Group>
3757
<EmptySpace min="0" pref="228" max="32767" attributes="0"/>
3858
</Group>
39-
<Component id="customTextField" alignment="0" max="32767" attributes="0"/>
59+
<Component id="rulesTextField" max="32767" attributes="0"/>
4060
</Group>
4161
</Group>
42-
<Group type="102" alignment="0" attributes="0">
43-
<Component id="dryRunLabel" min="-2" max="-2" attributes="0"/>
44-
<EmptySpace max="-2" attributes="0"/>
45-
<Component id="dryRunSeparator" max="32767" attributes="0"/>
46-
</Group>
47-
<Group type="102" attributes="0">
48-
<Group type="103" groupAlignment="0" attributes="0">
49-
<Component id="runOnSaveCheckBox" min="-2" max="-2" attributes="0"/>
50-
<Group type="102" alignment="0" attributes="0">
51-
<Component id="verboseCheckBox" min="-2" max="-2" attributes="0"/>
52-
<EmptySpace max="-2" attributes="0"/>
53-
<Component id="diffCheckBox" min="-2" max="-2" attributes="0"/>
54-
</Group>
55-
</Group>
56-
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
57-
</Group>
5862
</Group>
5963
<EmptySpace max="-2" attributes="0"/>
6064
</Group>
@@ -63,6 +67,11 @@
6367
<DimensionLayout dim="1">
6468
<Group type="103" groupAlignment="0" attributes="0">
6569
<Group type="102" alignment="0" attributes="0">
70+
<EmptySpace max="-2" attributes="0"/>
71+
<Group type="103" groupAlignment="3" attributes="0">
72+
<Component id="versionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
73+
<Component id="versionComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
74+
</Group>
6675
<EmptySpace max="-2" attributes="0"/>
6776
<Group type="103" groupAlignment="3" attributes="0">
6877
<Component id="levelComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -79,6 +88,11 @@
7988
<Component id="fixersTextField" alignment="3" min="-2" max="-2" attributes="0"/>
8089
</Group>
8190
<EmptySpace max="-2" attributes="0"/>
91+
<Group type="103" groupAlignment="3" attributes="0">
92+
<Component id="rulesCheckBox" alignment="3" min="-2" max="-2" attributes="0"/>
93+
<Component id="rulesTextField" alignment="3" min="-2" max="-2" attributes="0"/>
94+
</Group>
95+
<EmptySpace max="-2" attributes="0"/>
8296
<Group type="103" groupAlignment="3" attributes="0">
8397
<Component id="customCheckBox" alignment="3" min="-2" max="-2" attributes="0"/>
8498
<Component id="customTextField" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -194,5 +208,39 @@
194208
</Property>
195209
</Properties>
196210
</Component>
211+
<Component class="javax.swing.JLabel" name="versionLabel">
212+
<Properties>
213+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
214+
<ResourceString bundle="org/netbeans/modules/php/phpcsfixer/options/Bundle.properties" key="PhpCsFixerOptionsPanel.versionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
215+
</Property>
216+
</Properties>
217+
</Component>
218+
<Component class="javax.swing.JComboBox" name="versionComboBox">
219+
<Properties>
220+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
221+
<StringArray count="0"/>
222+
</Property>
223+
</Properties>
224+
<Events>
225+
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="versionComboBoxItemStateChanged"/>
226+
</Events>
227+
<AuxValues>
228+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;Integer&gt;"/>
229+
</AuxValues>
230+
</Component>
231+
<Component class="javax.swing.JCheckBox" name="rulesCheckBox">
232+
<Properties>
233+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
234+
<ResourceString bundle="org/netbeans/modules/php/phpcsfixer/options/Bundle.properties" key="PhpCsFixerOptionsPanel.rulesCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
235+
</Property>
236+
</Properties>
237+
</Component>
238+
<Component class="javax.swing.JTextField" name="rulesTextField">
239+
<Properties>
240+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
241+
<ResourceString bundle="org/netbeans/modules/php/phpcsfixer/options/Bundle.properties" key="PhpCsFixerOptionsPanel.rulesTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
242+
</Property>
243+
</Properties>
244+
</Component>
197245
</SubComponents>
198246
</Form>

0 commit comments

Comments
 (0)