Skip to content

Commit b5ee6dc

Browse files
committed
4.0 | Tokenizers: add parameter types
1 parent b3e4dd6 commit b5ee6dc

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/Tokenizers/Comment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Comment
2525
*
2626
* @return array<int, array<string, string|int|array<int>>>
2727
*/
28-
public function tokenizeString($comment, $eolChar, $stackPtr)
28+
public function tokenizeString(string $comment, string $eolChar, int $stackPtr)
2929
{
3030
if (PHP_CODESNIFFER_VERBOSITY > 1) {
3131
StatusWriter::write('*** START COMMENT TOKENIZING ***', 2);
@@ -188,7 +188,7 @@ public function tokenizeString($comment, $eolChar, $stackPtr)
188188
*
189189
* @return array<int, array<string, string|int>>
190190
*/
191-
private function processLine($comment, $eolChar, $start, $end)
191+
private function processLine(string $comment, string $eolChar, int $start, int $end)
192192
{
193193
$tokens = [];
194194

@@ -263,7 +263,7 @@ private function processLine($comment, $eolChar, $start, $end)
263263
*
264264
* @return array<string, string|int>|null
265265
*/
266-
private function collectWhitespace($comment, $start, $end)
266+
private function collectWhitespace(string $comment, int $start, int $end)
267267
{
268268
$space = '';
269269
for ($start; $start < $end; $start++) {

src/Tokenizers/PHP.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class PHP extends Tokenizer
535535
*
536536
* @return array
537537
*/
538-
protected function tokenize($code)
538+
protected function tokenize(string $code)
539539
{
540540
if (PHP_CODESNIFFER_VERBOSITY > 1) {
541541
StatusWriter::write('*** START PHP TOKENIZING ***', 1);
@@ -3847,7 +3847,7 @@ public static function standardiseToken($token)
38473847
*
38483848
* @return array The new token in array format.
38493849
*/
3850-
public static function resolveSimpleToken($token)
3850+
public static function resolveSimpleToken(string $token)
38513851
{
38523852
$newToken = [];
38533853

@@ -3955,7 +3955,7 @@ public static function resolveSimpleToken($token)
39553955
*
39563956
* @return int|null The position of the closing token, if found. NULL otherwise.
39573957
*/
3958-
private function findCloser(array &$tokens, $start, $openerTokens, $closerChar)
3958+
private function findCloser(array &$tokens, int $start, $openerTokens, string $closerChar)
39593959
{
39603960
$numTokens = count($tokens);
39613961
$stack = [0];
@@ -3990,7 +3990,7 @@ private function findCloser(array &$tokens, $start, $openerTokens, $closerChar)
39903990
*
39913991
* @return array|null The array of parsed attribute tokens
39923992
*/
3993-
private function parsePhpAttribute(array &$tokens, $stackPtr)
3993+
private function parsePhpAttribute(array &$tokens, int $stackPtr)
39943994
{
39953995

39963996
$token = $tokens[$stackPtr];

src/Tokenizers/Tokenizer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tokenizers;
1111

12+
use PHP_CodeSniffer\Config;
1213
use PHP_CodeSniffer\Exceptions\TokenizerException;
1314
use PHP_CodeSniffer\Util\Common;
1415
use PHP_CodeSniffer\Util\IgnoreList;
@@ -108,7 +109,7 @@ abstract class Tokenizer
108109
* @return void
109110
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
110111
*/
111-
public function __construct($content, $config, $eolChar='\n')
112+
public function __construct(string $content, ?Config $config, string $eolChar='\n')
112113
{
113114
$this->eolChar = $eolChar;
114115

@@ -139,7 +140,7 @@ public function __construct($content, $config, $eolChar='\n')
139140
*
140141
* @return boolean
141142
*/
142-
protected function isMinifiedContent($content, $eolChar='\n')
143+
protected function isMinifiedContent(string $content, string $eolChar='\n')
143144
{
144145
// Minified files often have a very large number of characters per line
145146
// and cause issues when tokenizing.
@@ -174,7 +175,7 @@ public function getTokens()
174175
*
175176
* @return array
176177
*/
177-
abstract protected function tokenize($code);
178+
abstract protected function tokenize(string $code);
178179

179180

180181
/**
@@ -500,7 +501,7 @@ private function createPositionMap()
500501
*
501502
* @return void
502503
*/
503-
public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null)
504+
public function replaceTabsInToken(array &$token, string $prefix=' ', string $padding=' ', ?int $tabWidth=null)
504505
{
505506
$checkEncoding = false;
506507
if (function_exists('iconv_strlen') === true) {
@@ -840,7 +841,7 @@ private function createScopeMap()
840841
* @return int The position in the stack that closed the scope.
841842
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the nesting level gets too deep.
842843
*/
843-
private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
844+
private function recurseScopeMap(int $stackPtr, int $depth=1, int &$ignore=0)
844845
{
845846
if (PHP_CODESNIFFER_VERBOSITY > 1) {
846847
StatusWriter::write("=> Begin scope map recursion at token $stackPtr with depth $depth", $depth);

0 commit comments

Comments
 (0)