This repository was archived by the owner on Jul 12, 2020. It is now read-only.
File tree 1 file changed +9
-2
lines changed
src/main/QafooLabs/Refactoring/Application
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,15 @@ public function refactor(File $file)
37
37
$ occurances = $ this ->phpNameScanner ->findNames ($ file );
38
38
$ class = $ classes [0 ];
39
39
40
+ $ appendNewLine = 0 === $ class ->namespaceDeclarationLine ();
40
41
$ lastUseStatementLine = $ class ->namespaceDeclarationLine () + 2 ;
41
42
$ usedNames = array ();
42
43
$ fqcns = array ();
43
44
44
45
foreach ($ occurances as $ occurance ) {
45
46
$ name = $ occurance ->name ();
46
47
47
- if ($ name ->type () === PhpName::TYPE_NAMESPACE ) {
48
+ if ($ name ->type () === PhpName::TYPE_NAMESPACE || $ name -> type () === PhpName:: TYPE_CLASS ) {
48
49
continue ;
49
50
}
50
51
@@ -67,7 +68,13 @@ public function refactor(File $file)
67
68
$ buffer ->replaceString ($ occurance ->declarationLine (), '\\' .$ name ->fullyQualifiedName (), $ name ->shortname ());
68
69
69
70
if (!in_array ($ name ->fullyQualifiedName (), $ usedNames )) {
70
- $ buffer ->append ($ lastUseStatementLine , array (sprintf ('use %s; ' , $ name ->fullyQualifiedName ())));
71
+ $ lines = array (sprintf ('use %s; ' , $ name ->fullyQualifiedName ()));
72
+ if ($ appendNewLine ) {
73
+ $ appendNewLine = FALSE ;
74
+ $ lines [] = '' ;
75
+ }
76
+
77
+ $ buffer ->append ($ lastUseStatementLine , $ lines );
71
78
$ lastUseStatementLine ++;
72
79
}
73
80
}
You can’t perform that action at this time.
0 commit comments