Skip to content

Commit e3e7dd5

Browse files
committed
Merge branch 'feature/respect-tabs-in-tokensasstring' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 9f48892 + 71df85c commit e3e7dd5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Files/File.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,12 +1895,14 @@ public function isReference($stackPtr)
18951895
* Returns the content of the tokens from the specified start position in
18961896
* the token stack for the specified length.
18971897
*
1898-
* @param int $start The position to start from in the token stack.
1899-
* @param int $length The length of tokens to traverse from the start pos.
1898+
* @param int $start The position to start from in the token stack.
1899+
* @param int $length The length of tokens to traverse from the start pos.
1900+
* @param int $origContent Whether the original content or the tab replaced
1901+
* content should be used.
19001902
*
19011903
* @return string The token contents.
19021904
*/
1903-
public function getTokensAsString($start, $length)
1905+
public function getTokensAsString($start, $length, $origContent=false)
19041906
{
19051907
$str = '';
19061908
$end = ($start + $length);
@@ -1909,7 +1911,13 @@ public function getTokensAsString($start, $length)
19091911
}
19101912

19111913
for ($i = $start; $i < $end; $i++) {
1912-
$str .= $this->tokens[$i]['content'];
1914+
// If tabs are being converted to spaces by the tokeniser, the
1915+
// original content should be used instead of the converted content.
1916+
if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1917+
$str .= $this->tokens[$i]['orig_content'];
1918+
} else {
1919+
$str .= $this->tokens[$i]['content'];
1920+
}
19131921
}
19141922

19151923
return $str;

0 commit comments

Comments
 (0)