@@ -166,38 +166,51 @@ protected function getBounds(int $surroundingLine, int $totalNumberOfLineInFile)
166166
167167 protected function getBoundsMulti (int $ totalNumberOfLineInFile ): array
168168 {
169- $ firstLineNum = $ this ->surroundingLines [0 ];
170- $ lastLineNum = $ this ->surroundingLines [count ($ this ->surroundingLines ) - 1 ];
169+ $ startLine = $ this ->surroundingLines [0 ];
170+ $ endLine = $ this ->surroundingLines [count ($ this ->surroundingLines ) - 1 ];
171171
172+ // snippetLineCount() was used
172173 if (! is_int ($ this ->linesAfter ) || ! is_int ($ this ->linesBefore )) {
173- $ startBounds = $ this ->getBounds ($ firstLineNum , $ totalNumberOfLineInFile );
174- $ endBounds = $ this ->getBounds ($ lastLineNum , $ totalNumberOfLineInFile );
174+ [$ startLine , $ endLine ] = $ this ->getBoundsMultiForSnippetLineCount (
175+ $ startLine , $ endLine , $ totalNumberOfLineInFile
176+ );
177+ }
175178
176- $ bounds = array_merge ($ startBounds , $ endBounds );
177- sort ($ bounds , SORT_NUMERIC );
179+ // linesBefore() and linesAfter() were used
180+ if (is_int ($ this ->linesAfter ) && is_int ($ this ->linesBefore )) {
181+ $ startLine -= $ this ->linesBefore ;
182+ $ endLine += $ this ->linesAfter ;
178183
179- $ startLine = $ bounds [ 0 ] ;
180- $ endLine = $ bounds [ count ( $ bounds ) - 1 ];
184+ $ this -> updateSnippetLineCount ( $ startLine, $ endLine ) ;
185+ }
181186
182- [$ startLine , $ endLine ] = $ this ->ensureBoundsAreWithinLimits ($ startLine , $ endLine , $ totalNumberOfLineInFile );
183- [$ startLine , $ endLine ] = $ this ->trimSnippetSize ($ startLine , $ endLine );
187+ [$ startLine , $ endLine ] = $ this ->ensureBoundsAreWithinLimits ($ startLine , $ endLine , $ totalNumberOfLineInFile );
188+ [$ startLine , $ endLine ] = $ this ->trimSnippetSize ($ startLine , $ endLine );
184189
185- $ this ->snippetLineCount = ( $ endLine - $ startLine ) + 1 ;
190+ $ this ->updateSnippetLineCount ( $ startLine , $ endLine ) ;
186191
187- return [$ startLine , $ endLine ];
188- }
192+ return [$ startLine , $ endLine ];
193+ }
189194
190- $ startLine = $ firstLineNum - $ this ->linesBefore ;
191- $ endLine = $ lastLineNum + $ this ->linesAfter ;
195+ protected function getBoundsMultiForSnippetLineCount (int $ firstLineNum , int $ lastLineNum , int $ totalNumberOfLineInFile ): array
196+ {
197+ $ startBounds = $ this ->getBounds ($ firstLineNum , $ totalNumberOfLineInFile );
198+ $ endBounds = $ this ->getBounds ($ lastLineNum , $ totalNumberOfLineInFile );
192199
193- $ this ->snippetLineCount = ($ endLine - $ startLine ) + 1 ;
200+ $ bounds = array_merge ($ startBounds , $ endBounds );
201+ sort ($ bounds , SORT_NUMERIC );
194202
195- [ $ startLine, $ endLine ] = $ this -> ensureBoundsAreWithinLimits ( $ startLine , $ endLine , $ totalNumberOfLineInFile ) ;
196- [ $ startLine , $ endLine] = $ this -> trimSnippetSize ( $ startLine , $ endLine ) ;
203+ $ startLine = $ bounds [ 0 ] ;
204+ $ endLine = $ bounds [ count ( $ bounds ) - 1 ] ;
197205
198206 return [$ startLine , $ endLine ];
199207 }
200208
209+ protected function updateSnippetLineCount (int $ startLine , int $ endLine ): void
210+ {
211+ $ this ->snippetLineCount = ($ endLine - $ startLine ) + 1 ;
212+ }
213+
201214 protected function trimSnippetSize (int $ startLine , int $ endLine ): array
202215 {
203216 if (count (range ($ startLine , $ endLine )) > $ this ->snippetLineCount ) {
0 commit comments