@@ -46,30 +46,30 @@ public function createCompletion(
4646 ){
4747 $ start = microtime (1 );
4848 $ entries = [];
49- if ($ line ){
50- list ($ lines , $ badLine , $ completionLine ) = $ this ->prepareContent (
49+ if ($ line ) {
50+ list ($ lines , , $ completionLine ) = $ this ->prepareContent (
5151 $ content ,
5252 $ line ,
5353 $ column
5454 );
5555 try {
5656 $ scope = $ this ->processFileContent ($ project , $ lines , $ line , $ file );
57- if (empty ($ scope )){
57+ if (empty ($ scope )) {
5858 $ scope = new Scope ;
5959 }
60- $ this ->logger ->addDebug (sprintf (
61- "%s seconds for ast processing "
62- , (microtime (1 ) - $ start )));
63- }
64- catch (\Exception $ e ){
60+ $ this ->logger ->debug (sprintf (
61+ "%s seconds for ast processing " ,
62+ (microtime (1 ) - $ start )
63+ ));
64+ } catch (\Exception $ e ) {
6565 $ scope = new Scope ;
6666 }
67- $ entries = $ this ->findEntries ($ project , $ scope , $ completionLine , $ column, $ lines );
68- $ this ->logger ->addDebug (sprintf (
69- "%s seconds for entries generation "
70- , (microtime (1 ) - $ start )));
71- }
72- elseif (!empty ($ content )) {
67+ $ entries = $ this ->findEntries ($ project , $ scope , $ completionLine , $ column );
68+ $ this ->logger ->debug (sprintf (
69+ "%s seconds for entries generation " ,
70+ (microtime (1 ) - $ start )
71+ ));
72+ } elseif (!empty ($ content )) {
7373 $ this ->processFileContent ($ project , $ content , $ line , $ file );
7474 }
7575
@@ -78,7 +78,8 @@ public function createCompletion(
7878 "context " => []
7979 ];
8080 }
81- protected function findEntries (Project $ project , Scope $ scope , $ badLine , $ column , $ lines ){
81+ protected function findEntries (Project $ project , Scope $ scope , $ badLine , $ column )
82+ {
8283 $ context = $ this ->contextResolver ->getContext ($ badLine , $ project ->getIndex (), $ scope );
8384 $ completer = $ this ->completerFactory ->getCompleter ($ context , $ project );
8485 if ($ completer ) {
@@ -92,10 +93,9 @@ protected function findEntries(Project $project, Scope $scope, $badLine, $column
9293 */
9394 protected function prepareContent ($ content , $ line , $ column ){
9495 $ lines = explode (PHP_EOL , $ content );
95- if ($ line > count ($ lines )){
96+ if ($ line > count ($ lines )) {
9697 $ badLine = "" ;
97- }
98- else {
98+ } else {
9999 $ badLine = $ lines [$ line -1 ];
100100 }
101101 $ completionLine = substr ($ badLine , 0 , $ column -1 );
@@ -107,26 +107,21 @@ protected function prepareContent($content, $line, $column){
107107 * @return Scope
108108 */
109109 protected function processFileContent (Project $ project , $ lines , $ line , $ file ){
110- if (is_array ($ lines )){
110+ if (is_array ($ lines )) {
111111 $ content = implode ("\n" , $ lines );
112- }
113- else {
112+ } else {
114113 $ content = $ lines ;
115114 }
116- if (empty ($ content )){
115+ if (empty ($ content )) {
117116 return ;
118117 }
119- $ fqcn = $ project ->getIndex ()->findFQCNByFile ($ file );
120- if (!$ fqcn instanceof FQN ) {
121- $ fqcn = new FQN ();
122- }
123118 if (!array_key_exists ($ file , $ this ->cachePool )) {
124119 $ this ->cachePool [$ file ] = [0 , [], []];
125120 }
126- if ($ this ->isValidCache ($ file , $ content )){
127- list ($ hash , $ indexNodes , $ scopeNodes ) = $ this ->cachePool [$ file ];
121+ if ($ this ->isValidCache ($ file , $ content )) {
122+ list (, , $ scopeNodes ) = $ this ->cachePool [$ file ];
128123 }
129- if (empty ($ scopeNodes )) {
124+ if (empty ($ scopeNodes )) {
130125 $ this ->indexProcessor ->clearResultNodes ();
131126 $ parser = $ this ->parser ;
132127 $ parser ->addProcessor ($ this ->indexProcessor );
@@ -145,13 +140,14 @@ protected function processFileContent(Project $project, $lines, $line, $file){
145140 $ contentHash = hash ('sha1 ' , $ content );
146141 $ this ->cachePool [$ file ] = [$ contentHash , $ nodes , $ scopeNodes ];
147142 }
148- if (count ($ scopeNodes )){
143+ if (count ($ scopeNodes )) {
149144 return $ scopeNodes [0 ];
150145 }
151146 return null ;
152147 }
153148
154- private function isValidCache ($ file , $ content ){
149+ private function isValidCache ($ file , $ content )
150+ {
155151 $ contentHash = hash ('sha1 ' , $ content );
156152 list ($ hash ) = $ this ->cachePool [$ file ];
157153 return $ hash === $ contentHash ;
0 commit comments