@@ -94,28 +94,19 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
9494 continue ;
9595 }
9696
97- $ firstIndex = $ tokens ->getPrevMeaningfulToken ($ index );
98- \assert (\is_int ($ firstIndex ));
99-
100- if (!$ tokens [$ firstIndex ]->isGivenKind (\T_CONSTANT_ENCAPSED_STRING )) {
101- continue ;
102- }
103- if (!$ this ->areOnlyHorizontalWhitespacesBetween ($ tokens , $ firstIndex , $ index )) {
97+ $ firstIndex = $ this ->getFirstIndex ($ tokens , $ index );
98+ if ($ firstIndex === null ) {
10499 continue ;
105100 }
106101
107- $ secondIndex = $ tokens ->getNextMeaningfulToken ($ index );
108- \assert (\is_int ($ secondIndex ));
109-
110- if (!$ tokens [$ secondIndex ]->isGivenKind (\T_CONSTANT_ENCAPSED_STRING )) {
111- continue ;
112- }
113- if (!$ this ->areOnlyHorizontalWhitespacesBetween ($ tokens , $ index , $ secondIndex )) {
102+ $ secondIndex = $ this ->getSecondIndex ($ tokens , $ index );
103+ if ($ secondIndex === null ) {
114104 continue ;
115105 }
106+
116107 if (
117108 $ this ->keepConcatenationForDifferentQuotes
118- && substr ($ tokens [$ firstIndex ]->getContent (), 0 , 1 ) !== substr ($ tokens [$ secondIndex ]->getContent (), 0 , 1 )
109+ && \ substr ($ tokens [$ firstIndex ]->getContent (), 0 , 1 ) !== \ substr ($ tokens [$ secondIndex ]->getContent (), 0 , 1 )
119110 ) {
120111 continue ;
121112 }
@@ -124,6 +115,36 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
124115 }
125116 }
126117
118+ private function getFirstIndex (Tokens $ tokens , int $ index ): ?int
119+ {
120+ $ firstIndex = $ tokens ->getPrevMeaningfulToken ($ index );
121+ \assert (\is_int ($ firstIndex ));
122+
123+ if (!$ tokens [$ firstIndex ]->isGivenKind (\T_CONSTANT_ENCAPSED_STRING )) {
124+ return null ;
125+ }
126+ if (!$ this ->areOnlyHorizontalWhitespacesBetween ($ tokens , $ firstIndex , $ index )) {
127+ return null ;
128+ }
129+
130+ return $ firstIndex ;
131+ }
132+
133+ private function getSecondIndex (Tokens $ tokens , int $ index ): ?int
134+ {
135+ $ secondIndex = $ tokens ->getNextMeaningfulToken ($ index );
136+ \assert (\is_int ($ secondIndex ));
137+
138+ if (!$ tokens [$ secondIndex ]->isGivenKind (\T_CONSTANT_ENCAPSED_STRING )) {
139+ return null ;
140+ }
141+ if (!$ this ->areOnlyHorizontalWhitespacesBetween ($ tokens , $ index , $ secondIndex )) {
142+ return null ;
143+ }
144+
145+ return $ secondIndex ;
146+ }
147+
127148 private function areOnlyHorizontalWhitespacesBetween (Tokens $ tokens , int $ indexStart , int $ indexEnd ): bool
128149 {
129150 for ($ index = $ indexStart + 1 ; $ index < $ indexEnd ; $ index ++) {
0 commit comments