@@ -166,38 +166,51 @@ protected function getBounds(int $surroundingLine, int $totalNumberOfLineInFile)
166
166
167
167
protected function getBoundsMulti (int $ totalNumberOfLineInFile ): array
168
168
{
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 ];
171
171
172
+ // snippetLineCount() was used
172
173
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
+ }
175
178
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 ;
178
183
179
- $ startLine = $ bounds [ 0 ] ;
180
- $ endLine = $ bounds [ count ( $ bounds ) - 1 ];
184
+ $ this -> updateSnippetLineCount ( $ startLine, $ endLine ) ;
185
+ }
181
186
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 );
184
189
185
- $ this ->snippetLineCount = ( $ endLine - $ startLine ) + 1 ;
190
+ $ this ->updateSnippetLineCount ( $ startLine , $ endLine ) ;
186
191
187
- return [$ startLine , $ endLine ];
188
- }
192
+ return [$ startLine , $ endLine ];
193
+ }
189
194
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 );
192
199
193
- $ this ->snippetLineCount = ($ endLine - $ startLine ) + 1 ;
200
+ $ bounds = array_merge ($ startBounds , $ endBounds );
201
+ sort ($ bounds , SORT_NUMERIC );
194
202
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 ] ;
197
205
198
206
return [$ startLine , $ endLine ];
199
207
}
200
208
209
+ protected function updateSnippetLineCount (int $ startLine , int $ endLine ): void
210
+ {
211
+ $ this ->snippetLineCount = ($ endLine - $ startLine ) + 1 ;
212
+ }
213
+
201
214
protected function trimSnippetSize (int $ startLine , int $ endLine ): array
202
215
{
203
216
if (count (range ($ startLine , $ endLine )) > $ this ->snippetLineCount ) {
0 commit comments