@@ -110,6 +110,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
110110
111111 $ preserveParenthesises = $ countParamTokens > 1 ;
112112
113+ $ afterCloseParenthesisIndex = $ tokens ->getNextMeaningfulToken ($ closeParenthesis );
114+ $ afterCloseParenthesisToken = $ tokens [$ afterCloseParenthesisIndex ];
115+ $ wrapInParenthesises = $ afterCloseParenthesisToken ->equals ('[ ' ) || $ afterCloseParenthesisToken ->isGivenKind (T_POW );
116+
113117 // analyse namespace specification (root one or none) and decide what to do
114118 $ prevTokenIndex = $ tokens ->getPrevMeaningfulToken ($ functionName );
115119 if ($ tokens [$ prevTokenIndex ]->isGivenKind (T_NS_SEPARATOR )) {
@@ -123,6 +127,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
123127 new Token ($ newToken ),
124128 new Token ([T_WHITESPACE , ' ' ]),
125129 ];
130+ if ($ wrapInParenthesises ) {
131+ array_unshift ($ replacementSequence , new Token ('( ' ));
132+ }
126133
127134 if (!$ preserveParenthesises ) {
128135 // closing parenthesis removed with leading spaces
@@ -138,6 +145,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
138145 $ tokens ->removeTrailingWhitespace ($ functionName );
139146 }
140147
148+ if ($ wrapInParenthesises ) {
149+ $ tokens ->insertAt ($ closeParenthesis , new Token (') ' ));
150+ }
151+
141152 $ tokens ->overrideRange ($ functionName , $ functionName , $ replacementSequence );
142153
143154 // nested transformations support
0 commit comments