This repository was archived by the owner on Jul 12, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
src/main/QafooLabs/Refactoring/Application Expand file tree Collapse file tree 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)
3737 $ occurances = $ this ->phpNameScanner ->findNames ($ file );
3838 $ class = $ classes [0 ];
3939
40+ $ appendNewLine = 0 === $ class ->namespaceDeclarationLine ();
4041 $ lastUseStatementLine = $ class ->namespaceDeclarationLine () + 2 ;
4142 $ usedNames = array ();
4243 $ fqcns = array ();
4344
4445 foreach ($ occurances as $ occurance ) {
4546 $ name = $ occurance ->name ();
4647
47- if ($ name ->type () === PhpName::TYPE_NAMESPACE ) {
48+ if ($ name ->type () === PhpName::TYPE_NAMESPACE || $ name -> type () === PhpName:: TYPE_CLASS ) {
4849 continue ;
4950 }
5051
@@ -67,7 +68,13 @@ public function refactor(File $file)
6768 $ buffer ->replaceString ($ occurance ->declarationLine (), '\\' .$ name ->fullyQualifiedName (), $ name ->shortname ());
6869
6970 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 );
7178 $ lastUseStatementLine ++;
7279 }
7380 }
You can’t perform that action at this time.
0 commit comments