@@ -90,29 +90,12 @@ public static List<String> getInjectionService(@NotNull Project project, @NotNul
9090 );
9191 }
9292
93- HashSet <String > objects = new HashSet <>();
93+ HashSet <String > classes = new HashSet <>();
9494
95- objects .addAll (PhpIndex .getInstance (project ).getAllClassFqns (PrefixMatcher . ALWAYS_TRUE ));
96- objects .addAll (PhpIndex .getInstance (project ).getAllInterfacesFqns (PrefixMatcher . ALWAYS_TRUE ));
95+ classes .addAll (PhpIndex .getInstance (project ).getAllClassFqns (NonGarbageClassPrefixMatcher . INSTANCE ));
96+ classes .addAll (PhpIndex .getInstance (project ).getAllInterfacesFqns (NonGarbageClassPrefixMatcher . INSTANCE ));
9797
98- Set <String > collect = objects .stream ().filter (s -> {
99- int i = s .lastIndexOf ("\\ " );
100- if (i > 0 ) {
101- if (s .toLowerCase ().contains ("\\ test\\ " )) {
102- return false ;
103- }
104-
105- s = s .substring (i );
106- }
107-
108- return !s .endsWith ("Test" )
109- && !s .toLowerCase ().contains ("_phpstan_" )
110- && !s .toLowerCase ().contains ("ecsprefix" )
111- && !s .toLowerCase ().contains ("_humbugbox" )
112- && !s .toLowerCase ().contains ("rectorprefix" );
113- }).collect (Collectors .toSet ());
114-
115- for (String fqn : collect ) {
98+ for (String fqn : classes ) {
11699 // Bar\Foo => Foo
117100 int i = fqn .lastIndexOf ("\\ " );
118101 String classPropertyNameRaw = i > 0
@@ -177,6 +160,37 @@ public static List<String> getInjectionService(@NotNull Project project, @NotNul
177160 .collect (Collectors .toList ());
178161 }
179162
163+ /**
164+ * Filter some invalid classes fqn
165+ * - RectorPrefix2...
166+ * - _PHPStan_f12ae...
167+ */
168+ private static class NonGarbageClassPrefixMatcher extends PrefixMatcher {
169+ private static final NonGarbageClassPrefixMatcher INSTANCE = new NonGarbageClassPrefixMatcher ();
170+
171+ private NonGarbageClassPrefixMatcher () {
172+ super ("" );
173+ }
174+
175+ @ Override
176+ public boolean prefixMatches (@ NotNull String fqn ) {
177+ if (fqn .contains ("\\ " ) && fqn .toLowerCase ().contains ("\\ test\\ " )) {
178+ return false ;
179+ }
180+
181+ return !fqn .endsWith ("Test" )
182+ && !fqn .toLowerCase ().contains ("_phpstan_" )
183+ && !fqn .toLowerCase ().contains ("ecsprefix" )
184+ && !fqn .toLowerCase ().contains ("_humbugbox" )
185+ && !fqn .toLowerCase ().contains ("rectorprefix" );
186+ }
187+
188+ @ Override
189+ public @ NotNull PrefixMatcher cloneWithPrefix (@ NotNull String prefix ) {
190+ return new NonGarbageClassPrefixMatcher ();
191+ }
192+ }
193+
180194 private static class Match {
181195 private final String fqn ;
182196 private int weight = 0 ;
0 commit comments