@@ -191,6 +191,7 @@ public static function convertPHPtoJava($arguments, $defaultJavaArgumentType = '
191191 * @param string $b
192192 * @return bool
193193 * @throws TypeException
194+ * @throws \ReflectionException
194195 */
195196 public static function compare (string $ a , string $ b ): bool
196197 {
@@ -205,30 +206,31 @@ public static function compare(string $a, string $b): bool
205206 return false ;
206207 }
207208
208- $ resultComparison = [];
209+ $ resultClassesComparison = [];
210+ $ resultInterfacesComparison = [];
209211 for ($ i = 0 , $ size = count ($ a ); $ i < $ size ; $ i ++) {
210- $ resultComparison [] = count (array_intersect ($ a [$ i ], $ b [$ i ])) > 0 ;
212+ $ resultClassesComparison [] = count (array_intersect ($ a [$ i ][0 ], $ b [$ i ][0 ])) > 0 ;
213+ $ resultInterfacesComparison [] = count (array_intersect ($ a [$ i ][1 ], $ b [$ i ][1 ])) > 0 ;
211214 }
212215
213- return !in_array (
214- false ,
215- $ resultComparison ,
216- true
217- );
216+ return !in_array (false , $ resultClassesComparison , true ) ||
217+ !in_array (false , $ resultInterfacesComparison , true );
218218 }
219219
220220 /**
221221 * @param $class
222222 * @return array
223223 * @throws TypeException
224+ * @throws \ReflectionException
224225 */
225226 public static function getExtendedClasses ($ class ): array
226227 {
227228 static $ loadedExtendedRoots = [];
228229 $ result = [];
230+
229231 foreach (Formatter::parseSignature ($ class ) as $ signature ) {
230232 if ($ signature ['type ' ] !== 'class ' ) {
231- $ result [] = [$ signature ['type ' ]];
233+ $ result [] = [[ $ signature ['type ' ]], [ ]];
232234 continue ;
233235 }
234236 $ path = [];
@@ -249,15 +251,10 @@ public static function getExtendedClasses($class): array
249251 $ classPath
250252 );
251253
252- $ extendedClasses = [];
253- $ extendedClasses [] = $ rootClass = $ classPath ;
254- while (($ getRootClass = get_parent_class ($ rootClass )) !== false ) {
255- $ extendedClasses [] = $ rootClass = '\\' . $ getRootClass ;
256- }
257-
258- $ result [] = $ extendedClasses ;
259-
254+ $ extendedClasses = array_values (class_parents (ltrim ($ classPath , '\\' ), true ));
255+ $ interfaces = array_values (class_implements ($ classPath , true ));
260256 $ loadedExtendedRoots = $ extendedClasses ;
257+
261258 if (class_exists ($ classPath )) {
262259 $ reflectionClass = new \ReflectionClass ($ classPath );
263260 preg_match_all ('/\@parent\s+([^\r\n]+)/i ' , $ reflectionClass ->getDocComment (), $ parents );
@@ -266,22 +263,12 @@ public static function getExtendedClasses($class): array
266263 $ loadedExtendedRoots = $ roots ;
267264 }
268265 }
266+
267+ $ result [] = [$ extendedClasses , $ interfaces ];
269268 }
270269
271270 array_walk_recursive ($ result , function (&$ className ) {
272- $ newClassName = explode (
273- '. ' ,
274- str_replace (
275- [Runtime::PHP_IMITATION_DIRECTORY . '\\' , '\\' ],
276- ['' , '. ' ],
277- $ className
278- )
279- );
280- foreach ($ newClassName as $ key => $ value ) {
281- $ newClassName [$ key ] = array_flip (Runtime::PHP_IMITATION_MAPS )[$ value ] ?? $ value ;
282- }
283-
284- $ className = $ newClassName = implode ('. ' , $ newClassName );
271+ $ className = Formatter::convertPHPNamespacesToJava ($ className );
285272 });
286273
287274 return $ result ;
0 commit comments