Skip to content

Commit 8ae192e

Browse files
committed
Debug/TokenList: add column showing nr of nested parentheses
This is based on a count of the `nested_parenthesis` index. Includes adjusted unit tests.
1 parent 379f8cd commit 8ae192e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

PHPCSDebug/Sniffs/Debug/TokenListSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function process(File $phpcsFile, $stackPtr)
8888
$sep, \str_pad('Ln', ($linePadding + 1), ' ', \STR_PAD_BOTH),
8989
$sep, 'Col ',
9090
$sep, 'Cond',
91+
$sep, '( #)',
9192
$sep, \str_pad('Token Type', 26), // Longest token type name is 26 chars.
9293
$sep, '[len]: Content', \PHP_EOL;
9394

@@ -116,10 +117,16 @@ public function process(File $phpcsFile, $stackPtr)
116117
}
117118
}
118119

120+
$parenthesesCount = 0;
121+
if (isset($token['nested_parenthesis'])) {
122+
$parenthesesCount = \count($token['nested_parenthesis']);
123+
}
124+
119125
echo \str_pad($ptr, $ptrPadding, ' ', \STR_PAD_LEFT),
120126
$sep, 'L', \str_pad($token['line'], $linePadding, '0', \STR_PAD_LEFT),
121127
$sep, 'C', \str_pad($token['column'], 3, ' ', \STR_PAD_LEFT),
122128
$sep, 'CC', \str_pad($token['level'], 2, ' ', \STR_PAD_LEFT),
129+
$sep, '(', \str_pad($parenthesesCount, 2, ' ', \STR_PAD_LEFT), ')',
123130
$sep, \str_pad($token['type'], 26), // Longest token type name is 26 chars.
124131
$sep, '[', $token['length'], ']: ', $content, \PHP_EOL;
125132
}

PHPCSDebug/Tests/Debug/TokenListUnitTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function testOutput()
4545
$this->assertNotEmpty($output);
4646

4747
$expected = "\n";
48-
$expected .= 'Ptr | Ln | Col | Cond | Token Type | [len]: Content' . "\n";
48+
$expected .= 'Ptr | Ln | Col | Cond | ( #) | Token Type | [len]: Content' . "\n";
4949
$expected .= '-------------------------------------------------------------------------' . "\n";
50-
$expected .= ' 0 | L1 | C 1 | CC 0 | T_OPEN_TAG | [5]: <?php' . "\n\n";
51-
$expected .= ' 1 | L2 | C 1 | CC 0 | T_WHITESPACE | [0]: ' . "\n\n";
52-
$expected .= ' 2 | L3 | C 1 | CC 0 | T_FUNCTION | [8]: function' . "\n";
53-
$expected .= ' 3 | L3 | C 9 | CC 0 | T_WHITESPACE | [0]: ' . "\n\n";
50+
$expected .= ' 0 | L1 | C 1 | CC 0 | ( 0) | T_OPEN_TAG | [5]: <?php' . "\n\n";
51+
$expected .= ' 1 | L2 | C 1 | CC 0 | ( 0) | T_WHITESPACE | [0]: ' . "\n\n";
52+
$expected .= ' 2 | L3 | C 1 | CC 0 | ( 0) | T_FUNCTION | [8]: function' . "\n";
53+
$expected .= ' 3 | L3 | C 9 | CC 0 | ( 0) | T_WHITESPACE | [0]: ' . "\n\n";
5454

5555
$this->assertSame($expected, $output);
5656
}

0 commit comments

Comments
 (0)