@@ -150,9 +150,9 @@ public List<PluginData> getPluginsForClass(
150150 }
151151
152152 public List <PluginMethodData > getPluginMethods (final List <PluginData > pluginDataList ) {
153- List <PluginMethodData > result = new ArrayList <>();
153+ final List <PluginMethodData > result = new ArrayList <>();
154154
155- for (PluginData pluginData : pluginDataList ) {
155+ for (final PluginData pluginData : pluginDataList ) {
156156 for (final PhpClass plugin : pluginData .getPhpClassCollection ()) {
157157 //@todo add module sequence ID if sortOrder equal zero. It should be negative value.
158158 result .addAll (getPluginMethods (plugin , pluginData .getSortOrder ()));
@@ -162,7 +162,7 @@ public List<PluginMethodData> getPluginMethods(final List<PluginData> pluginData
162162 return result ;
163163 }
164164
165- public List <PluginMethodData > getPluginMethods (final @ NotNull PhpClass pluginClass , int sortOrder ) {
165+ public List <PluginMethodData > getPluginMethods (final @ NotNull PhpClass pluginClass , final int sortOrder ) {
166166 final List <PluginMethodData > methodList = new ArrayList <>();
167167
168168 for (final Method method : pluginClass .getMethods ()) {
@@ -171,13 +171,18 @@ public List<PluginMethodData> getPluginMethods(final @NotNull PhpClass pluginCla
171171
172172 if (pluginMethodName .length () > MIN_PLUGIN_METHOD_NAME_LENGTH ) {
173173 //@todo module sequence value should be set here instead of zero.
174- methodList .add (new PluginMethodData (method , sortOrder , 0 ));
174+ methodList .add (getPluginMethodDataObject (method , sortOrder , 0 ));
175175 }
176176 }
177177 }
178178
179179 return methodList ;
180180 }
181+
182+ @ NotNull
183+ private PluginMethodData getPluginMethodDataObject (final Method method , final int sortOrder , final int moduleSequence ) {
184+ return new PluginMethodData (method , sortOrder , moduleSequence );
185+ }
181186 }
182187
183188 private static class ClassPluginCollector implements Collector <PhpClass , PhpClass > {
@@ -192,10 +197,10 @@ public ClassPluginCollector(
192197
193198 @ Override
194199 public List <PhpClass > collect (final @ NotNull PhpClass psiElement ) {
195- List <PluginData > pluginDataList = pluginClassCache .getPluginsForClass (psiElement );
196- List <PhpClass > phpClassList = new ArrayList <>();
200+ final List <PluginData > pluginDataList = pluginClassCache .getPluginsForClass (psiElement );
201+ final List <PhpClass > phpClassList = new ArrayList <>();
197202
198- for (PluginData pluginData : pluginDataList ) {
203+ for (final PluginData pluginData : pluginDataList ) {
199204 phpClassList .addAll (pluginData .getPhpClassCollection ());
200205 }
201206
@@ -207,6 +212,7 @@ private static class MethodPluginCollector implements Collector<Method, Method>
207212
208213 private final PluginLineMarkerProvider .PluginClassCache pluginClassCache ;
209214 private final Map <String , Integer > pluginMethodsSortOrder ;
215+ private static final String AFTER_PLUGIN_PREFIX = "after" ;
210216
211217 public MethodPluginCollector (
212218 final PluginLineMarkerProvider .PluginClassCache pluginClassCache
@@ -215,7 +221,7 @@ public MethodPluginCollector(
215221 pluginMethodsSortOrder = new HashMap <>();
216222 pluginMethodsSortOrder .put ("before" , 1 );
217223 pluginMethodsSortOrder .put ("around" , 2 );
218- pluginMethodsSortOrder .put ("after" , 3 );
224+ pluginMethodsSortOrder .put (AFTER_PLUGIN_PREFIX , 3 );
219225 }
220226
221227 @ SuppressWarnings ("checkstyle:LineLength" )
@@ -238,13 +244,13 @@ public List<Method> collect(final @NotNull Method psiElement) {
238244 return results ;
239245 }
240246
241- @ SuppressWarnings ({"checkstyle:Indentation" , "checkstyle:OperatorWrap" , "checkstyle:LineLength" })
242- private void sortMethods (final @ NotNull List <PluginMethodData > methodDataList , List <Method > results ) {
243- List <Integer > bufferSortOrderList = new ArrayList <>();
247+ @ SuppressWarnings ({"checkstyle:Indentation" , "checkstyle:OperatorWrap" , "checkstyle:LineLength" , "PMD.NPathComplexity" })
248+ private void sortMethods (final @ NotNull List <PluginMethodData > methodDataList , final List <Method > results ) {
249+ final List <Integer > bufferSortOrderList = new ArrayList <>();
244250 int biggestSortOrder = 0 ;
245251
246- for (PluginMethodData pluginMethodData : methodDataList ) {
247- String methodName = pluginMethodData .getMethodName ();
252+ for (final PluginMethodData pluginMethodData : methodDataList ) {
253+ final String methodName = pluginMethodData .getMethodName ();
248254
249255 if (methodName .startsWith ("around" )) {
250256 bufferSortOrderList .add (pluginMethodData .getSortOrder ());
@@ -261,10 +267,10 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
261267 (PluginMethodData method1 , PluginMethodData method2 ) -> {
262268 final String firstMethodName = method1 .getMethodName ();
263269 final String secondMethodName = method2 .getMethodName ();
264- final int firstIndexEnd = firstMethodName .startsWith ("after" ) ? 5 : 6 ;
265- final int secondIndexEnd = secondMethodName .startsWith ("after" ) ? 5 : 6 ;
266- String firstMethodPrefix = firstMethodName .substring (0 ,firstIndexEnd );
267- String secondMethodPrefix = secondMethodName .substring (0 ,secondIndexEnd );
270+ final int firstIndexEnd = firstMethodName .startsWith (AFTER_PLUGIN_PREFIX ) ? 5 : 6 ;
271+ final int secondIndexEnd = secondMethodName .startsWith (AFTER_PLUGIN_PREFIX ) ? 5 : 6 ;
272+ final String firstMethodPrefix = firstMethodName .substring (0 ,firstIndexEnd );
273+ final String secondMethodPrefix = secondMethodName .substring (0 ,secondIndexEnd );
268274
269275 if (!pluginMethodsSortOrder .containsKey (firstMethodPrefix )
270276 || !pluginMethodsSortOrder .containsKey (secondMethodPrefix )) {
@@ -280,17 +286,17 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
280286
281287 Integer firstBuffer = 0 ;
282288 Integer secondBuffer = 0 ;
283- Integer firstModuleSequence = (method1 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
284- Integer secondModuleSequence = (method2 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
285- Integer firstSortOrder = method1 .getSortOrder () ! = 0 ?
286- method1 . getSortOrder () :
287- firstModuleSequence ;
288- Integer secondSortOrder = method2 .getSortOrder () ! = 0 ?
289- method2 . getSortOrder () :
290- secondModuleSequence ;
291-
292- if (!bufferSortOrderList .isEmpty () && firstMethodPrefix .equals ("after" )) {
293- for (Integer bufferSortOrder : bufferSortOrderList ) {
289+ final Integer firstModuleSequence = (method1 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
290+ final Integer secondModuleSequence = (method2 .getModuleSequence () + biggestSortOrderValue ) * -1 ;
291+ final Integer firstSortOrder = method1 .getSortOrder () = = 0 ?
292+ firstModuleSequence :
293+ method1 . getSortOrder () ;
294+ final Integer secondSortOrder = method2 .getSortOrder () = = 0 ?
295+ secondModuleSequence :
296+ method2 . getSortOrder () ;
297+
298+ if (!bufferSortOrderList .isEmpty () && firstMethodPrefix .equals (AFTER_PLUGIN_PREFIX )) {
299+ for (final Integer bufferSortOrder : bufferSortOrderList ) {
294300 if (bufferSortOrder < firstSortOrder && firstBuffer < bufferSortOrder + 1 ) {
295301 firstBuffer = bufferSortOrder + 1 ;
296302 }
@@ -316,7 +322,7 @@ private void sortMethods(final @NotNull List<PluginMethodData> methodDataList, L
316322 }
317323 );
318324
319- for (PluginMethodData pluginMethodData : methodDataList ) {
325+ for (final PluginMethodData pluginMethodData : methodDataList ) {
320326 results .add (pluginMethodData .getMethod ());
321327 }
322328 }
0 commit comments